nearestPoint
Description
Takes a reference point and a FeatureCollection of Features with Point geometries and returns the point from the FeatureCollection closest to the reference. This calculation is geodesic.
Parameters
Name | Type | Description |
---|---|---|
targetPoint | Coord | the reference point |
points | FeatureCollection<Point> | against input point set |
options? | Object | Optional parameters (default {}) |
options.units? | string | the units of the numeric result (default 'kilometers') |
Returns
Examples
var targetPoint = turf.point([28.965797, 41.010086], {
"marker-color": "#0F0",
});
var points = turf.featureCollection([
turf.point([28.973865, 41.011122]),
turf.point([28.948459, 41.024204]),
turf.point([28.938674, 41.013324]),
]);
var nearest = turf.nearestPoint(targetPoint, points);
Installation
$ npm install @turf/nearest-point
import { nearestPoint } from "@turf/nearest-point";
const result = nearestPoint(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.nearestPoint(...);