Skip to main content
Version: 7.1.0

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

NameTypeDescription
targetPointCoordthe reference point
pointsFeatureCollection<Point>against input point set
options?ObjectOptional parameters (default {})
options.units?stringthe units of the numeric result (default 'kilometers')

Returns

    Feature<Point> the closest point in the set to the reference point

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(...);