pointToPolygonDistance
Description
Calculates the distance from a point to the edges of a polygon or multi-polygon. Returns negative values for points inside the polygon. Handles polygons with holes and multi-polygons. A hole is treated as the exterior of the polygon.
Parameters
| Name | Type | Description |
|---|---|---|
| point | Feature<Point> | Point | Position | Input point |
| polygonOrMultiPolygon | Feature<Polygon | MultiPolygon> | Polygon | MultiPolygon | Input polygon or multipolygon |
| options | Object | Optional parameters (default {}) |
| options.units | Units | Units of the result e.g. "kilometers", "miles", "meters" |
| options.method | "geodesic" | "planar" | Method of the result |
Returns
number Distance in meters (negative values for points inside the polygon)
Installation
$ npm install @turf/point-to-polygon-distance
import { pointToPolygonDistance } from "@turf/point-to-polygon-distance";
const result = pointToPolygonDistance(...);
$ npm install @turf/turf
import * as turf from "@turf/turf";
const result = turf.pointToPolygonDistance(...);