@turf/nearest-point-on-line
Advanced tools
Comparing version 7.1.0-alpha.7 to 7.1.0-alpha.70
@@ -12,3 +12,3 @@ import { LineString, MultiLineString, Feature, Point } from 'geojson'; | ||
* @param {string} [options.units='kilometers'] can be degrees, radians, miles, or kilometers | ||
* @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point. | ||
* @returns {Feature<Point>} closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point. | ||
* @example | ||
@@ -36,2 +36,3 @@ * var line = turf.lineString([ | ||
index: number; | ||
multiFeatureIndex: number; | ||
location: number; | ||
@@ -38,0 +39,0 @@ [key: string]: any; |
@@ -36,67 +36,77 @@ var __defProp = Object.defineProperty; | ||
index: -1, | ||
multiFeatureIndex: -1, | ||
location: -1 | ||
}); | ||
let length = 0; | ||
flattenEach(lines, function(line) { | ||
const coords = getCoords(line); | ||
for (let i = 0; i < coords.length - 1; i++) { | ||
const start = point(coords[i]); | ||
start.properties.dist = distance(pt, start, options); | ||
const stop = point(coords[i + 1]); | ||
stop.properties.dist = distance(pt, stop, options); | ||
const sectionLength = distance(start, stop, options); | ||
const heightDistance = Math.max( | ||
start.properties.dist, | ||
stop.properties.dist | ||
); | ||
const direction = bearing(start, stop); | ||
const perpendicularPt1 = destination( | ||
pt, | ||
heightDistance, | ||
direction + 90, | ||
options | ||
); | ||
const perpendicularPt2 = destination( | ||
pt, | ||
heightDistance, | ||
direction - 90, | ||
options | ||
); | ||
const intersect = lineIntersects( | ||
lineString([ | ||
perpendicularPt1.geometry.coordinates, | ||
perpendicularPt2.geometry.coordinates | ||
]), | ||
lineString([start.geometry.coordinates, stop.geometry.coordinates]) | ||
); | ||
let intersectPt; | ||
if (intersect.features.length > 0 && intersect.features[0]) { | ||
intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), { | ||
properties: { | ||
dist: distance(pt, intersect.features[0], options), | ||
location: length + distance(start, intersect.features[0], options) | ||
} | ||
}); | ||
flattenEach( | ||
lines, | ||
function(line, _featureIndex, multiFeatureIndex) { | ||
const coords = getCoords(line); | ||
for (let i = 0; i < coords.length - 1; i++) { | ||
const start = point(coords[i]); | ||
start.properties.dist = distance(pt, start, options); | ||
const stop = point(coords[i + 1]); | ||
stop.properties.dist = distance(pt, stop, options); | ||
const sectionLength = distance(start, stop, options); | ||
const heightDistance = Math.max( | ||
start.properties.dist, | ||
stop.properties.dist | ||
); | ||
const direction = bearing(start, stop); | ||
const perpendicularPt1 = destination( | ||
pt, | ||
heightDistance, | ||
direction + 90, | ||
options | ||
); | ||
const perpendicularPt2 = destination( | ||
pt, | ||
heightDistance, | ||
direction - 90, | ||
options | ||
); | ||
const intersect = lineIntersects( | ||
lineString([ | ||
perpendicularPt1.geometry.coordinates, | ||
perpendicularPt2.geometry.coordinates | ||
]), | ||
lineString([start.geometry.coordinates, stop.geometry.coordinates]) | ||
); | ||
let intersectPt; | ||
if (intersect.features.length > 0 && intersect.features[0]) { | ||
intersectPt = __spreadProps(__spreadValues({}, intersect.features[0]), { | ||
properties: { | ||
dist: distance(pt, intersect.features[0], options), | ||
multiFeatureIndex, | ||
location: length + distance(start, intersect.features[0], options) | ||
} | ||
}); | ||
} | ||
if (start.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, start), { | ||
properties: __spreadProps(__spreadValues({}, start.properties), { | ||
index: i, | ||
multiFeatureIndex, | ||
location: length | ||
}) | ||
}); | ||
} | ||
if (stop.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, stop), { | ||
properties: __spreadProps(__spreadValues({}, stop.properties), { | ||
index: i + 1, | ||
multiFeatureIndex, | ||
location: length + sectionLength | ||
}) | ||
}); | ||
} | ||
if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, intersectPt), { | ||
properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i }) | ||
}); | ||
} | ||
length += sectionLength; | ||
} | ||
if (start.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, start), { | ||
properties: __spreadProps(__spreadValues({}, start.properties), { index: i, location: length }) | ||
}); | ||
} | ||
if (stop.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, stop), { | ||
properties: __spreadProps(__spreadValues({}, stop.properties), { | ||
index: i + 1, | ||
location: length + sectionLength | ||
}) | ||
}); | ||
} | ||
if (intersectPt && intersectPt.properties.dist < closestPt.properties.dist) { | ||
closestPt = __spreadProps(__spreadValues({}, intersectPt), { | ||
properties: __spreadProps(__spreadValues({}, intersectPt.properties), { index: i }) | ||
}); | ||
} | ||
length += sectionLength; | ||
} | ||
}); | ||
); | ||
return closestPt; | ||
@@ -103,0 +113,0 @@ } |
{ | ||
"name": "@turf/nearest-point-on-line", | ||
"version": "7.1.0-alpha.7+0ce6ecca0", | ||
"version": "7.1.0-alpha.70+948cdafaf", | ||
"description": "turf nearest-point-on-line module", | ||
@@ -49,5 +49,5 @@ "author": "Turf Authors", | ||
"devDependencies": { | ||
"@turf/along": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/length": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/truncate": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/along": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/length": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/truncate": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/benchmark": "^2.1.5", | ||
@@ -65,12 +65,13 @@ "@types/tape": "^4.2.32", | ||
"dependencies": { | ||
"@turf/bearing": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/destination": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/distance": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/helpers": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/invariant": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/line-intersect": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/meta": "^7.1.0-alpha.7+0ce6ecca0", | ||
"@turf/bearing": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/destination": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/distance": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/helpers": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/invariant": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/line-intersect": "^7.1.0-alpha.70+948cdafaf", | ||
"@turf/meta": "^7.1.0-alpha.70+948cdafaf", | ||
"@types/geojson": "^7946.0.10", | ||
"tslib": "^2.6.2" | ||
}, | ||
"gitHead": "0ce6ecca05829690270fec6d6bed2003495fe0ea" | ||
"gitHead": "948cdafaf70606d2e27fcc79973fa48ee1182067" | ||
} |
@@ -11,7 +11,7 @@ # @turf/nearest-point-on-line | ||
* `lines` **([Geometry][3] | [Feature][4]<([LineString][5] | [MultiLineString][6])>)** lines to snap to | ||
* `pt` **([Geometry][3] | [Feature][4]<[Point][7]> | [Array][8]<[number][9]>)** point to snap from | ||
* `options` **[Object][10]** Optional parameters (optional, default `{}`) | ||
* `lines` **([Geometry][3] | [Feature][4]<([LineString][2] | [MultiLineString][5])>)** lines to snap to | ||
* `pt` **([Geometry][3] | [Feature][4]<[Point][1]> | [Array][6]<[number][7]>)** point to snap from | ||
* `options` **[Object][8]** Optional parameters (optional, default `{}`) | ||
* `options.units` **[string][11]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
* `options.units` **[string][9]** can be degrees, radians, miles, or kilometers (optional, default `'kilometers'`) | ||
@@ -38,3 +38,3 @@ ### Examples | ||
Returns **[Feature][4]<[Point][7]>** closest point on the `line` to `point`. The properties object will contain three values: `index`: closest point was found on nth line part, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point. | ||
Returns **[Feature][4]<[Point][1]>** closest point on the `line` to `point`. The properties object will contain four values: `index`: closest point was found on nth line part, `multiFeatureIndex`: closest point was found on the nth line of the `MultiLineString`, `dist`: distance between pt and the closest point, `location`: distance along the line between start and the closest point. | ||
@@ -49,16 +49,12 @@ [1]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.4 | ||
[5]: https://tools.ietf.org/html/rfc7946#section-3.1.5 | ||
[6]: https://tools.ietf.org/html/rfc7946#section-3.1.5 | ||
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | ||
[7]: https://tools.ietf.org/html/rfc7946#section-3.1.2 | ||
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array | ||
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number | ||
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | ||
[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object | ||
[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String | ||
<!-- This file is automatically generated. Please don't edit it directly. If you find an error, edit the source file of the module in question (likely index.js or index.ts), and re-run "yarn docs" from the root of the turf project. --> | ||
@@ -65,0 +61,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
33857
268
9
76
+ Added@types/geojson@^7946.0.10