6.5.0 • Published 1 month ago

@turf/nearest-point-on-line v6.5.0

Weekly downloads
146,849
License
MIT
Repository
github
Last release
1 month ago

@turf/nearest-point-on-line

nearestPointOnLine

Takes a Point and a LineString and calculates the closest Point on the (Multi)LineString.

Parameters

Examples

var line = turf.lineString([
    [-77.031669, 38.878605],
    [-77.029609, 38.881946],
    [-77.020339, 38.884084],
    [-77.025661, 38.885821],
    [-77.021884, 38.889563],
    [-77.019824, 38.892368]
]);
var pt = turf.point([-77.037076, 38.884017]);

var snapped = turf.nearestPointOnLine(line, pt, {units: 'miles'});

//addToMap
var addToMap = [line, pt, snapped];
snapped.properties['marker-color'] = '#00f';

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.


This module is part of the Turfjs project, an open source module collection dedicated to geographic algorithms. It is maintained in the Turfjs/turf repository, where you can create PRs and issues.

Installation

Install this module individually:

$ npm install @turf/nearest-point-on-line

Or install the Turf module that includes it as a function:

$ npm install @turf/turf
@makinacorpus/mapbox-gl-pathmapbox-gl-routingmapbox-gl-pathgisviewer-vue-ftest1zxmap-ui-supermap@infinitebrahmanuniverse/nolb-_tur@everything-registry/sub-chunk-941react-leaflet-box-select-measurementreact-leaflet-box-select-measurement-privatesharedstreetsshinegis-clientrnmapbox-animated@deck.gl-community/editable-layerscool-map-gl@conveyal/analysis-ui@bmap-turf/turfflow-rdf@flightmap-react-native-android/maps@emuanalytics/flow-rdf@ragone/edit-modes@ott_test/transit-vehicle-overlay@rnmapbox/maps@react-native-flightmap-gl/android@react-native-flightmap-gl/flightmap@react-native-flightmap-gl/maps@react-native-mapbox-gl/maps@strategies/maplibsasakidev@zalastax/nolb-_tur@v-mapboxgl/utils@varlab-ucf/nebulagl-layers@varlab-ucf/nebula.gl@varlab-ucf/nebulagl-edit-modes@tamagui/maps@track-asia/trackasia-react-nativeagentmaps@vtmap/vtmap-react-native-sdk@turf/turf@turf/line-overlap@turf/line-slice@turf/line-splitfengsheng-rnmapsgallavantgas3d.glzxmap-uizxmap-ui-v2geo-data-integrationgisviewer-vue-ftestgisviewer-vuevue-openlayer-sailingmapvue-openlayer-slmap1vue-openlayer-darktransportationhafas-find-triphafas-find-tripsvanity-widgetxbsj-rendererxbsj-xe2yymap-turfvue3-openlayer-slmapmapbox-gl-draw-cut-line-modemapbox-draw-expandmapmyindia-map-react-native-betamaptalks.autoadsorbmappls-map-react-nativenebula.gl@mapxus/react-native-mapxus-sdknearest-point-on-geometry@makina-corpus/mapbox-gl-forbidden-area@makina-corpus/mapbox-gl-path@loudsrl/turf@mapbox/carmen@mapbox/carmen-private@maplibre/maplibre-react-nativeluke.glmax-inscribed-circleleaflet-draw-cut@larryamiel/peek-mapsmini-tokyo-3dminimongo@hortau/maps@mybus/spatial@nebula.gl/edit-modes@nebula.gl/layers@mpvite/maps@oidajs/eo-mobx
7.0.0-alpha.114

1 month ago

7.0.0-alpha.113

3 months ago

7.0.0-alpha.111

3 months ago

7.0.0-alpha.110

4 months ago

7.0.0-alpha.1

7 months ago

7.0.0-alpha.2

7 months ago

7.0.0-alpha.0

1 year ago

6.5.0

3 years ago

6.4.0

3 years ago

6.3.0

3 years ago

6.2.0

3 years ago

6.2.0-alpha.3

3 years ago

6.2.0-alpha.2

4 years ago

6.2.0-alpha.1

4 years ago

6.0.2

6 years ago

6.0.1

6 years ago

6.0.0

6 years ago

5.1.5

6 years ago

5.1.0

6 years ago

5.0.4

6 years ago

5.0.0

6 years ago