forked from Turfjs/turf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Turfjs#1357 from Turfjs/typescript-modules
Update nearest-point-to-line & point-to-line-distance TS
- Loading branch information
Showing
13 changed files
with
205 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { Feature, FeatureCollection, GeometryCollection, LineString, Point, Properties, Units } from "@turf/helpers"; | ||
/** | ||
* Returns the closest {@link Point|point}, of a {@link FeatureCollection|collection} of points, | ||
* to a {@link LineString|line}. The returned point has a `dist` property indicating its distance to the line. | ||
* | ||
* @name nearestPointToLine | ||
* @param {FeatureCollection|GeometryCollection<Point>} points Point Collection | ||
* @param {Feature|Geometry<LineString>} line Line Feature | ||
* @param {Object} [options] Optional parameters | ||
* @param {string} [options.units='kilometers'] unit of the output distance property | ||
* (eg: degrees, radians, miles, or kilometers) | ||
* @param {Object} [options.properties={}] Translate Properties to Point | ||
* @returns {Feature<Point>} the closest point | ||
* @example | ||
* var pt1 = turf.point([0, 0]); | ||
* var pt2 = turf.point([0.5, 0.5]); | ||
* var points = turf.featureCollection([pt1, pt2]); | ||
* var line = turf.lineString([[1,1], [-1,1]]); | ||
* | ||
* var nearest = turf.nearestPointToLine(points, line); | ||
* | ||
* //addToMap | ||
* var addToMap = [nearest, line]; | ||
*/ | ||
declare function nearestPointToLine<P = { | ||
dist: number; | ||
[key: string]: any; | ||
}>(points: FeatureCollection<Point> | Feature<GeometryCollection> | GeometryCollection, line: Feature<LineString> | LineString, options?: { | ||
units?: Units; | ||
properties?: Properties; | ||
}): Feature<Point, P>; | ||
export default nearestPointToLine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
|
||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
|
||
/* Module Resolution Options */ | ||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"defaultSeverity": "error", | ||
"extends": [ | ||
"tslint:recommended" | ||
], | ||
"jsRules": {}, | ||
"rules": {}, | ||
"rulesDirectory": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Coord, Feature, LineString, Units } from "@turf/helpers"; | ||
/** | ||
* Returns the minimum distance between a {@link Point} and a {@link LineString}, being the distance from a line the | ||
* minimum distance between the point and any segment of the `LineString`. | ||
* | ||
* @name pointToLineDistance | ||
* @param {Feature<Point>|Array<number>} pt Feature or Geometry | ||
* @param {Feature<LineString>} line GeoJSON Feature or Geometry | ||
* @param {Object} [options={}] Optional parameters | ||
* @param {string} [options.units="kilometers"] can be anything supported by turf/convertLength | ||
* (ex: degrees, radians, miles, or kilometers) | ||
* @param {string} [options.method="geodesic"] wether to calculate the distance based on geodesic (spheroid) or | ||
* planar (flat) method. Valid options are 'geodesic' or 'planar'. | ||
* @returns {number} distance between point and line | ||
* @example | ||
* var pt = turf.point([0, 0]); | ||
* var line = turf.lineString([[1, 1],[-1, 1]]); | ||
* | ||
* var distance = turf.pointToLineDistance(pt, line, {units: 'miles'}); | ||
* //=69.11854715938406 | ||
*/ | ||
declare function pointToLineDistance(pt: Coord, line: Feature<LineString> | LineString, options?: { | ||
units?: Units; | ||
method?: "geodesic" | "planar"; | ||
}): number; | ||
export default pointToLineDistance; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Basic Options */ | ||
"target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"declaration": true, /* Generates corresponding '.d.ts' file. */ | ||
|
||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
|
||
/* Module Resolution Options */ | ||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
}, | ||
"files": [ | ||
"index.ts" | ||
] | ||
} |
Oops, something went wrong.