Skip to content

Measurement

Area, length, distance, nearest points, and similarity measures.

Related: CRS, units & measurement

area

Accepted call forms
area(
    geom: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float
area(
    geom: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
area(
    geom: Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
area(
    geom: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None]
    | Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float | NDArray[float64]

Compute area in CRS-natural units or with a unit override.

For a GeometryCollection, overlapping members count once, as the area of their union. Parts of a valid MultiPolygon cannot overlap.

Geographic area follows the input Space's edges on the selected surface. The default geographic surface is the CRS ellipsoid.

Parameters:

Name Type Description Default
geom Geometry, GeometryArray, or iterable of geometry-like values or None

Input geometry, array, or iterable materialized as a row-preserving array. Missing rows return nan.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests square-meter output when the CRS and metric have compatible axes; Sphere metrics already use square meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires a Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
float or ndarray

Scalar area or one value per row.

Raises:

Type Description
CRSError

If the CRS lacks linear axis units for a metric result.

GeometryError

If unit='meters' is requested for a CRS-free geometry.

See Also

Geometry.area : CRS-natural property form. length : Length/perimeter with the same unit override.

Examples:

>>> import gometry as gm
>>> gm.area(gm.box(0, 0, 2, 2), metric='cartesian')
4.0

distance

Accepted call forms
distance(
    left: Point,
    right: Point,
    *,
    path: Literal['rhumb'],
    unit: Literal['meters'] | None = None,
    metric: Sphere | None = None,
) -> float
distance(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Point | None],
    right: Point
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Point | None],
    *,
    path: Literal['rhumb'],
    unit: Literal['meters'] | None = None,
    metric: Sphere | None = None,
) -> NDArray[float64]
distance(
    left: Point,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Point | None],
    *,
    path: Literal['rhumb'],
    unit: Literal['meters'] | None = None,
    metric: Sphere | None = None,
) -> NDArray[float64]
distance(
    left: Point
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Point | None],
    right: Point
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Point | None],
    *,
    path: Literal['rhumb'],
    unit: Literal['meters'] | None = None,
    metric: Sphere | None = None,
) -> float | NDArray[float64]
distance(
    left: Geometry,
    right: Geometry,
    *,
    path: Literal['geodesic'] = 'geodesic',
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float
distance(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    path: Literal['geodesic'] = 'geodesic',
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
distance(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    path: Literal['geodesic'] = 'geodesic',
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
distance(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    path: Literal['geodesic'] = 'geodesic',
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float | NDArray[float64]

Compute the minimum distance between left and right.

The input Space defines shape edges, and the selected metric measures them. Geographic point-to-point distances use geodesics on the selected surface; filled polygon interiors participate. For two points, path='rhumb' measures the constant-bearing route in meters on a geographic surface.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
right Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
path ('geodesic', 'rhumb')

Route for point operands. Omit for geodesic distance; rhumb distance requires path='rhumb' and a geographic CRS and uses meters.

'geodesic'
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires a Planar Space; Sphere requires a geographic CRS. Rhumb distance requires a geographic surface.

None

Returns:

Type Description
float or ndarray

One result per input pair.

Raises:

Type Description
CRSError

If the CRS lacks linear axis units for a metric result, or path='rhumb' is used without a geographic CRS.

CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

GeometryTypeError

If path='rhumb' is used with non-point operands.

GeometryError

If unit='meters' is requested for a CRS-free geometry, or the selected metric is incompatible with the input Space or path.

See Also

dwithin : Within-distance test. nearest_points : Closest-pair witness points. shortest_line : Connecting line between closest points. hausdorff_distance : Hausdorff (set-to-set) similarity distance. frechet_distance : Curve-to-curve similarity (linestrings).

Examples:

>>> import gometry as gm
>>> gm.distance(gm.Point(0, 0), gm.Point(3, 4))
5.0
>>> a, b = gm.Point(13.0, 52.0, space=gm.Space(crs=4326)), gm.Point(13.1, 52.0, space=gm.Space(crs=4326))
>>> round(gm.distance(a, b))  # meters
6868

distance_3d

Accepted call forms
distance_3d(
    left: Geometry, right: Geometry, *, unit: Literal['meters'] | None = None
) -> float
distance_3d(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    unit: Literal['meters'] | None = None,
) -> NDArray[float64]
distance_3d(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    unit: Literal['meters'] | None = None,
) -> NDArray[float64]
distance_3d(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    unit: Literal['meters'] | None = None,
) -> float | NDArray[float64]

Compute the minimum 3D (Euclidean) distance between two geometries, measured for their CRS.

Distance is over linework: points/multipoints as degenerate segments, polygons via their boundary rings. Part of the 3D Euclidean family with length_3d only — area and perimeter are inherently 2D (XY footprint) and have no 3D form; the 3D extent is bounds with min_z/max_z.

A projected CRS gives native linear units and a CRS-free geometry gives raw coordinate units — the same defaults as the 2D distance. A geographic CRS raises under every unit: a Euclidean norm cannot combine degrees with meter heights. Every vertex on both operands must carry a Z ordinate.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
right Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'

Returns:

Type Description
float or ndarray

One result per input pair.

Raises:

Type Description
CRSError

If the CRS lacks linear axis units for a metric result.

CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

GeometryError

If unit='meters' is requested for a CRS-free geometry.

InvalidGeometryError

If either operand lacks a Z ordinate on every vertex.

See Also

distance : The 2D sibling, with the same unit override. length_3d : Total 3D length under the same metric.

Examples:

>>> import gometry as gm
>>> gm.distance_3d(gm.from_wkt('POINT Z (0 0 0)'), gm.from_wkt('POINT Z (0 0 3)'))
3.0

frechet_distance

Accepted call forms
frechet_distance(
    left: Geometry,
    right: Geometry,
    *,
    densify: float | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float
frechet_distance(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    densify: FloatInput | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
frechet_distance(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    densify: FloatInput | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
frechet_distance(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    densify: FloatInput | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float | NDArray[float64]

Discrete Fréchet distance between two linestrings.

Measures XY vertex pairs on the selected surface. densify subdivides source curves defined by the input Space before those distances are evaluated. Geographic source stationing uses the original CRS ellipsoid; a selected Sphere changes only the distances between sampled XY vertices. Empty line operands give infinity, and missing array pairs give NaN.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

The line operands; scalar and sequence inputs broadcast pairwise.

required
right Geometry, GeometryArray, or iterable of Geometry or None

The line operands; scalar and sequence inputs broadcast pairwise.

required
densify float or array_like

Subdivide source segments by this fraction (in (0, 1]) before measuring. Arrays may provide one fraction per pair. The source parameterization comes from the input Space; the selected metric measures the resulting XY vertex pairs. Omitted measures input vertices only.

None
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Surface for XY vertex-pair distances. Cartesian requires Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
float or ndarray

One result per input pair.

Raises:

Type Description
GeometryError

If densify is outside (0, 1].

CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

CRSError

If the selected physical surface is unsupported by the CRS.

ResourceLimitError

If densification exceeds the generated pairwise-work budget.

GeometryTypeError

If either geometry is not a single line.

InvalidGeometryError

If geographic measurement encounters a latitude outside the source CRS's pole limits.

See Also

distance : Minimum pairwise distance. hausdorff_distance : Hausdorff (set-to-set) similarity distance. dwithin : Within-distance test. nearest_points : Closest-pair witness points. shortest_line : Connecting line between closest points.

Examples:

>>> import gometry as gm
>>> a = gm.LineString([(0, 0), (10, 0)])
>>> b = gm.LineString([(0, 1), (10, 1)])
>>> gm.frechet_distance(a, b)
1.0

hausdorff_distance

Accepted call forms
hausdorff_distance(
    left: Geometry,
    right: Geometry,
    *,
    max_error: float | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float
hausdorff_distance(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    max_error: float | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
hausdorff_distance(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    max_error: float | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
hausdorff_distance(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    max_error: float | None = None,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float | NDArray[float64]

Compute the continuous Hausdorff (set-to-set) distance between left and right.

Compare complete selected support, including point, curve, filled-area, collection and nonempty Full support. The source Space retains its literal Planar paths, Chart branches or minor spherical arcs; the measuring surface supplies distances without replacing those curves.

Planar polygons are filled sets, including their interiors. For example, a square [-2, 2] by [-2, 2] and the same square with a diamond hole at (0, 1), (1, 0), (0, -1), (-1, 0) have filled-set Hausdorff distance 1 / sqrt(2), whereas their boundary Hausdorff distance is 1.5. Shapely's discrete and densified Hausdorff forms measure boundaries instead.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
right Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
max_error float

Nonnegative finite scalar absolute accuracy target in final result units. Physical measurements use a separation-aware automatic target when omitted. Zero requests the highest useful accuracy at the numerical and work limits; an unmet physical target alone does not invalidate a useful estimate. Cartesian results default to a certified relative error of at most 1e-9; zero requests binary64 relative resolution.

None
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
float or ndarray

One result per input pair. A planar result is zero exactly when the operands have equal closed support; unequal positive distances remain positive even when smaller than the effective error bound. An empty operand yields inf, including two empty operands. Missing array rows yield nan. Full is nonempty and participates in physical measurements.

Raises:

Type Description
CRSError

If the CRS or selected measuring surface is outside its supported physical numerical domain.

CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

GeometryError

If max_error is not a nonnegative finite scalar; if physical units are requested without a compatible CRS; or if a finite Cartesian result cannot be certified within representable output and the available generated-work or memory resources.

See Also

distance : Minimum pairwise distance. frechet_distance : Curve-to-curve similarity (linestrings). dwithin : Within-distance test. nearest_points : Closest-pair witness points. shortest_line : Connecting line between closest points.

Examples:

>>> import gometry as gm
>>> a = gm.LineString([(0, 0), (10, 0)])
>>> b = gm.LineString([(0, 1), (10, 3)])
>>> abs(gm.hausdorff_distance(a, b, max_error=1e-12) - 3.0) <= 1e-12
True

length

Accepted call forms
length(
    geom: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float
length(
    geom: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
length(
    geom: Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> NDArray[float64]
length(
    geom: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None]
    | Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> float | NDArray[float64]

Compute length in CRS-natural units or with a unit override.

For a GeometryCollection, length sums every member's length or perimeter, including overlapping members.

Geographic length and perimeter follow the input Space's edges on the selected surface. The default geographic surface is the CRS ellipsoid.

For chart polygons, artificial cut edges along the antimeridian seam cancel out of the perimeter when opposite sides of the cut meet across the seam (or when a single ring traces the same meridian in opposite directions at wrapped longitudes). Genuine overlapping edges away from the seam remain in the perimeter.

Parameters:

Name Type Description Default
geom Geometry, GeometryArray, or iterable of geometry-like values or None

Input geometry, array, or iterable materialized as a row-preserving array. Missing rows return nan.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires a Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
float or ndarray

Scalar length or one value per row.

Raises:

Type Description
CRSError

If the CRS lacks linear axis units for a metric result.

GeometryError

If unit='meters' is requested for a CRS-free geometry.

See Also

Geometry.length : CRS-natural property form. area : Area with the same unit override.

Examples:

>>> import gometry as gm
>>> gm.length(gm.LineString([(0, 0), (3, 4)]), metric='cartesian')
5.0

length_3d

Accepted call forms
length_3d(geom: Geometry, *, unit: Literal['meters'] | None = None) -> float
length_3d(
    geom: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        Geometry | None
    ],
    *,
    unit: Literal['meters'] | None = None,
) -> NDArray[float64]
length_3d(
    geom: Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
) -> NDArray[float64]
length_3d(
    geom: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None]
    | Iterable[
        Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
    ],
    *,
    unit: Literal['meters'] | None = None,
) -> float | NDArray[float64]

Compute 3D length in CRS-natural units or with a unit override.

Parameters:

Name Type Description Default
geom Geometry, GeometryArray, or iterable of geometry-like values or None

Input geometry, array, or iterable materialized as a row-preserving array. Missing rows return nan.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement. Geographic CRSs are not supported by 3D Euclidean metrics.

'meters'

Returns:

Type Description
float or ndarray

Scalar 3D length or one value per row.

Raises:

Type Description
CRSError

If the CRS lacks linear axis units for a metric result.

GeometryError

If unit='meters' is requested for a CRS-free geometry.

InvalidGeometryError

If a scalar geometry lacks Z on every vertex.

See Also

Geometry.length_3d : CRS-natural property form. length : The 2D sibling, with the same unit override. distance_3d : Pairwise 3D distance under the same metric.

Examples:

>>> import gometry as gm
>>> gm.length_3d(gm.from_wkt('LINESTRING Z (0 0 0, 3 4 0)'))
5.0

nearest_points

Accepted call forms
nearest_points(
    left: Geometry,
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[Point, Point]
nearest_points(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point], GeometryArray[Point]]
nearest_points(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point], GeometryArray[Point]]
nearest_points(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryOtherT
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point], GeometryArray[Point]]
nearest_points(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point | None], GeometryArray[Point | None]]
nearest_points(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point | None], GeometryArray[Point | None]]
nearest_points(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryOtherT | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> tuple[GeometryArray[Point | None], GeometryArray[Point | None]]
nearest_points(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> (
    tuple[Point, Point]
    | tuple[GeometryArray[Point | None], GeometryArray[Point | None]]
)

Return the closest pair of points between two geometries.

The input Space defines source curves, and the selected metric measures them. Filled polygon interiors participate. A witness can lie inside an edge; the connecting line is shortest_line.

An empty operand yields (POINT EMPTY, POINT EMPTY), and the pair is dropped to the operands' common axes so it matches shortest_line's endpoints exactly.

Witness coordinates are numerical approximations to points on the inputs.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames. Unpack order is point on left, then on right.

required
right Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames. Unpack order is point on left, then on right.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
tuple of Point or tuple of GeometryArray

A (left_point, right_point) pair for scalar inputs, or a (left, right) pair of parallel witness point columns when either operand is a GeometryArray.

Raises:

Type Description
CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

See Also

distance : Minimum pairwise distance. shortest_line : Connecting line between closest points. dwithin : Within-distance test. hausdorff_distance : Hausdorff (set-to-set) similarity distance. frechet_distance : Curve-to-curve similarity (linestrings).

Examples:

>>> import gometry as gm
>>> square = gm.box(0, 0, 1, 1)
>>> a, b = gm.nearest_points(square, gm.Point(3, 0.5))
>>> (a.to_wkt(), b.to_wkt())
('POINT (1 0.5)', 'POINT (3 0.5)')

shortest_line

Accepted call forms
shortest_line(
    left: Geometry,
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> LineString
shortest_line(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString]
shortest_line(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString]
shortest_line(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryOtherT
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString]
shortest_line(
    left: Geometry,
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString | None]
shortest_line(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    right: Geometry,
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString | None]
shortest_line(
    left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryT | None
    ],
    right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
        GeometryOtherT | None
    ],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[LineString | None]
shortest_line(
    left: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    right: Geometry
    | (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
    *,
    unit: Literal['meters'] | None = None,
    metric: Literal['cartesian'] | Sphere | None = None,
) -> LineString | GeometryArray[LineString | None]

Return the shortest connecting line between two geometries (CRS-aware).

nearest_points as a connecting LineString — degenerate when the geometries touch. Planar and projected metrics accept any geometry pair, not only points, and the witness is the closest approach, so an endpoint may land on an edge interior rather than a vertex.

The input Space defines source curves and the selected metric measures them. Geographic results approximate the shortest physical connector in that Space's curve model; refinement can add intermediate vertices. A planar geographic connector must fit the inputs' retained longitude branch.

An empty operand yields LINESTRING EMPTY (the output-type sentinel, like distance's inf). Output ordinates are the operands' common axes (an XYZM line versus an XY point gives an XY line). See nearest_points for the witnesses and distance for their metric separation.

Parameters:

Name Type Description Default
left Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
right Geometry, GeometryArray, or iterable of Geometry or None

Scalar and sequence operands broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames.

required
unit 'meters'

None uses the selected metric's natural units. 'meters' requests meter output when the CRS and metric have compatible axes; Sphere metrics already use meters. Use metric='cartesian' to select coordinate-plane measurement.

'meters'
metric None, "cartesian", or Sphere

Measuring surface. Cartesian requires Planar Space; Sphere requires a geographic CRS. The default follows the CRS.

None

Returns:

Type Description
Geometry or GeometryArray

One connecting LineString per input pair.

Raises:

Type Description
CRSMismatchError

If the operands' CRS or coordinate-epoch metadata differ.

See Also

distance : Minimum pairwise distance. nearest_points : Closest-pair witness points. dwithin : Within-distance test. hausdorff_distance : Hausdorff (set-to-set) similarity distance. frechet_distance : Curve-to-curve similarity (linestrings).

Examples:

>>> import gometry as gm
>>> square = gm.box(0, 0, 1, 1)
>>> gm.shortest_line(square, gm.Point(3, 0.5)).to_wkt()
'LINESTRING (1 0.5, 3 0.5)'
>>> # The near point can fall mid-edge, not on a vertex:
>>> a = gm.from_wkt('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))')
>>> b = gm.from_wkt('POLYGON ((4 1, 5 0, 6 1, 5 2, 4 1))')
>>> gm.shortest_line(a, b).to_wkt()
'LINESTRING (2 1, 4 1)'