distance
Computes the Cartesian distance between geometry a
and geometry b
.
Distance is in input geometry units.
Parameters
Name | Type | Description |
---|---|---|
a | Geometry | Prepared<Geometry> | First geometry |
b | Geometry | Second geometry |
Returns
number
The distance between geometries
Throws
See also
distanceWithin
returnstrue
when two geometries are within a given distancenearestPoints
finds the nearest points of two geometriesprepare
improves performance of repeated calls against a single geometry
Examples
distance between point and line
distance between line and polygon
distance 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
// `distance` calls, but only those where `a` is the first geometry
const r1 = distance(a, point([ 12, 0 ]));
const r2 = distance(a, point([ 12, 1 ]));
const r3 = distance(point([ 12, 2 ]), a); // no benefit from prepared geometry