nearestPoints
Finds the nearest points between geometry a
and geometry b
.
The returned points can be points along a line segment, not necessarily one of the vertices of the input geometries.
Parameters
Name | Type | Description |
---|---|---|
a | Geometry | Prepared<Geometry> | First geometry |
b | Geometry | Second geometry |
Returns
[ Point, Point ]
An array with two point geometries, first is the nearest point
from the geometry a
second from the geometry b
Throws
See also
distance
computes the distance between two geometriesdistanceWithin
returnstrue
when two geometries are within a given distanceprepare
improves performance of repeated calls against a single geometry
Examples
nearest points between point and line
nearest points between two polygons
to improve performance of repeated calls against a single geometry
const a = buffer(point([ 0, 0 ]), 10, { quadrantSegments: 1000 });
// `a` is a polygon with many vertices (4000 in this example)
prepare(a);
// preparation of geometry `a` will improve the performance of repeated
// `nearestPoints` calls, but only those where `a` is the first geometry
const r1 = nearestPoints(a, point([ 12, 0 ]));
const r2 = nearestPoints(a, point([ 12, 1 ]));
const r3 = nearestPoints(point([ 12, 2 ]), a); // no benefit from prepared geometry