Skip to main content

distance

Computes the Cartesian distance between geometry a and geometry b.

Distance is in input geometry units.

Parameters​

NameTypeDescription
aGeometry | Prepared<Geometry>First geometry
bGeometrySecond geometry

Returns​

number

The distance between geometries

Throws​

  • GEOSError on unsupported geometry types (curved)
  • GEOSError when either geometry is empty

See also​

  • distanceWithin returns true when two geometries are within a given distance
  • nearestPoints finds the nearest points of two geometries
  • prepare improves performance of repeated calls against a single geometry

Examples​

distance between point and line
distance between line and polygon
distance between two polygons