Skip to main content
Version: Next

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

NameTypeDescription
pointFeature<Point> | Point | PositionInput point
polygonOrMultiPolygonFeature<Polygon | MultiPolygon> | Polygon | MultiPolygonInput polygon or multipolygon
optionsObjectOptional parameters (default {})
options.unitsUnitsUnits 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(...);