Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

turf-nearest

Turfjs73.9kMITdeprecated3.0.12

Turf packages are now namespaced: please use @turf/nearest instead

turf nearest module

turf, geojson, gis, near

readme

turf-nearest

build status

turf nearest module

turf.nearest(point, against)

Takes a Point feature and a FeatureCollection of Point features and returns the Point feature from the FeatureCollection closest to the input point.

Parameters

parameter type description
point Point the reference point
against FeatureCollection a FeatureCollection of Point features

Example

var point = turf.point([28.965797, 41.010086]);
point.properties['marker-color'] = '#0f0';
var against = turf.featurecollection([
 turf.point([28.973865, 41.011122]),
 turf.point([28.948459, 41.024204]),
 turf.point([28.938674, 41.013324])
]);

var nearest = turf.nearest(point, against);
nearest.properties['marker-color'] = '#f00';

var result = turf.featurecollection(
  against.features.concat(point));

//=result

Installation

Requires nodejs.

$ npm install turf-nearest

Tests

$ npm test