nearest-point-on-geometry

1.0.1 • Public • Published

nearest-point-on-geometry

Takes a point and a geometry (Point, Polygon, LineString, GeometryCollection, ...) and calculates the closest point on the geometry using turf. If the point lies within a polygon, it will return the point itself.

nearest-point-on-geometry mostly relies on @turf/nearest-point-on-line and accepts the same parameters.

Usage

const nearestPointOnGeometry = require('nearest-point-on-geometry')
 
let 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]
])
let pt = turf.point([-77.037076, 38.884017]);
 
let snapped = nearestPointOnGeometry(line, pt, {units: 'miles'})
 
console.log(snapped)

Result:

{
    "type": "Feature",
    "properties": {
        "dist": 0.4239819718626291,
        "location": 0.2112562928240912,
        "index": 0
    },
    "geometry": {
        "type": "Point",
        "coordinates": [
            -77.02996941477018,
            38.88136146322953
        ]
    }
}

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.1
    72
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.0.1
    72
  • 1.0.0
    1

Package Sidebar

Install

npm i nearest-point-on-geometry

Weekly Downloads

51

Version

1.0.1

License

MIT

Unpacked Size

147 kB

Total Files

14

Last publish

Collaborators

  • plepe