Geometry¶
Methods and properties shared by all geometry types.
Related: Geometry & dimensions
Geometry
¶
An immutable geometry with optional CRS.
The frozen scalar value at the heart of gometry: a point, linestring,
polygon, multi-part, or collection, carrying its coordinate
dimensionality (XY/XYZ/XYM/XYZM) and an optional CRS + epoch frame.
Construct with the leaf classes (Point(...), LineString(...)) or
parsers (from_wkt(...)),
inspect it (geom.bounds, geom.coords), relate it
(contains(geom, other)), measure it (geom.area — ellipsoidal square
meters of the longitude/latitude chart region on a geographic CRS), and
derive from it (geom.buffer(10.0)); every
operation returns a new geometry. Instances are one of the typed subclasses
(Point, LineString, Polygon, ...), so isinstance narrows.
area
property
¶
area: float
Area in CRS-natural units for the geometry's CRS.
A geographic CRS uses its ellipsoid by default, while the complete Space
still selects the represented paths and polygon interior: Planar keeps
coordinate-plane topology, Chart uses straight periodic longitude/
latitude edges, and Spherical uses great-circle arcs. Projected CRSs use
squared native linear units; CRS-free values use squared coordinate units.
Use to_space to transform coordinates or with_space to
deliberately reinterpret them.
A GeometryCollection counts overlapping members once, as the area
of their union. Parts of a valid MultiPolygon cannot overlap.
Returns:
| Type | Description |
|---|---|
float
|
The area; |
Raises:
| Type | Description |
|---|---|
CRSError
|
If the CRS lacks linear axis units for a metric result. |
See Also
length : Length/perimeter under the same CRS-aware metric.
bounds
property
¶
bounds: tuple[float, float, float, float] | None
Axis-aligned bounds (minx, miny, maxx, maxy), or None if empty.
Geographic bounds use periodic longitude; minx > maxx denotes an
interval crossing that frame's seam. Empty rows in a GeometryArray
are all-nan instead — see GeometryArray.bounds.
Returns:
| Type | Description |
|---|---|
tuple or None
|
|
coordinate_axes
property
¶
coordinate_axes: Literal['XY', 'XYZ', 'XYM', 'XYZM']
Ordinate layout: 'XY', 'XYZ', 'XYM', or 'XYZM'.
This is the coordinate layout (which ordinates are present), not the
topological dimension (see topological_dimension).
Returns:
| Type | Description |
|---|---|
str
|
The geometry's exact |
coords
property
¶
coords: Coordinates
Indexable, iterable view over this geometry's vertices.
Returns:
| Type | Description |
|---|---|
Coordinates
|
Flat, indexable view of vertex coordinates (X/Y and active Z/M). |
crosses_antimeridian
property
¶
crosses_antimeridian: bool
Whether a geographic geometry crosses the antimeridian.
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
CRSError
|
If the CRS is projected (a geographic CRS or CRS-free lon/lat is required). |
epoch
property
¶
epoch: float | None
Coordinate epoch of this geometry, if set.
Returns:
| Type | Description |
|---|---|
float or None
|
|
geometry_type
property
¶
geometry_type: Literal[
'Point',
'MultiPoint',
'LineString',
'MultiLineString',
'Polygon',
'MultiPolygon',
'GeometryCollection',
'CircularString',
'CompoundCurve',
'CurvePolygon',
'MultiCurve',
'MultiSurface',
'PolyhedralSurface',
'TIN',
'Triangle',
]
OGC geometry type name, e.g. 'Point' or 'MultiPolygon'.
Returns:
| Type | Description |
|---|---|
str
|
One of |
has_m
property
¶
has_m: bool
Whether the geometry carries an M ordinate.
Returns:
| Type | Description |
|---|---|
bool
|
|
has_z
property
¶
has_z: bool
Whether the geometry carries a Z ordinate.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_ccw
property
¶
is_ccw: bool
Whether a closed LineString, CircularString or CompoundCurve
winds counter-clockwise. False for open curves and every other kind.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_closed
property
¶
is_closed: bool
Whether every (multi)linestring component starts and ends at the same point.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_convex
property
¶
is_convex: bool
Whether the polygon is convex.
Every shell turn has one orientation — collinear edges allowed —
and there are no holes; the empty polygon is convex. Non-polygon
geometries return False.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_empty
property
¶
is_empty: bool
Whether the geometry is empty (no points, rings, or parts).
Returns:
| Type | Description |
|---|---|
bool
|
|
is_ring
property
¶
is_ring: bool
Whether the geometry is a closed, simple LineString (a ring).
Geographic closure uses quotient vertex identity and simplicity uses
the frame-aware topology; projected and CRS-free geometry remains planar.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_simple
property
¶
is_simple: bool
Whether the geometry has no self-intersections or self-tangencies.
Repeated CONSECUTIVE vertices are removable redundancy, not a
self-intersection, so they do not affect simplicity. Areal simplicity
is validity: a polygon/multipolygon
is simple exactly when it is is_valid — so holes outside the
shell, nested holes, or a disconnected interior make it not simple
even with no ring self-crossing. Collections are never simple.
Geographic simplicity uses the CRS longitude quotient, so periodic aliases and seam cuts do not depend on their stored spelling. Geographic coordinate-admission failures still raise; projected and CRS-free geometry remains planar.
Returns:
| Type | Description |
|---|---|
bool
|
|
is_valid
property
¶
is_valid: bool
Whether the geometry is topologically valid in its coordinate frame.
Geographic validity uses exact quotient topology, so period aliases and
seam cuts do not depend on their stored longitude spelling. An
out-of-domain latitude returns False and is reported by validate;
geographic operations that require coordinate admission still raise.
Projected and CRS-free geometry uses ordinary planar OGC validity.
A nonempty LineString needs at least two distinct XY positions;
consecutive repeats remain valid when another position is present.
True exactly when validate finds no issue; call
validate for the reason, location, and path of a failure, and
make_valid to fix it.
Returns:
| Type | Description |
|---|---|
bool
|
|
length
property
¶
length: float
Length (curves) or perimeter (areal), measured for the geometry's CRS.
A geographic CRS uses its ellipsoid by default, while the complete Space
still selects the represented paths: Planar keeps coordinate-plane
edges, Chart uses straight periodic longitude/latitude edges, and
Spherical uses great-circle arcs. Projected CRSs use native linear units;
CRS-free values use raw coordinate units. Use to_space to transform
coordinates or with_space to deliberately reinterpret them.
A GeometryCollection sums every member's length or perimeter,
including overlapping members.
Returns:
| Type | Description |
|---|---|
float
|
The length or perimeter; |
Raises:
| Type | Description |
|---|---|
CRSError
|
If the CRS lacks linear axis units for a metric result. |
See Also
area : Area under the same CRS-aware metric.
length_3d
property
¶
length_3d: float
3D length of curves with Z, measured for the geometry's CRS.
Geographic CRSs do not support 3D Euclidean length.
Returns:
| Type | Description |
|---|---|
float
|
|
Raises:
| Type | Description |
|---|---|
CRSError
|
If the CRS lacks linear axis units for a metric result. |
InvalidGeometryError
|
If the geometry lacks Z on every vertex. |
max_m
property
¶
max_m: float | None
Largest M ordinate, or None if no vertex carries M.
Returns:
| Type | Description |
|---|---|
float or None
|
|
max_z
property
¶
max_z: float | None
Largest Z ordinate, or None if no vertex carries Z.
Returns:
| Type | Description |
|---|---|
float or None
|
|
min_m
property
¶
min_m: float | None
Smallest M ordinate, or None if no vertex carries M.
Returns:
| Type | Description |
|---|---|
float or None
|
|
min_z
property
¶
min_z: float | None
Smallest Z ordinate, or None if no vertex carries Z.
Returns:
| Type | Description |
|---|---|
float or None
|
|
nbytes
property
¶
nbytes: int
Raw coordinate payload in bytes (numpy's nbytes convention): the
stored f64 ordinate columns only — object headers, prepared-state
caches, and CRS metadata are excluded.
Returns:
| Type | Description |
|---|---|
int
|
|
num_coordinates
property
¶
num_coordinates: int
Total number of coordinates in this geometry.
Returns:
| Type | Description |
|---|---|
int
|
|
num_geometries
property
¶
num_geometries: int
Number of top-level parts: 1 for a single-part geometry,
including a typed empty; the member count for a multi/collection, and
0 for an empty multipart or collection. Explicit empty members
still count in their multipart's member count.
Returns:
| Type | Description |
|---|---|
int
|
|
parts
property
¶
parts: GeometryParts[Geometry]
Lazy view over this geometry's top-level parts.
Simple geometries expose themselves as a one-row view; multipart and
collection geometries expose their members. GeometryArray(geom.parts)
materializes them as an array.
Returns:
| Type | Description |
|---|---|
GeometryParts
|
|
topological_dimension
property
¶
topological_dimension: Literal[0, 1, 2]
Topological dimension: 0 (point), 1 (curve), or 2 (surface).
The maximum over members for collections. Distinct from the coordinate
layout (see coordinate_axes).
Returns:
| Type | Description |
|---|---|
int
|
|
__bool__
¶
__bool__() -> bool
False when the geometry is empty; True otherwise.
Empty means a typed empty shape (for example POINT EMPTY), not
a missing array row.
Returns:
| Type | Description |
|---|---|
bool
|
|
affine_transform
¶
affine_transform(
matrix: tuple[float, float, float, float, float, float] | Iterable[float],
) -> Self
Apply a 2D affine transform (a, b, d, e, xoff, yoff) to a geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
matrix
|
sequence of float
|
The six affine coefficients (a, b, d, e, xoff, yoff). |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry (same kind as the input). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
Examples:
>>> import gometry as gm
>>> gm.LineString([(0, 0), (1, 1)]).affine_transform([2, 0, 0, 2, 1, 1]).to_wkt()
'LINESTRING (1 1, 3 3)'
boundary
¶
boundary() -> MultiPoint | LineString | MultiLineString | GeometryCollection
Return the topological boundary of the geometry's occupied support.
Returns:
| Type | Description |
|---|---|
MultiPoint, LineString, MultiLineString, or GeometryCollection
|
Boundary-location cells, one dimension below the effective dimension of the occupied support. A Polygon or MultiPolygon is evaluated as one union of polygonal support, so internal edges, collapsed interior spans, and ring edges outside that support are omitted. A GeometryCollection is processed member by member; non-empty member occurrences are retained. |
Notes
In a geographic CRS, seam aliases and all longitudes at a pole identify the same vertex. Edges introduced only by a chart cut or pole closure are not boundaries, although a seam vertex may appear where the geographic line emitter splits a run. The CRS and coordinate epoch are preserved; coordinates are not transformed. Source Z/M values are kept where emitted vertices have unambiguous ordinates; an axis is dropped when an emitted vertex has no value. Typed empty inputs keep their dimension-appropriate empty boundary.
Raises:
| Type | Description |
|---|---|
CRSError
|
If the declared CRS cannot be resolved to a topology frame. |
InvalidGeometryError
|
If a geographic coordinate read by boundary is outside its CRS domain. |
ResourceLimitError
|
If exact work exceeds the generated-item or embedding-search budget. |
OverflowError
|
If emitted cells cannot preserve the exact topology in binary64. |
Examples:
>>> import gometry as gm
>>> gm.box(0, 0, 2, 2).boundary().to_wkt()
'LINESTRING (0 0, 2 0, 2 2, 0 2, 0 0)'
buffer
¶
buffer(
distance: FloatScalar | ScalarFloatArray,
*,
cap_style: Literal['round', 'flat', 'square'] = 'round',
join_style: Literal['round', 'miter', 'bevel'] = 'round',
tolerance: FloatScalar | ScalarFloatArray | None = None,
miter_limit: FloatScalar | ScalarFloatArray = 5.0,
side: Literal['both', 'left', 'right'] = 'both',
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Polygon | MultiPolygon
Construct an XY buffer region while preserving the complete input Space.
The ordinary positive round buffer is the closed metric neighborhood, including selected source interiors. Negative distances erode areal support; a point or line has an empty buffer at nonpositive distance. Empty remains empty, and a full geographic surface remains full for every finite distance.
Geographic construction follows the retained Chart or Spherical source curves
on the selected measuring surface. Physical Planar geographic results stay on their
original longitude sheet; a pole-enclosing or full-period result requires
to_space() with a geographic Space. Cartesian construction requires Planar
Space. Every buffer synthesizes XY and preserves CRS and coordinate epoch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
float
|
Buffer radius; negative shrinks areal geometries. CRS-aware: geodesic meters on a geographic CRS, native linear units on a projected CRS, raw coordinate units when CRS-free. Must be finite. |
required |
cap_style
|
('round', 'flat', 'square')
|
End-cap shape at the original first and last vertices of open lines. Closed lines have no end caps.
Point inputs always buffer to round discs, and MultiPoint buffers are
unions of round discs; |
'round'
|
join_style
|
('round', 'miter', 'bevel')
|
Interior corner style for both two-sided and sided line buffers, including 180-degree reversals. |
'round'
|
tolerance
|
float or None
|
Scalar nonnegative finite positional target in the active construction
units. Automatic quality uses the sagitta of a 32-chord circle at
|
None
|
miter_limit
|
float
|
With |
5.0
|
side
|
('both', 'left', 'right')
|
Which side(s) of lineal input to buffer. |
'both'
|
metric
|
'cartesian'
|
Measuring surface, independent of the retained source curves. The default
uses the CRS-natural metric. |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Polygon or MultiPolygon
|
The selected buffer region. Point buffers are Polygon-valued, including Empty and geographic Full. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If coordinates are non-finite or buffer arithmetic produces a non-finite derived coordinate. |
GeometryError
|
If distance, tolerance, styles, metric or units are invalid, or the result
cannot be represented in its input Space. Geographic Planar branch errors
name |
ResourceLimitError
|
If required output or generated construction work exceeds its budget. |
GeometryTypeError
|
If |
See Also
offset_curve : Visible or raw signed source-corresponding line offsets.
Examples:
>>> import gometry as gm
>>> disc = gm.Point(0, 0).buffer(10)
>>> assert gm.covers(disc, gm.Point(0, 0))
build_area
¶
build_area() -> Polygon | MultiPolygon | GeometryCollection
Assemble linework into one areal geometry. Input ordinates are carried where vertices can be sourced; otherwise the mathematically planar result is XY. When returned polygons retain different coordinate axes, they remain separate members of a GeometryCollection rather than being promoted or flattened. The GeometryArray method processes rows independently; to assemble linework from several geometries as one area, combine them into one GeometryCollection first.
Returns:
| Type | Description |
|---|---|
Polygon, MultiPolygon, or GeometryCollection
|
The maximal areal geometry covered by the input. A GeometryCollection is returned only when multiple output polygons retain different coordinate axes; each polygon member preserves its own ordinates. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If the area cannot be assembled from the input linework. |
Examples:
>>> import gometry as gm
>>> edges = [[(0,0),(2,0)],[(2,0),(0,2)],[(0,2),(0,0)]]
>>> gm.MultiLineString(edges).build_area().to_wkt()
'POLYGON ((0 0, 2 0, 0 2, 0 0))'
centroid
¶
Center of mass on the selected measuring surface. Geographic input uses
the CRS ellipsoid by default; metric=Sphere() selects a sphere, with an
optional radius in meters. Regions contribute area, curves contribute length,
and points contribute equal mass; only the highest-dimensional mass contributes.
The result is projected radially onto that surface and returned as an XY point in
the source Space. Z and M do not contribute to mass. Empty input returns
POINT EMPTY; a nonempty input with no net direction returns POINT (0 0).
metric='cartesian' selects coordinate-plane measurement and requires a
Planar Space. Geographic input crossing the antimeridian is handled in its
declared Space.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
'cartesian'
|
|
'cartesian'
|
Returns:
| Type | Description |
|---|---|
Point
|
Area/length-weighted center; may lie outside the geometry. |
See Also
point_on_surface : A representative point guaranteed on the geometry. polylabel : Pole of inaccessibility (best label anchor).
Raises:
| Type | Description |
|---|---|
CRSError
|
If the selected metric is incompatible with the source CRS. |
InvalidGeometryError
|
If geographic measurement encounters a latitude outside the source CRS's pole limits. |
Examples:
>>> import gometry as gm
>>> (gm.box(0, 0, 2, 4).centroid()).to_wkt()
'POINT (1 2)'
concave_hull
¶
concave_hull(
*,
concavity: FloatScalar | ScalarFloatArray = 2.0,
length_threshold: FloatScalar | ScalarFloatArray = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
allow_holes: bool = False,
) -> Point | LineString | Polygon
Return one source-conforming concave hull of the complete represented
geometry, including retained linework and selected filled regions. Planar and
Spherical Spaces are supported; Chart Space must be converted with to_space.
The selected metric scores complete retained edges without changing their source
model. Original source locations supply scores and ordinates; scaffold-only
corners are never treated as input sites. Z and M come from retained source
correspondences; an ordinate axis is omitted when any published boundary site
lacks it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
concavity
|
float
|
Controls the distance guards on a candidate boundary edge of length |
2.0
|
length_threshold
|
float
|
Keep candidate edges at or below this selected-metric length. Must be finite
and non-negative, in the selected metric's units. For fixed input and
|
0.0
|
metric
|
'cartesian'
|
Select Cartesian measurement for Planar Space or a spherical measuring surface for geographic Space. Omission uses the CRS-based default. |
"cartesian"
|
unit
|
'meters'
|
Interpret |
"meters"
|
allow_holes
|
bool
|
By default the hull has one connected complement component: bounded planar
gaps and all but the selected spherical exterior are filled. |
False
|
Returns:
| Type | Description |
|---|---|
Point, LineString, or Polygon
|
One hull enclosing the complete source support. Empty inputs return an empty Polygon; lower-dimensional support may return a Point or LineString. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If a parameter is non-finite or negative, Chart Space is used, or the source-conforming hull cannot be represented as one connected Polygon. |
CRSError
|
If the CRS cannot provide the selected metric or a physical geographic coordinate is outside its longitude/latitude domain. |
See Also
convex_hull : Smallest convex set containing the geometry (planar).
Examples:
>>> import gometry as gm
>>> mp = gm.MultiPoint([(0, 0), (2, 0), (2, 2), (0, 2), (1, 0.2)])
>>> hull = mp.concave_hull(concavity=1.0)
>>> hull.geometry_type
'Polygon'
convex_hull
¶
convex_hull() -> Point | LineString | Polygon
Compute the convex hull of the geometry in a Planar or Spherical Space.
Convert geographic input to a Planar Space with to_space when a cut chart is
needed. Source vertices retained by the hull keep their
ordinates. Geographic hull construction can add chart-support vertices on
producer root edges; see the geometry guide's Z/M under operations section
for how their ordinates are carried. When several input vertices share an XY
position, the first in storage order is the copied survivor.
Returns:
| Type | Description |
|---|---|
Point, LineString, or Polygon
|
The convex hull; degenerate inputs reduce dimension. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If selected hull vertices have different coordinate axis layouts. |
See Also
concave_hull : Concave hull that can follow non-convex outlines.
Examples:
>>> import gometry as gm
>>> pts = gm.MultiPoint([(0, 0), (2, 0), (1, 1), (0, 2), (2, 2)])
>>> pts.convex_hull().to_wkt()
'POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))'
envelope
¶
envelope(
*,
tolerance: FloatScalar
| ScalarFloatArray
| (
FloatColumn
| ndarray[
tuple[int],
dtype[floating[Any] | signedinteger[Any] | unsignedinteger[Any]],
]
)
| None = None,
unit: Literal['meters'] | None = None,
) -> Point | LineString | Polygon | MultiPolygon
Return an XY enclosure in the input's complete Space. Planar and Chart values keep their coordinate-aligned envelope. Spherical values use selected support bounds and conservatively approximated spherical rectangle edges, so curved source arcs and selected poles remain enclosed. Latitude-degenerate point sets retain every source point on their parallel. Empty input returns a typed empty Polygon; nonempty degenerate bounds keep their Point or LineString dimension; Full remains Full.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float or sequence of float
|
Non-negative positional accuracy target. A scalar applies to every row. Omission selects a scale-aware target for Spherical approximation; exact Planar and Chart envelopes need no refinement. |
None
|
unit
|
'meters'
|
Unit for the Spherical approximation tolerance. The output always preserves the input's Space and epoch. |
'meters'
|
Returns:
| Type | Description |
|---|---|
Point, LineString, Polygon, or MultiPolygon
|
The XY envelope, retaining the input's Space and its degenerate dimension. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If coordinates are non-finite or outside the spherical coordinate domain. |
ResourceLimitError
|
If spherical boundary refinement exceeds its per-row generated-output budget. |
Examples:
>>> import gometry as gm
>>> gm.LineString([(0, 0), (3, 1)]).envelope().to_wkt()
'POLYGON ((0 0, 3 0, 3 1, 0 1, 0 0))'
estimate_local_crs
¶
estimate_local_crs() -> CRS
Estimate a conformal metric CRS for this geometry.
Every local frame retains the source geodetic datum. A datum-matched
UTM or UPS CRS is preferred when it meets the fixed 0.1% linear scale-
error ceiling; otherwise a transverse-Mercator frame centered on the
geometry is built on the source datum.
Empty, CRS-free, or geographically unsafe geometries raise CRSError.
Returns:
| Type | Description |
|---|---|
CRS
|
|
Raises:
| Type | Description |
|---|---|
CRSError
|
If the geometry has no CRS, is empty, or one safe local frame cannot represent its extent. |
Examples:
>>> import gometry as gm
>>> gm.Point(-122.4, 37.8, space=gm.Space(crs=4326)).estimate_local_crs()
CRS("EPSG:32610")
extremes
¶
Return the west, south, east, and north extreme vertices of the geometry (numeric X/Y; ties keep the first vertex in storage order).
Returns:
| Type | Description |
|---|---|
Extremes or None
|
The |
Examples:
>>> import gometry as gm
>>> extremes = gm.box(0, 0, 2, 4).extremes()
>>> assert extremes is not None # None only for an empty geometry
>>> (extremes.west.to_wkt(), extremes.north.to_wkt())
('POINT (0 0)', 'POINT (2 4)')
force_2d
¶
force_2d() -> Self
Drop Z and M ordinates, preserving geometry type and CRS. Already-2D input is returned unchanged.
Returns:
| Type | Description |
|---|---|
Geometry
|
The XY-only geometry (same kind as the input). |
See Also
force_3d : Add a Z ordinate, filling missing vertices.
Examples:
>>> import gometry as gm
>>> gm.from_wkt('POINT Z (1 2 3)').force_2d().to_wkt()
'POINT (1 2)'
force_3d
¶
force_3d(z: FloatScalar | ScalarFloatArray = 0.0) -> Self
Make each geometry 3D, filling vertices that lack Z with z. Vertices
that already carry Z keep it; M passes through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z
|
float
|
Finite Z to assign where it is missing. |
0.0
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with a Z ordinate on every vertex (same kind as the input). |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If |
See Also
force_2d : Drop Z and M to plain XY. with_coordinates : Replace individual coordinate ordinates.
Examples:
>>> import gometry as gm
>>> arr = gm.GeometryArray([gm.Point(1, 2)])
>>> arr.force_3d().to_wkt()[0]
'POINT Z (1 2 0)'
interpolate_m
¶
interpolate_m(
start_m: FloatScalar | ScalarFloatArray,
end_m: FloatScalar | ScalarFloatArray,
*,
overwrite: bool = False,
metric: Literal['cartesian'] | Sphere | None = None,
) -> Self
Assign M ordinates by cumulative length along the retained linework.
M runs from start_m to end_m across all parts, with no distance
added between parts. The selected metric measures the source curves without
changing them or rescaling the supplied M range. It determines the stored
values, not how M is later evaluated between vertices.
Every vertex, its X/Y and Z, and the Space are preserved. Existing M requires
overwrite=True. A zero-length X/Y segment has equal M values at both
ends. Empty linework stays empty and gains an M axis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_m
|
float
|
The measure range (finite, |
required |
end_m
|
float
|
The measure range (finite, |
required |
overwrite
|
bool
|
Replace existing M ordinates instead of raising. |
False
|
metric
|
'cartesian'
|
|
'cartesian'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with interpolated M values (same kind as the input). |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the geometry is not lineal. |
InvalidGeometryError
|
If the linework carries M without |
GeometryError
|
If the measure range is invalid. |
See Also
line_interpolate : Point at a distance or M location along the line. line_substring : Extract a contiguous portion of the line. line_locate : Locate the nearest route position on the line.
Examples:
>>> import gometry as gm
>>> line = gm.LineString([(0, 0), (10, 0)])
>>> line.interpolate_m(0.0, 100.0).to_wkt()
'LINESTRING M (0 0 0, 10 0 100)'
line_interpolate
¶
Accepted call forms
line_interpolate(
at: FloatScalar | ScalarFloatArray,
*,
basis: Literal['distance'] = 'distance',
count: None = None,
normalized: bool = False,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> Point
line_interpolate(
at: FloatColumn
| ndarray[
tuple[int],
dtype[floating[Any] | signedinteger[Any] | unsignedinteger[Any]],
],
*,
basis: Literal['distance'] = 'distance',
count: None = None,
normalized: bool = False,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[Point]
line_interpolate(
at: None = None,
*,
count: int | integer[Any],
basis: Literal['distance'] = 'distance',
normalized: Literal[False] = False,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[Point]
line_interpolate(
at: FloatColumn
| ndarray[
tuple[int],
dtype[floating[Any] | signedinteger[Any] | unsignedinteger[Any]],
],
*,
basis: Literal['m'],
count: None = None,
normalized: Literal[False] = False,
unit: None = None,
metric: None = None,
) -> GeometryArray[Point]
line_interpolate(
at: FloatScalar | ScalarFloatArray,
*,
count: None = None,
basis: Literal['m'],
normalized: Literal[False] = False,
unit: None = None,
metric: None = None,
) -> Point
Interpolate point locations along linework. Empty linework yields
POINT EMPTY at every location.
Distance-basis routes retain vertices at zero-length X/Y segments. At an
interior prefix shared by such a run, an exact boundary selects its first
stored vertex; normalized 0 and 1 select the first and last stored
vertices. M-basis interpolation follows the stored monotonic measure and keeps
vertices whose active Z/M ordinates differ even when X/Y is equal.
Distance stations follow cumulative length on the retained source edges under the selected metric. An independently interpolated geographic point uses canonical longitude; original endpoints retain their stored spelling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
at
|
float or sequence of float
|
One location or many explicit distance-basis locations. Under
For an array, numeric Empty station groups produce empty point groups; missing routes or station
groups produce missing groups. Empty routes yield one empty point per station.
A plain numeric sequence stays flat, including an empty sequence; only
|
required |
count
|
int
|
Number of evenly spaced distance-basis samples ( |
None
|
basis
|
('distance', 'm')
|
Use CRS-aware distance, or the line's monotonic M ordinate. Distance forms
omit |
'distance'
|
normalized
|
bool
|
Interpret distance-basis |
False
|
metric
|
'cartesian'
|
Measuring surface for distance stationing. With |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Point or GeometryArray[Point]
|
One point for scalar |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the geometry is not lineal. |
InvalidGeometryError
|
If M values are missing or non-monotonic. Array failures identify the original input row. |
GeometryError
|
If input forms conflict, a value is non-finite, or a distance-only option
is used with |
ResourceLimitError
|
If |
See Also
line_locate : Locate the nearest route position; repeated support makes the inverse non-unique. line_substring : Extract a contiguous portion of the line. interpolate_m : Assign M ordinates along arc length.
Examples:
>>> import gometry as gm
>>> line = gm.LineString([(0, 0), (10, 0)])
>>> line.line_interpolate(4).to_wkt()
'POINT (4 0)'
line_locate
¶
Accepted call forms
line_locate(
point: Point,
*,
basis: Literal['distance'] = 'distance',
normalized: bool = False,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> float
line_locate(
point: GeometryArray[Point | None],
*,
basis: Literal['distance'] = 'distance',
normalized: bool = False,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> NDArray[float64]
line_locate(
point: Point,
*,
basis: Literal['m'],
normalized: Literal[False] = False,
metric: Literal['cartesian'] | Sphere | None = None,
unit: None = None,
) -> float
line_locate(
point: GeometryArray[Point | None],
*,
basis: Literal['m'],
normalized: Literal[False] = False,
metric: Literal['cartesian'] | Sphere | None = None,
unit: None = None,
) -> NDArray[float64]
Locate the position on linework nearest point. Empty linework, or
an empty query point, locates to nan.
Projection is in X/Y. Zero-length X/Y segments add no distance-basis projection.
Planar distance-basis locate selects the exactly nearest segment; exact ties
prefer an interior projection over an endpoint, then the first segment in route
order, matching planar proximity. Geographic locate applies the same role and
source order when evaluated backend distances compare equal. It ranks available
measurements, including the chart projection trial, rather than asserting an
exact geodesic minimum. With basis='m', the returned M is taken from the
selected projection.
The Space defines the route: Planar segments retain their literal coordinate paths, Chart segments follow the longitude/latitude chart, and Spherical segments follow great-circle arcs. The selected metric measures that route without changing it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
point
|
Point or GeometryArray[Point | None]
|
A point to project, or one point per line row. Missing query rows produce
|
required |
basis
|
('distance', 'm')
|
Return a CRS-aware distance, or the line's monotonic M ordinate. Distance
forms omit |
'distance'
|
normalized
|
bool
|
Return a distance-basis fraction in [0, 1] under the selected metric.
Changing |
False
|
metric
|
'cartesian'
|
|
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
float or ndarray
|
One location, or a column when |
Raises:
| Type | Description |
|---|---|
CRSError
|
If the CRS cannot provide an unambiguous distance metric. |
CRSMismatchError
|
If operands' CRS or coordinate-epoch metadata differ. |
GeometryTypeError
|
If the geometry is not lineal. |
InvalidGeometryError
|
If M values are missing or non-monotonic. Array failures identify the original input row. |
GeometryError
|
If a distance-only option is used with |
See Also
line_interpolate : Point at a route station; locate/interpolate round-trip only at a unique nearest position. line_substring : Extract a contiguous portion of the line. interpolate_m : Assign M ordinates along arc length.
Examples:
>>> import gometry as gm
>>> line = gm.LineString([(0, 0), (10, 0)])
>>> line.line_locate(gm.Point(4, 3))
4.0
line_merge
¶
line_merge(*, directed: bool = False) -> LineString | MultiLineString
Merge connected LineString parts into longer LineStrings.
Joins occur only at degree-two endpoints, never across branching junctions.
With directed=True, join only a source end to a source start: no component's
coordinate order is reversed.
Directed merging keeps active-distinct endpoint occurrences at a join, so
different Z/M values at the same X/Y are retained as consecutive vertices.
Chart and Spherical endpoints join by physical site, including seam and pole
aliases. Chart publication can insert vertices to preserve authored longitude
travel. Spherical merging retains the original minor great-circle arcs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
directed
|
bool
|
Preserve the direction of every source coordinate sequence. |
False
|
Returns:
| Type | Description |
|---|---|
LineString or MultiLineString
|
The merged linework. |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the geometry is not lineal. |
Examples:
>>> import gometry as gm
>>> a, b = [(0, 0), (1, 1)], [(1, 1), (2, 2)]
>>> (gm.MultiLineString([a, b]).line_merge()).to_wkt()
'LINESTRING (0 0, 1 1, 2 2)'
line_substring
¶
Accepted call forms
line_substring(
start: FloatScalar | ScalarFloatArray,
end: FloatScalar | ScalarFloatArray,
*,
basis: Literal['m'],
normalized: Literal[False] = False,
unit: None = None,
metric: None = None,
) -> LineString | Point
line_substring(
start: FloatScalar | ScalarFloatArray,
end: FloatScalar | ScalarFloatArray,
*,
basis: Literal['distance'] = 'distance',
normalized: bool = False,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> LineString | Point
Return the portion of linework from start through end. Empty
linework yields LINESTRING EMPTY.
Both bounds are inclusive. Stored vertices at zero-length X/Y segments consume no distance but remain in the result when their active ordinates differ, including consecutive vertices with identical X/Y. This applies to distance and M basis.
Distance stations follow cumulative length on the retained source edges under the selected metric. New endpoints embedded in a retained source edge keep that edge's continuous longitude spelling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start
|
float or sequence of float
|
Ordered locations on the selected basis. Distance values follow the CRS; M values are stored route measures. A scalar applies to every array row. |
required |
end
|
float or sequence of float
|
Ordered locations on the selected basis. Distance values follow the CRS; M values are stored route measures. A scalar applies to every array row. |
required |
basis
|
('distance', 'm')
|
Use CRS-aware distance, or the line's monotonic M ordinate. Distance forms
omit |
'distance'
|
normalized
|
bool
|
Interpret distance-basis positions as fractions of the route length under
the selected metric. Changing |
False
|
metric
|
'cartesian'
|
Measuring surface for distance stationing. With |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
LineString or Point
|
The substring (a |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the geometry is not lineal. |
InvalidGeometryError
|
If M values are missing or non-monotonic. Array failures identify the original input row. |
GeometryError
|
If locations are non-finite or out of order, or a distance-only option is
used with |
See Also
line_interpolate : Point at a location along the line. line_locate : Locate the nearest route position on the line. interpolate_m : Assign M ordinates along arc length.
Examples:
>>> import gometry as gm
>>> line = gm.LineString([(0, 0), (10, 0)])
>>> line.line_substring(2, 6).to_wkt()
'LINESTRING (2 0, 6 0)'
linearize
¶
linearize(
*, quadrant_segments: int | None = None, max_deviation: float | None = None
) -> Geometry
Replace curves and surfaces with simple features.
Each circular arc becomes equal-angle chords through both of its stored
endpoints, as PostGIS ST_CurveToLine produces, and Z and M vary linearly
along the arc through its middle control point. CircularString and
CompoundCurve become LineString; CurvePolygon and Triangle
become Polygon; MultiCurve becomes MultiLineString; and
MultiSurface, PolyhedralSurface and TIN become MultiPolygon.
Straight-edged surfaces convert exactly, and simple features return
unchanged. The Space and coordinate axes are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
quadrant_segments
|
int
|
Chords per quarter circle, at least 1. The default is 32, as in PostGIS. |
None
|
max_deviation
|
float
|
Largest distance between an arc and its chords, in coordinate units. Pass
at most one of |
None
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with every arc replaced by chords. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If both parameters are given, or either is not positive. |
ResourceLimitError
|
If the chords would exceed the generated-vertex limit. |
Examples:
>>> import gometry as gm
>>> arc = gm.CircularString([(0, 0), (1, 1), (2, 0)])
>>> arc.linearize(quadrant_segments=1).to_wkt()
'LINESTRING (0 0, 1 1, 2 0)'
>>> len(arc.linearize().coords)
65
make_valid
¶
make_valid(
*, method: Literal['linework', 'structure'] = 'linework'
) -> Geometry
Repair invalid geometry, returning corrected result(s) (OGC). Already-valid input is returned unchanged at validation cost. Geographic repair checks exact quotient validity before rebuilding; when output construction needs seam vertices it splits the source while preserving traceable Z/M ordinates. Projected and CRS-free geometry remains planar. A collapsed LineString becomes a Point at its first coordinate. Collapsed MultiLineString members become a Point or MultiPoint, combined with surviving linework in a GeometryCollection when both dimensions remain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
('linework', 'structure')
|
Repair strategy: At rebuilt vertices, Z is the occurrence-weighted mean of eligible source values; M is retained when eligible measures agree. Each axis is resolved independently, and an unavailable axis is dropped from the affected result. |
'linework'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
A valid geometry. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If the geometry cannot be repaired. |
Examples:
>>> import gometry as gm
>>> bowtie = gm.from_wkt('POLYGON ((0 0, 2 2, 2 0, 0 2, 0 0))')
>>> fixed = bowtie.make_valid()
>>> (fixed.is_valid, fixed.geometry_type)
(True, 'MultiPolygon')
map_coordinate_sequences
¶
map_coordinate_sequences(func: Callable[[NDArray[float64]], ArrayLike]) -> Self
Map each line, ring, or point coordinate sequence independently.
The callback receives a read-only (N, D) float64 array in native
ordinate order (XY, XYZ, XYM, or XYZM). It may change N, but must retain
D and return finite coordinates. A point receives one coordinate and
may return zero or one. A multipoint receives its stored point sequence;
changing its size replaces its point membership, including empty slots.
Empty components are retained without calling the callback.
Parts, rings, CRS, epoch, and ordinate schemas stay with their source. Empty output empties a point or line, removes a hole, or empties a polygon whose rings all become empty. A nonempty hole with an empty shell is an error. Nonempty lines need two vertices; nonempty rings use constructor admission (three open corners, or four closed vertices, closed on all active ordinates). No validity repair is run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Per-sequence transformation, returning a two-dimensional matrix. |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
|
map_coordinates
¶
map_coordinates(func: Callable[[NDArray[float64]], ArrayLike]) -> Self
Apply a vectorized callback to this geometry's coordinate matrix.
The callback receives a read-only (N, dims) float64 matrix and must
return a matrix with the same shape. Topology, CRS, epoch, and ordinate
layout are preserved.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
callable
|
Function called with the read-only coordinate matrix. |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
|
Examples:
>>> import gometry as gm
>>> gm.LineString([(0, 0), (1, 1)]).map_coordinates(lambda m: m + 1).to_wkt()
'LINESTRING (1 1, 2 2)'
materialize
¶
materialize() -> Self
Return an independently owned copy of this geometry.
The copy preserves its geometry kind, coordinates, axes, complete Space, and selected polygon interior. It does not repair or normalize the geometry, and it does not retain prepared products owned by this value.
Returns:
| Type | Description |
|---|---|
Geometry
|
A copy with coordinate storage independent of the source. |
maximum_inscribed_circle
¶
Solve an inscribed circle of a polygonal geometry. The selected metric measures boundary clearance within the filled source support, including holes. The result retains the complete source Space. Empty support has an empty center and NaN radius. Full geographic support has an infinite radius and a deterministic center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Nonnegative finite absolute optimization target in the selected units. Zero requests the highest useful fidelity; None selects a scale-aware target. |
None
|
metric
|
'cartesian'
|
|
"cartesian"
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Circle
|
Retained circle solution; polygon construction is deferred until requested. |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the input is not polygonal. |
InvalidGeometryError
|
If invalid polygonal topology prevents the circle calculation. |
GeometryError
|
If tolerance is not finite and nonnegative or the metric is not admitted. |
See Also
minimum_bounding_circle : Smallest enclosing circle solution. polylabel : Approximate label anchor from a distinct floating-point search.
Examples:
>>> import gometry as gm
>>> circle = gm.box(0, 0, 2, 2).maximum_inscribed_circle()
>>> (circle.center.to_wkt(), circle.radius)
('POINT (1 1)', 1.0)
>>> circle.to_geometry().geometry_type
'Polygon'
minimum_bounding_circle
¶
Solve a circle enclosing the complete represented geometry. The selected metric measures distances to source points, curves and filled regions. The retained center and realization preserve the complete source Space. Empty support has an empty center and NaN radius.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Nonnegative finite absolute optimization target in the selected units, shared by all rows. Zero requests the highest useful fidelity. |
None
|
metric
|
'cartesian'
|
|
"cartesian"
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Circle
|
Retained circle solution. Empty input has an empty center and NaN radius. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the tolerance or measuring surface is invalid, or the physical disk cannot be represented on a Planar geographic source branch. |
Examples:
>>> import gometry as gm
>>> circle = gm.MultiPoint([(0, 0), (4, 0)]).minimum_bounding_circle()
>>> (circle.center.to_wkt(), circle.radius)
('POINT (2 0)', 2.0)
minimum_clearance
¶
minimum_clearance(
*,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> float
Minimum separation of original logical vertex sites and nonincident retained edges. Original sites belong to the input's closed support, including its interior. Duplicate model positions and an original edge's endpoint sites are excluded. A vertex touching an edge interior has zero clearance. Refinement introduces no sites. This feature separation is not a universal safe-edit radius.
The selected metric measures the input Space's original curves. Geographic physical distances default to meters on the CRS ellipsoid. Cartesian projected distances use native linear units; CRS-free distances use raw units. Explicit Cartesian measurement of geographic Planar input uses native angular units. No eligible pair gives infinity, including Empty, a bare Point, a duplicate-only MultiPoint and boundary-free Full. One surviving original site can still pair with nonincident retained edges whose endpoints are constructed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
None, ``cartesian``, or Sphere
|
Measuring metric, independent of the input Space. Cartesian requires a planar Space; Sphere requires a geographic CRS. Omitted follows the CRS. |
None
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
float
|
The minimum clearance distance. |
Examples:
>>> import gometry as gm
>>> gm.box(0, 0, 3, 2).minimum_clearance()
2.0
minimum_clearance_line
¶
minimum_clearance_line(
*,
unit: Literal['meters'] | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> LineString
Shortest connector realizing original-feature minimum_clearance.
The metric measures the input Space's original curves; refinement creates no
new clearance sites. The connector uses the same representation, admission and
refinement as shortest_line and preserves the input Space. A physical
connector may contain more than two coordinates when the model's edges differ
from the metric geodesic.
No eligible pair gives an empty LineString; actual zero separation gives a nonempty zero-length line. Missing rows remain missing. Endpoint fields use the original source resolver. Chart and Spherical field stationing uses the original CRS ellipsoid independently of the selected measuring surface.
A physical connector with a genuine planar longitude-branch, wrapping or pole
conflict raises GeometryError and requires explicit geographic conversion.
Numerical minimum_clearance remains available in that case.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
None, ``cartesian``, or Sphere
|
Measuring metric; omitted follows the CRS. Cartesian requires planar input. |
None
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
LineString
|
The realizing connector, preserving the input Space and eligible fields. |
See Also
minimum_clearance : The clearance distance itself.
Examples:
>>> import gometry as gm
>>> (gm.box(0, 0, 3, 2).minimum_clearance_line()).to_wkt()
'LINESTRING (0 0, 0 2)'
minimum_rotated_rectangle
¶
minimum_rotated_rectangle() -> Point | LineString | Polygon
Minimum-area rotated bounding rectangle. A computed areal rectangle is
returned in XY. A degenerate geographic result that follows source-edge support
can retain resolvable Z/M by the original edge's ellipsoidal arclength; see the
geometry guide's Z/M under operations section.
Returns:
| Type | Description |
|---|---|
Point, LineString, or Polygon
|
The minimum rotated rectangle (degenerate inputs reduce dimension). |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If the rotated rectangle cannot be computed. |
Examples:
>>> import gometry as gm
>>> rect = gm.box(0, 0, 2, 2).minimum_rotated_rectangle()
>>> gm.equals(rect, gm.box(0, 0, 2, 2))
True
minimum_width
¶
minimum_width(
*,
metric: Literal['cartesian'] | None = None,
unit: Literal['meters'] | None = None,
) -> float
Width of the narrowest parallel strip enclosing the geometry. Uses the complete convex hull, including all disconnected components. Holes do not reduce the width. This is distinct from minimum clearance and from the shorter side of the minimum-area rotated rectangle. A point or collinear support has width zero; empty input has width NaN.
Requires a planar Space and measures XY in its coordinate plane.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metric
|
'cartesian'
|
Use |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
float
|
Minimum strip width in the selected units. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the Space is not planar, the measurement metric is not Cartesian, or meters are requested without a compatible CRS. |
CRSError
|
If CRS resolution fails. |
OverflowError
|
If non-finite coordinates prevent the support calculation. |
Examples:
>>> import gometry as gm
>>> gm.box(0, 0, 4, 2).minimum_width()
2.0
node
¶
node() -> MultiLineString
Node linework by splitting every edge at all intersections. Input ordinates are carried where possible; unsourceable seam vertices yield XY.
Returns:
| Type | Description |
|---|---|
MultiLineString
|
The noded linework. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If noding fails on the input linework. |
Examples:
>>> import gometry as gm
>>> lines = gm.MultiLineString([[(0,0),(2,0)],[(1,-1),(1,1)]])
>>> noded = lines.node()
>>> (noded.num_geometries, noded.length)
(4, 4.0)
normalize
¶
normalize() -> Self
Return a geometry in canonical (normalized) form. The canonical form is the lexicographically smallest equivalent presentation: parts sort ascending, lines take their smaller direction (closed lines the smallest rotation), and polygon rings lead with their minimum vertex under RFC 7946 winding (exterior counter-clockwise, holes clockwise).
Returns:
| Type | Description |
|---|---|
Geometry
|
The canonical form (same kind as the input). |
Examples:
>>> import gometry as gm
>>> messy = gm.from_wkt('MULTIPOINT ((1 1), (0 0))')
>>> messy.normalize().to_wkt()
'MULTIPOINT ((0 0), (1 1))'
offset_curve
¶
offset_curve(
distance: FloatScalar | ScalarFloatArray,
*,
join_style: Literal['round', 'miter', 'bevel'] = 'round',
tolerance: FloatScalar | ScalarFloatArray | None = None,
miter_limit: FloatScalar | ScalarFloatArray = 5.0,
mode: Literal['clean', 'raw'] = 'clean',
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Point | LineString | MultiPoint | MultiLineString | GeometryCollection
Construct a signed line offset, keeping its visible boundary pieces by default.
Positive distance selects the source's left side; negative distance selects its
right side. Clean visibility uses the whole supplied lineal geometry's
two-sided styled buffer at abs(distance), with the same joins and miter
limit and round line-end caps. GeometryCollection member structure, including
emptied members, is retained. Array rows remain independent.
Both modes preserve Space, CRS, epoch and original-source Z/M. New cuts use original source parameters; artificial subdivisions add no attribute weight. Geographic source fields use the original CRS ellipsoid independently of a selected Sphere. A zero offset preserves the admitted source value. Available Z records are averaged at coalesced locations. M is retained only when eligible measures numerically agree; conflicts drop M from the output component independently of Z.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
distance
|
float
|
Offset; sign selects the side. CRS-aware: geodesic meters on a geographic CRS, native linear units on a projected CRS, raw coordinate units when CRS-free. Must be finite. |
required |
join_style
|
('round', 'miter', 'bevel')
|
Corner treatment at outside turns: |
'round'
|
tolerance
|
float or None
|
Scalar nonnegative finite positional target in the active construction
units. Automatic quality uses the sagitta of a 32-chord circle at
|
None
|
miter_limit
|
float
|
With |
5.0
|
mode
|
('clean', 'raw')
|
Omission selects |
'clean'
|
metric
|
'cartesian'
|
Measuring surface. Cartesian offsets require Planar Space. Physical offsets
preserve the original Chart, Spherical or Planar geographic interpretation
and require the supported local carried-style domain. Global focal or
repeated-wrap continuation is not supported. An unrepresentable Planar
geographic branch names |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
Visible offset support, possibly multipart, mixed-dimensional or empty. A single raw LineString yields a continuous LineString or a collapsed Point. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If distance, tolerance, styles, metric or units are invalid, or the requested construction is outside its supported domain or cannot preserve its Space. |
ResourceLimitError
|
If required output or generated construction work exceeds its budget. |
See Also
buffer : Offset region (optionally one-sided via side).
Examples:
>>> import gometry as gm
>>> path = gm.LineString([(0, 0), (4, 0)])
>>> shifted = path.offset_curve(1)
>>> assert shifted.space == path.space
orient_polygons
¶
orient_polygons(*, ccw: bool = True) -> Self
Orient polygon rings to a consistent winding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ccw
|
bool
|
|
True
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with ring winding normalized (same kind as the input). |
Examples:
>>> import gometry as gm
>>> cw = gm.Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
>>> cw.orient_polygons().exterior.is_ccw
True
point_on_surface
¶
point_on_surface() -> Point
Representative point guaranteed to lie on the geometry. Geographic input crossing the antimeridian is interpreted in its declared Space. The point lies inside or on the geometry, unlike centroid. Planar and Chart polygonal scanline candidates are checked after rounding, with a source boundary point used when no candidate is covered. Spherical Space uses spherical geometry rather than treating longitude and latitude as planar coordinates. The representative is computed in XY and does not imply source Z/M. On planar polygonal input, the first polygon component wins when representative chords have equal width. A GeometryCollection uses its highest-dimensional nonempty support.
See Also
centroid : Area/length-weighted center (may fall outside). polylabel : Pole of inaccessibility (best label anchor).
Returns:
| Type | Description |
|---|---|
Point
|
A point guaranteed to lie on the geometry. |
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If a finite representative point cannot be computed. |
Examples:
>>> import gometry as gm
>>> square = gm.box(0, 0, 2, 2)
>>> gm.within(square.point_on_surface(), square)
True
polygonize
¶
polygonize() -> GeometryArray[Polygon]
Build polygons from a geometry's own linework, automatically noding
crossings and overlaps. Each geometry is polygonized in isolation; to reconstruct
polygons from a pile of edges pooled across many geometries, use free function
polygonize_all on an iterable of
values. Input ordinates are carried where possible; unsourceable noding seams
yield XY.
Returns:
| Type | Description |
|---|---|
GeometryArray
|
The polygons built from the input linework. |
See Also
polygonize_all : Pool linework across all supplied geometries.
Raises:
| Type | Description |
|---|---|
InvalidGeometryError
|
If polygons cannot be assembled from the linework. |
Examples:
>>> import gometry as gm
>>> a, b = [(0, 0), (1, 0)], [(1, 0), (1, 1)]
>>> edges = gm.MultiLineString([a, b, [(1, 1), (0, 0)]])
>>> edges.polygonize().to_wkt()[0]
'POLYGON ((0 0, 1 0, 1 1, 0 0))'
polylabel
¶
Return an approximate most-distant point in a polygon for label placement.
The selected metric measures distance to the boundary of the filled support,
including holes. Geographic inputs retain their Space and use their source
curves rather than a local projected optimum.
Empty geometries return POINT EMPTY.
See Also
maximum_inscribed_circle : Retained inscribed circle with direct center access. centroid : Area/length-weighted center (may fall outside). point_on_surface : A representative point guaranteed on the geometry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Nonnegative finite absolute stopping target for the approximate label search,
interpreted for the CRS (see |
None
|
metric
|
'cartesian'
|
|
"cartesian"
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Point
|
The pole of inaccessibility. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If an explicit |
InvalidGeometryError
|
If the pole of inaccessibility cannot be computed. |
Examples:
>>> import gometry as gm
>>> gm.box(0, 0, 2, 2).polylabel().to_wkt()
'POINT (1 1)'
quantize
¶
quantize(precision: int | integer[Any]) -> Self
Round coordinates to a fixed number of decimal places.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
int
|
Decimal places to keep. Negative values round to tens, hundreds, and so
on. Every present X/Y/Z/M ordinate is rounded independently, with ties to
even, as with Python's |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
The rounded geometry (same kind as the input; vertices preserved). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If a rounded coordinate is outside the finite binary64 range. |
Examples:
>>> import gometry as gm
>>> gm.Point(2.3479218, 48.8589321).quantize(3).to_wkt()
'POINT (2.348 48.859)'
remove_repeated_points
¶
remove_repeated_points(
*,
tolerance: FloatScalar | ScalarFloatArray = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Self
Drop consecutive nearby coordinates while retaining the source path.
Candidates are measured from the last retained vertex. Deletion also checks the complete original span against its retained shortcut, including removed detail. Unresolved spans retain their vertices. Zero uses exact model positions; necessary longitude laps, directed half-turn records and pole departures survive. Retained vertices keep their own Z/M and selected polygon interiors are not reselected.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Finite non-negative distance scale in the selected metric. Geographic CRSs default to meters even for Planar values; projected CRSs use native linear units and CRS-free values use raw coordinate units. |
0.0
|
metric
|
None, 'cartesian', or Sphere
|
Measuring surface, independently of the curve model. Cartesian requires Planar values. |
None
|
unit
|
None or 'meters'
|
Override the tolerance's distance units. |
None
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The deduplicated geometry (same kind as the input). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
Examples:
>>> import gometry as gm
>>> stuttery = gm.LineString([(0, 0), (0, 0), (1, 1)])
>>> stuttery.remove_repeated_points().to_wkt()
'LINESTRING (0 0, 1 1)'
reverse
¶
reverse() -> Self
Reverse the vertex order of a geometry. Linework retains every stored vertex and its active Z/M ordinates, including equal-X/Y vertices, in reverse order.
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with vertex order reversed (same kind as the input). |
Examples:
>>> import gometry as gm
>>> line = gm.LineString([(0, 0), (1, 1), (2, 2)])
>>> line.reverse().to_wkt()
'LINESTRING (2 2, 1 1, 0 0)'
rotate
¶
rotate(
angle: FloatScalar | ScalarFloatArray,
*,
origin: Origin = 'centroid',
radians: bool = False,
) -> Self
Rotate a geometry about an origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
angle
|
float
|
Rotation angle (degrees by default; radians if |
required |
origin
|
str or sequence of float
|
Transform origin: |
'centroid'
|
radians
|
bool
|
Interpret |
False
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry (same kind as the input). |
Examples:
>>> import gometry as gm
>>> gm.Point(1, 0).rotate(90, origin=(0, 0)).quantize(6).to_wkt()
'POINT (0 1)'
sample_points
¶
sample_points(
count: int | integer[Any],
*,
seed: int | integer[Any] | Generator | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
) -> GeometryArray[Point]
Random points on the geometry. The sample space is its highest dimension: area weighted for areal input, length weighted for lineal input, and equal weight across point atoms.
Physical sampling is uniform in surface area or along the retained curve's physical arclength. Planar keeps literal coordinate-plane paths and longitude sheets, Chart keeps its lifted coordinate paths, and Spherical keeps its great-circle arcs. Geographic coordinates default to the CRS ellipsoid.
An explicit metric selects another measurement surface without changing
the source Space or its stored paths.
Sampling has no unit option: it has no distance-valued output or threshold,
so a constant unit rescaling cancels from its weights.
metric='cartesian' requires Planar Space and uses literal coordinate-plane
measure. For example, a horizontal Planar line from 170° to -170° contributes
340 coordinate units, not the 20° seam crossing of a Chart line.
Each logical member contributes separately, so overlapping members retain their sampling multiplicity. A zero-area polygon falls back to its linework, and zero-length linework falls back to vertices, like centroid.
An integer seed reproduces the same points for the same input and measure.
A broadcast seed derives distinct streams by logical row index; row zero agrees
with a scalar call. An explicit seed for a row uses the scalar stream for that
seed.
An empty geometry has nothing to sample and yields no points. Results retain the input Space. Sampled points are new XY locations, so they have no source Z/M.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count
|
int
|
Number of points to draw ( |
required |
seed
|
int, numpy.random.Generator, or None
|
An integer reproduces the sample stream. A Generator advances once to
seed the native stream. |
None
|
metric
|
'cartesian'
|
|
"cartesian"
|
Returns:
| Type | Description |
|---|---|
GeometryArray
|
The |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
ResourceLimitError
|
If |
Examples:
>>> import gometry as gm
>>> square = gm.box(0, 0, 10, 10)
>>> pts = square.sample_points(5, seed=42)
>>> (len(pts), all(p is not None and gm.within(p, square) for p in pts))
(5, True)
scale
¶
scale(
x_factor: FloatScalar | ScalarFloatArray,
y_factor: FloatScalar | ScalarFloatArray | None = None,
*,
origin: Origin = 'centroid',
) -> Self
Scale a geometry about an origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_factor
|
float
|
Scale factors along the X and Y axes; |
required |
y_factor
|
float
|
Scale factors along the X and Y axes; |
required |
origin
|
str or sequence of float
|
Transform origin: |
'centroid'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry (same kind as the input). |
Examples:
>>> import gometry as gm
>>> gm.box(0, 0, 1, 1).scale(2, 2, origin=(0, 0)).bounds
(0.0, 0.0, 2.0, 2.0)
segmentize
¶
Accepted call forms
segmentize(
max_length: FloatScalar | ScalarFloatArray,
/,
*,
fraction: None = None,
path: None = None,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Self
segmentize(
max_length: FloatScalar | ScalarFloatArray,
/,
*,
fraction: None = None,
path: Literal['geodesic', 'rhumb'],
metric: Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Self
segmentize(
max_length: None = None,
/,
*,
fraction: FloatScalar | ScalarFloatArray,
path: None = None,
metric: Literal['cartesian'] | Sphere | None = None,
unit: None = None,
) -> Self
segmentize(
max_length: None = None,
/,
*,
fraction: FloatScalar | ScalarFloatArray,
path: Literal['geodesic', 'rhumb'],
metric: Sphere | None = None,
unit: None = None,
) -> Self
Insert vertices along stored edges or explicitly selected routes.
By default, subdivision follows the source Space's edges, measured under
metric. path='geodesic' or path='rhumb' instead samples a route
between each pair of original vertices. The result reconnects those samples
using the source Space's edge model.
Projected geometries use native linear units, and CRS-free geometries use raw coordinate units.
Every original vertex survives unchanged — this operation only inserts. Consecutive equal-X/Y vertices with distinct active Z/M ordinates remain in their stored order; their zero-length segments are not subdivided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_length
|
float
|
Positive maximum segment length, interpreted for the CRS (see |
None
|
fraction
|
float
|
Fraction in |
required |
path
|
('geodesic', 'rhumb')
|
Route for inserted geographic vertices. |
'geodesic'
|
metric
|
'cartesian'
|
Measuring surface. |
'cartesian'
|
unit
|
'meters'
|
|
'meters'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The segmentized geometry (same kind as the input). |
Raises:
| Type | Description |
|---|---|
CRSError
|
If |
GeometryError
|
If neither or both constraints are supplied, |
OverflowError
|
If endpoint-preserving binary64 output cannot satisfy |
ResourceLimitError
|
If generated coordinates exceed the output budget. |
Examples:
>>> import gometry as gm
>>> gm.LineString([(0, 0), (4, 0)]).segmentize(2).to_wkt()
'LINESTRING (0 0, 2 0, 4 0)'
>>> # On a geographic CRS the bound is meters along the ellipsoid.
>>> line = gm.LineString([(0, 0), (1, 0)], space=gm.Space(crs=4326))
>>> len(list(line.segmentize(20_000).coords))
7
segments
¶
segments() -> GeometryArray[LineString]
Consecutive vertex pairs from each line and polygon ring, in source order.
Includes closing ring edges and repeated-coordinate pairs; never joins independent parts or rings. Points and empty geometries have no segments. Every segment retains its source ordinates, CRS, and epoch.
Returns:
| Type | Description |
|---|---|
GeometryArray[LineString]
|
|
self_intersections
¶
self_intersections() -> GeometryArray[Point]
Return points where the geometry coincides with itself. Reports proper linework
self-crossings, non-adjacent touches, the endpoints of collinear overlaps
(spikes and backtracks), contact between distinct parts, and duplicate point
coordinates; legal adjacent shared vertices, ring closures, and removable
repeated consecutive vertices are not nodes. For point/lineal input the
result is non-empty exactly when is_simple is False; areal input
diagnoses its rings' linework, and collections are diagnosed recursively.
Geographic diagnostics follow the CRS longitude quotient; projected and
CRS-free geometry remains planar. Points are XY only.
Returns:
| Type | Description |
|---|---|
GeometryArray
|
The distinct self-intersection points. |
Examples:
>>> import gometry as gm
>>> cross = gm.from_wkt('LINESTRING (0 0, 1 1, 1 0, 0 1)')
>>> cross.self_intersections().to_wkt()
['POINT (0.5 0.5)']
simplify
¶
simplify(
tolerance: FloatScalar | ScalarFloatArray,
*,
method: Literal['vw', 'dp'] = 'vw',
preserve_topology: bool = True,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Self
Simplify a geometry, dropping vertices below a tolerance. Two
algorithms, selected by method, both reading tolerance on the
same distance scale:
'vw'(Visvalingam-Whyatt, the default) removes the least visually significant vertices first — the smallest effective triangle spanned with its two neighbors — for a smoother, more natural cartographic result. The effective-area threshold istolerance**2 / 2.'dp'(Douglas-Peucker) uses distance to a retained shortcut. In spherical Space, each removal bounds the complete original normal-arc window, including arcs whose intermediate vertices were removed earlier.
Geographic VW measures the smaller physical filling of each deviation cycle on the selected surface, retaining literal Planar, periodic Chart, or spherical normal-arc edges. Geographic Planar and Chart DP use conservative chart-unit tolerance conversion. Conservative retention can keep extra vertices, especially near the poles. VW is an effective-area criterion, not a maximum-displacement guarantee. Retained vertices keep their qualified Z/M fields. Simplified spherical curves use canonical native XY.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Distance scale of removable detail in the selected metric's units. The default uses meters for geographic CRSs, native linear units for projected CRSs, and raw coordinate units when CRS-free. |
required |
method
|
('vw', 'dp')
|
|
'vw'
|
preserve_topology
|
bool
|
Preserve valid, non-collapsed components and their contacts, connectivity
and containment within each geometry, including nested collection and
point members. Extra vertices may be retained to preserve these relationships.
Separate array rows are simplified independently.
|
True
|
metric
|
'cartesian'
|
Select the measuring surface without changing stored coordinates or Space.
Geographic CRSs use their ellipsoid by default; |
'cartesian'
|
unit
|
'meters'
|
Override the resolved metric's tolerance scale. |
'meters'
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The simplified geometry (same kind as the input). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
CRSError
|
If a physical metric cannot be resolved, or geographic coordinates are outside their native latitude domain. |
See Also
coverage_simplify : Topology-preserving simplification across a polygonal coverage.
Examples:
>>> import gometry as gm
>>> wiggly = gm.LineString([(0, 0), (1, 0.1), (2, -0.1), (3, 0)])
>>> (wiggly.simplify(1.0)).to_wkt()
'LINESTRING (0 0, 3 0)'
skew
¶
skew(
x_angle: FloatScalar | ScalarFloatArray = 0.0,
y_angle: FloatScalar | ScalarFloatArray = 0.0,
*,
origin: Origin = 'centroid',
radians: bool = False,
) -> Self
Skew (shear) a geometry about an origin.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_angle
|
float
|
Shear angles along the X and Y axes (degrees by default; radians if
|
0.0
|
y_angle
|
float
|
Shear angles along the X and Y axes (degrees by default; radians if
|
0.0
|
origin
|
str or sequence of float
|
Transform origin: |
'centroid'
|
radians
|
bool
|
Interpret |
False
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry (same kind as the input). |
Examples:
>>> import gometry as gm
>>> gm.Point(0, 2).skew(x_angle=45, origin=(0, 0)).quantize(6).to_wkt()
'POINT (2 2)'
smooth
¶
smooth(
*,
tolerance: FloatScalar | ScalarFloatArray | None = None,
method: Literal['chaikin', 'catmull_rom'] = 'chaikin',
keep_endpoints: bool = True,
) -> Self
Smooth line and polygon boundary linework (planar).
Two algorithms, selected by method:
'chaikin'(the default) samples quadratic spans between neighboring edge midpoints. Open lines honorkeep_endpoints; polygon rings are always treated as cyclic.'catmull_rom'samples a centripetal cubic through every original vertex, regardless ofkeep_endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
float
|
Finite non-negative XY positional target in native coordinate units.
|
None
|
method
|
('chaikin', 'catmull_rom')
|
|
'chaikin'
|
keep_endpoints
|
bool
|
For open lines under |
True
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The smoothed geometry (same kind as the input). |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
Examples:
>>> import gometry as gm
>>> square = gm.box(0, 0, 1, 1)
>>> square.smooth().area < square.area
True
snap_to_grid
¶
Accepted call forms
snap_to_grid(
grid_size: FloatScalar
| ScalarFloatArray
| tuple[float, float]
| Iterable[float],
*,
origin: GridOrigin = (0.0, 0.0),
repair: Literal[False] = False,
) -> Self
snap_to_grid(
grid_size: FloatScalar
| ScalarFloatArray
| tuple[float, float]
| Iterable[float],
*,
origin: GridOrigin = (0.0, 0.0),
repair: bool = False,
) -> Geometry
Snap every coordinate onto a regular grid and clean the result. X/Y move to
the nearest origin + k * grid_size grid node; consecutive duplicate vertices
collapse, and parts that degenerate below their minimum become empty (the
PostGIS ST_SnapToGrid shape — output may be non-simple). Z/M ride on
surviving vertices. quantize is the decimal-rounding, vertex-preserving
sibling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid_size
|
float or tuple of float
|
Positive finite coordinate-space grid spacing — native angular units for
geographic CRSs, native linear units for projected CRSs, and raw
coordinate units when CRS-free. Pass one value for a square grid or
|
required |
origin
|
tuple of float
|
A grid node anchoring the lattice. |
(0.0, 0.0)
|
repair
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The snapped geometry; parts below their minimum degenerate to empty. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
InvalidGeometryError
|
If |
Examples:
>>> import gometry as gm
>>> jittery = gm.LineString([(0.12, 0.88), (2.49, 1.51)])
>>> jittery.snap_to_grid(grid_size=0.5).to_wkt()
'LINESTRING (0 1, 2.5 1.5)'
subdivide
¶
subdivide(*, max_vertices: int | integer[Any] = 256) -> GeometryArray[Geometry]
Split geometry into parts of bounded complexity. Recursively clips
across the longer axis until every part has at most max_vertices
coordinates (the PostGIS ST_Subdivide shape). Spherical linework and Chart
linework whose admitted longitude branch cannot use a literal rectangular cut
are divided at source vertices, as is linework with no representable cut. Parts cover
the input up to binary64 rounding at constructed cut vertices. Source
ordinates are carried where meaningful; synthesized clip vertices use the
operation's natural XY result. On geographic input, recursively generated cut
vertices remain traced to their original source edges, including across seam
pieces; they are not re-interpolated from an edge fragment created by an earlier
cut.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_vertices
|
int
|
Maximum coordinates per part (at least |
256
|
Returns:
| Type | Description |
|---|---|
GeometryArray
|
The parts of the input geometry, in input order. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
OverflowError
|
If exact partitioning cannot produce parts within the requested bound. |
ResourceLimitError
|
If generated output exceeds its budget. |
Examples:
>>> import gometry as gm
>>> parts = gm.LineString([(i, 0) for i in range(20)]).subdivide(max_vertices=8)
>>> len(parts)
4
swap_xy
¶
swap_xy() -> Self
Swap the X and Y ordinate of every coordinate (Z/M untouched). The axis-
order repair for data delivered latitude-first: gometry is always (x, y)
= (lon, lat), so latitude-ordered input swaps once on ingest.
Returns:
| Type | Description |
|---|---|
Geometry
|
The geometry with X and Y swapped (same kind as the input). |
Examples:
>>> import gometry as gm
>>> latitude_first = gm.Point(52.5, 13.4)
>>> latitude_first.swap_xy().to_wkt()
'POINT (13.4 52.5)'
to_arrow
¶
to_arrow(*, encoding: Literal['auto', 'wkb'] = 'auto') -> PyArrowArray
Export the geometry as a GeoArrow array.
Geographic export may canonicalize longitude aliases, split parts and add rounded seam vertices or pole closures. Original Z/M occurrences remain; seam Z/M uses native source arclength and pole closures extend incident endpoint values. This is a finite drawing, not a lossless raw coordinate codec or a guarantee of identical source-point incidence. The complete Space is retained in GeoArrow metadata. Planar and Spherical values are supported; Chart values must first be converted to a supported model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding
|
('auto', 'wkb')
|
|
'auto'
|
Returns:
| Type | Description |
|---|---|
object
|
|
Raises:
| Type | Description |
|---|---|
ModuleNotFoundError
|
If PyArrow is not installed. |
GeometryError
|
If |
CRSError
|
If CRS metadata cannot be serialized for Arrow export. |
InvalidGeometryError
|
If a geographic geometry has coordinates outside its CRS domain. |
Examples:
>>> import gometry as gm
>>> type(gm.Point(1, 2).to_arrow()).__name__
'ExtensionArray'
to_geojson
¶
to_geojson() -> str
Serialize Planar coordinates as GeoJSON text. GeoJSON uses OGC:CRS84
longitude/latitude order under RFC 7946 and carries no source CRS label.
CRS-tagged input must use the 2D WGS 84 geographic family
(EPSG:4326 or OGC:CRS84) or the 3D longitude/latitude/height family
(EPSG:4979 or OGC:CRS84h); reproject other CRS values first. CRS-free
input is explicitly assumed to already be WGS84 longitude/latitude. Coordinates
outside longitude [-180, 180] or latitude [-90, 90] are rejected.
Antimeridian-crossing Planar segments retain their stored endpoints; this
writer does not split or densify them. Convert Chart or Spherical values to
Planar Space before export.
Unsupported Z/M axes raise an error rather than being silently discarded. Remove them explicitly with force_2d(), with_coordinates(z=None), or with_coordinates(m=None).
GeoJSON cannot represent M; drop it with with_coordinates(m=None) (or force_2d()).
Coordinate epoch is not represented in GeoJSON.
Returns:
| Type | Description |
|---|---|
str
|
The |
Raises:
| Type | Description |
|---|---|
CRSError
|
If the input carries a CRS outside the 2D/3D WGS84 longitude/latitude family. |
InvalidGeometryError
|
If input carries M ordinates; drop them with |
GeometryError
|
If coordinates cannot be represented in GeoJSON."; |
See Also
from_geojson : Parse GeoJSON back into a geometry.
Examples:
>>> import gometry as gm
>>> gm.Point(1, 2).to_geojson()
'{"type":"Point","coordinates":[1.0,2.0]}'
to_geoparquet
¶
to_geoparquet(
path: str | PathLike[str] | BinaryIO | PyArrowNativeFile,
*,
attributes: PyArrowTable | Mapping[str, Any] | None = None,
encoding: Literal['wkb', 'geoarrow', 'geometry'] = 'wkb',
**kwargs: Any,
) -> None
Write this geometry as a single-row GeoParquet file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str, path-like, or binary stream
|
Output Parquet path or caller-owned binary writable stream. Text streams are not supported; the writer leaves streams open. |
required |
attributes
|
Table or mapping
|
Single-row attribute columns written beside the geometry column. |
None
|
encoding
|
str
|
|
"wkb"
|
kwargs
|
mapping
|
Additional options forwarded to |
{}
|
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the encoding is unknown, attributes clash with the geometry column or mismatch the row count, or a GeoParquet 1.1 encoding carries M. |
ModuleNotFoundError
|
If PyArrow is not installed. |
Examples:
>>> import gometry as gm
>>> import tempfile, os
>>> path = tempfile.mktemp(suffix='.parquet')
>>> gm.Point(1, 2, space=gm.Space(crs=4326)).to_geoparquet(path)
>>> os.path.getsize(path) > 0
True
to_polyline
¶
to_polyline(*, precision: int = 5) -> str
Encode the LineString or Point as Google polyline text (see
from_polyline).
Unsupported Z/M axes raise an error rather than being silently discarded. Remove them explicitly with force_2d(), with_coordinates(z=None), or with_coordinates(m=None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
precision
|
int
|
Decimal digits encoded per ordinate ( |
5
|
Returns:
| Type | Description |
|---|---|
str
|
The encoded polyline. |
Raises:
| Type | Description |
|---|---|
GeometryTypeError
|
If the geometry is not a |
CRSError
|
If the CRS is set and is not EPSG:4326 longitude/latitude. |
InvalidGeometryError
|
If the geometry carries Z/M, or a coordinate is outside the
longitude/latitude domain. Flatten explicitly with |
GeometryError
|
If |
See Also
from_polyline : Decode Google polyline text into geometries.
Examples:
>>> import gometry as gm
>>> gm.LineString([(-120.2, 38.5), (-120.95, 40.7)]).to_polyline()
'_p~iF~ps|U_ulLnnqC'
to_space
¶
to_space(
space: Space,
*,
area_of_interest: CrsAreaInput | None = None,
authority: str | None = None,
accuracy: FloatScalar | ScalarFloatArray | None = None,
allow_ballpark: bool | None = None,
only_best: bool | None = None,
force_over: bool = False,
tolerance: FloatScalar | ScalarFloatArray | None = None,
unit: Literal['meters'] | None = None,
) -> Geometry
Transform the complete represented geometry into a target Space.
Curves are refined when the target cannot represent their coordinate image directly. Polygon shell and hole ownership and selected interiors are carried through the transformation. Geometry kind may change when the image splits or collapses; a GeometryCollection retains its member structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
Space
|
Complete target interpretation, including CRS, model and epoch. |
required |
area_of_interest
|
sequence of float
|
Bounding |
None
|
authority
|
str
|
Restrict candidate coordinate operations to this authority. |
None
|
accuracy
|
float
|
Maximum acceptable coordinate-operation accuracy, in meters. |
None
|
allow_ballpark
|
bool
|
Allow low-accuracy ballpark operations when no precise one exists. |
None
|
only_best
|
bool
|
Use only the single best operation; no fallback. |
None
|
force_over
|
bool
|
Preserve coordinates on the source side of the antimeridian instead
of wrapping them into |
False
|
tolerance
|
float
|
Nonnegative target-space error target for representing transformed curves. Omission selects the operation's default target. |
None
|
unit
|
'meters'
|
Interpret |
"meters"
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry in the requested Space. Its kind may change. |
Raises:
| Type | Description |
|---|---|
CRSError
|
If a nonempty geometry requires transformation but exactly one
endpoint lacks CRS metadata, or |
TransformError
|
If no coordinate operation exists or it fails, or the represented path cannot be transformed continuously. |
GeometryError
|
If a transformed path or selected region cannot be represented in the
target model, |
to_space_vertices
¶
to_space_vertices(
space: Space,
*,
area_of_interest: CrsAreaInput | None = None,
authority: str | None = None,
accuracy: FloatScalar | ScalarFloatArray | None = None,
allow_ballpark: bool | None = None,
only_best: bool | None = None,
force_over: bool = False,
) -> Self
Transform stored vertices into a complete target Space.
Geometry kind and component layout are retained. Intervening curves are reconnected between transformed vertices without approximation, so this method does not claim shape preservation. Target-model admission still checks geographic coordinates, spherical edges and selected polygon regions.
Z follows the coordinate operation's computed output and remains an ordinate when the target CRS is 2D. A 2D source CRS cannot feed a geocentric target from a carried Z alone; the source Space must declare a physical 3D CRS and the geometry must contain Z. Geocentric source Z participates in transformed X/Y; a geocentric source without Z cannot supply a 2D target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
Space
|
Complete target interpretation, including CRS, model and epoch. |
required |
area_of_interest
|
sequence of float
|
Bounding |
None
|
authority
|
str
|
Restrict candidate coordinate operations to this authority. |
None
|
accuracy
|
float
|
Maximum acceptable coordinate-operation accuracy, in meters. |
None
|
allow_ballpark
|
bool
|
Allow low-accuracy ballpark operations when no precise one exists. |
None
|
only_best
|
bool
|
Use only the single best operation; no fallback. |
None
|
force_over
|
bool
|
Preserve coordinates on the source side of the antimeridian instead
of wrapping them into |
False
|
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed vertices in the requested Space. |
Raises:
| Type | Description |
|---|---|
CRSError
|
If exactly one endpoint lacks CRS metadata. |
TransformError
|
If no coordinate operation exists or it fails to apply. |
GeometryError
|
If transformed coordinates or selected regions are inadmissible in the target model. |
to_wkb
¶
to_wkb(
*,
srid: Literal['auto'] | SupportsIndex | None = None,
srids: Mapping[int, CrsInput] | None = None,
convention: Literal['left', 'smaller', 'postgis_geography'] | None = None,
) -> bytes
Serialize to Well-Known Binary.
Unsupported Z/M axes raise an error rather than being silently discarded. Remove them explicitly with force_2d(), with_coordinates(z=None), or with_coordinates(m=None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srid
|
None, 'auto', or int
|
Omit the identifier, select the value's explicit EPSG or PostGIS wire-alias code, or emit the supplied destination identifier (including zero). |
None
|
srids
|
mapping[int, CRS - like]
|
Validate an emitted nonzero identifier in this destination namespace
against the geometry CRS. Under |
None
|
convention
|
('left', 'smaller', 'postgis_geography')
|
Encode geographic polygon boundaries under a declared ring convention.
|
"left"
|
Returns:
| Type | Description |
|---|---|
bytes
|
The WKB payload. |
Notes
The coordinate epoch is not representable in (E)WKB and does not survive a round-trip; use Arrow interchange when the epoch matters.
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the selected region cannot be represented by the requested convention,
a convention is unsupported or conflicts with the selected Space,
or the string value of |
InvalidGeometryError
|
If |
CRSError
|
If |
CRSMismatchError
|
If the destination namespace maps the emitted identifier to a different CRS. |
TypeError
|
If |
OverflowError
|
If |
See Also
from_wkb : Parse WKB/EWKB back into a geometry.
Examples:
>>> import gometry as gm
>>> pt = gm.Point(1, 2)
>>> pt.to_wkt() == gm.from_wkb(pt.to_wkb()).to_wkt()
True
to_wkt
¶
to_wkt(
*,
srid: Literal['auto'] | SupportsIndex | None = None,
srids: Mapping[int, CrsInput] | None = None,
convention: Literal['left', 'smaller', 'postgis_geography'] | None = None,
) -> str
Serialize to Well-Known Text.
Unsupported Z/M axes raise an error rather than being silently discarded. Remove them explicitly with force_2d(), with_coordinates(z=None), or with_coordinates(m=None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
srid
|
None, 'auto', or int
|
Omit the identifier, select the value's explicit EPSG or PostGIS wire-alias code, or emit the supplied destination identifier (including zero). |
None
|
srids
|
mapping[int, CRS - like]
|
Validate an emitted nonzero identifier in this destination namespace
against the geometry CRS. Under |
None
|
convention
|
('left', 'smaller', 'postgis_geography')
|
Encode geographic polygon boundaries under a declared ring convention.
|
"left"
|
Returns:
| Type | Description |
|---|---|
str
|
The WKT string. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If the selected region cannot be represented by the requested convention,
a convention is unsupported or conflicts with the selected Space,
or the string value of |
InvalidGeometryError
|
If |
CRSError
|
If |
CRSMismatchError
|
If the destination namespace maps the emitted identifier to a different CRS. |
TypeError
|
If |
OverflowError
|
If |
See Also
from_wkt : Parse WKT back into a geometry.
Examples:
>>> import gometry as gm
>>> gm.Point(1.5, 2.5).to_wkt()
'POINT (1.5 2.5)'
>>> gm.GeometryArray([gm.Point(1.5, 2.5)]).to_wkt()
['POINT (1.5 2.5)']
translate
¶
translate(
x_offset: FloatScalar | ScalarFloatArray,
y_offset: FloatScalar | ScalarFloatArray,
) -> Self
Translate a geometry by (x_offset, y_offset).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_offset
|
float
|
Offsets along the X and Y axes. |
required |
y_offset
|
float
|
Offsets along the X and Y axes. |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
The transformed geometry (same kind as the input). |
Examples:
>>> import gometry as gm
>>> gm.Point(1, 2).translate(10, 20).to_wkt()
'POINT (11 22)'
triangulate
¶
Accepted call forms
triangulate(
*,
method: Literal['earcut'],
metric: Literal['cartesian'] | Sphere | None = None,
tolerance: None = None,
min_angle: None = None,
max_area: None = None,
) -> GeometryArray[Polygon]
triangulate(
*,
method: Literal['delaunay'],
metric: Literal['cartesian'] | Sphere | None = None,
tolerance: FloatScalar | ScalarFloatArray | None = None,
min_angle: None = None,
max_area: None = None,
) -> GeometryArray[Polygon]
triangulate(
*,
method: Literal['constrained'],
metric: Literal['cartesian'] | Sphere | None = None,
tolerance: None = None,
min_angle: FloatScalar | ScalarFloatArray | None = None,
max_area: FloatScalar | ScalarFloatArray | None = None,
) -> GeometryArray[Polygon]
Triangulate geometry with an explicit algorithm.
Point-site Delaunay uses the Planar coordinate plane or Spherical great-circle model; Chart point sites must be converted to Planar or Spherical Space. Region Earcut and constrained triangulation retain the source Space and edge model. Selecting a Sphere for a geographic region does not reinterpret its source edges or source ordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
('earcut', 'delaunay', 'constrained')
|
Required algorithm choice: |
'earcut'
|
metric
|
'cartesian'
|
For point-site Delaunay, |
"cartesian"
|
tolerance
|
float
|
Nonnegative point-site accuracy target, in coordinate units for Planar
Space or meters for Spherical Space. Valid with |
None
|
min_angle
|
float
|
Minimum triangle angle in degrees, finite from 0 through 180. Zero disables
the angle target. Valid with |
None
|
max_area
|
float
|
Positive finite maximum area in the selected metric. Cartesian uses squared
coordinate units; physical geographic metrics use square meters. Valid with
Setting either option enables refinement; without either option, duplicate XY sites use their first source occurrence and triangle corners preserve the selected source ordinates. Refinement inserts Steiner vertices and therefore returns uniform XY. Area refinement makes progress independently of an unattainable angle target. Targets are best effort: constrained boundaries and a complete valid mesh remain mandatory. Boundary samples follow the retained source curves, with shared edges using the same samples. |
None
|
Returns:
| Type | Description |
|---|---|
GeometryArray[Polygon]
|
The generated triangles. Delaunay methods return counter-clockwise triangles starting at their smallest XY corner, sorted by corner coordinates. |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If a quality constraint is invalid or method-specific options are used with the wrong algorithm, or the selected construction cannot be produced. |
CRSError
|
If the Space model and selected construction metric are incompatible. |
OverflowError
|
If a boundary Steiner point cannot be represented at float resolution;
|
ResourceLimitError
|
If refinement exceeds the generated-output budget. |
InvalidGeometryError
|
If the input polygon is invalid or the triangulation cannot be constructed. |
Examples:
>>> import gometry as gm
>>> sites = gm.MultiPoint([(0, 0), (2, 0), (1, 2), (1, 0.5)])
>>> tris = sites.triangulate(method='delaunay')
>>> (len(tris), tris.geometry_type[0])
(3, 'Polygon')
unique_points
¶
unique_points() -> MultiPoint | GeometryCollection
Distinct vertices in first-occurrence order. Vertices compare by exact
structural identity (every active ordinate by bit pattern, the
equals_identical notion), so XYZ points that differ only in Z stay
distinct.
Returns:
| Type | Description |
|---|---|
MultiPoint or GeometryCollection
|
The distinct vertices. Homogeneous surviving vertices use a |
Notes
A heterogeneous result follows ordinary GeometryCollection semantics:
is_simple is false by convention and structural equality remains type-sensitive.
Mixed-axis and collection exports use WKB for Arrow interchange; see
Arrow & storage.
See Also
remove_repeated_points : Collapse consecutive duplicate vertices in place, keeping the geometry kind.
Examples:
>>> import gometry as gm
>>> loop = gm.LineString([(0, 0), (1, 1), (0, 0), (2, 2)])
>>> loop.unique_points().to_wkt()
'MULTIPOINT ((0 0), (1 1), (2 2))'
validate
¶
validate() -> ValidationReport
Structured validity report in the geometry's coordinate frame.
Geographic validity reads exact quotient topology, so period aliases and seam
cuts do not depend on their stored longitude spelling. An out-of-domain
latitude is reported as latitude_out_of_range; geographic operations that
require coordinate admission still raise.
For quotient-topology issues, the location is a canonical coordinate of the issue's contact set, chosen deterministically by minimum latitude then longitude.
Projected and CRS-free geometry uses ordinary
planar OGC validity. A nonempty LineString with fewer than two distinct XY
positions is invalid and reports line_collapsed.
Returns:
| Type | Description |
|---|---|
ValidationReport
|
Truthy when valid. |
See Also
is_valid : Boolean-only test. repair : Fix what the report diagnoses.
Examples:
>>> import gometry as gm
>>> bowtie = gm.from_wkt('POLYGON ((0 0, 2 2, 2 0, 0 2, 0 0))')
>>> report = bowtie.validate()
>>> (report.is_valid, report.reason)
(False, 'exterior ring has a self-intersection')
voronoi
¶
Accepted call forms
voronoi(
*,
output: Literal['polygons'] = 'polygons',
tolerance: FloatScalar | ScalarFloatArray | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
clip: Polygon | MultiPolygon | None = None,
) -> GeometryArray[Polygon | MultiPolygon]
voronoi(
*,
output: Literal['edges'],
tolerance: FloatScalar | ScalarFloatArray | None = None,
metric: Literal['cartesian'] | Sphere | None = None,
clip: Polygon | MultiPolygon | None = None,
) -> GeometryArray[LineString]
Construct a Voronoi diagram from the geometry's vertices.
Planar sites use Cartesian distance in their coordinate plane, including when they have a geographic CRS. Spherical sites use great-circle distance over the whole surface. Chart sites require conversion to a Planar or Spherical Space. Outputs retain the sites' complete Space.
Distinct sites retain first-occurrence order. A clipped cell with no area remains a typed empty cell in that position. One spherical site owns Full or the supplied clip. Shared cell boundaries are published once and reused by both adjacent cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
('polygons', 'edges')
|
Return clipped Voronoi cells or the internal Voronoi edges. The polygon
form omits |
'polygons'
|
tolerance
|
float or None
|
Finite nonnegative publication target in meters for Spherical sites. None selects the automatic target of 0.1 meters; zero requests the highest useful accuracy. The target guides refinement, not site snapping or merging, and is not a guaranteed error bound. Planar diagrams already use their fixed construction precision and do not require refinement. |
None
|
metric
|
'cartesian'
|
|
'cartesian'
|
clip
|
Polygon or MultiPolygon
|
Restrict the diagram to this region in the same complete Space.
|
None
|
Returns:
| Type | Description |
|---|---|
GeometryArray[Polygon | MultiPolygon] or GeometryArray[LineString]
|
The selected output for the scalar geometry's vertices. |
Raises:
| Type | Description |
|---|---|
OverflowError
|
If the output cannot be represented in binary64. |
ResourceLimitError
|
If generated output or the embedding search exceeds its budget. |
InvalidGeometryError
|
If the clip or constructed diagram cannot be admitted for publication. |
GeometryError
|
If the input is in Chart Space or the selected metric does not match the model. |
Examples:
>>> import gometry as gm
>>> sites = gm.MultiPoint([(0, 0), (2, 0), (1, 2)])
>>> len(sites.voronoi())
3
>>> len(sites.voronoi(output='edges'))
3
with_coordinates
¶
Accepted call forms
with_coordinates(
coordinates: Sequence[Sequence[float]]
| ndarray[
tuple[int, int],
dtype[
floating[Any] | signedinteger[Any] | unsignedinteger[Any] | bool_
],
]
| Coordinates,
/,
) -> Self
with_coordinates(
coordinates: None = None,
/,
*,
x: FloatScalar | ScalarFloatArray | FloatColumn = ...,
y: FloatScalar | ScalarFloatArray | FloatColumn = ...,
z: FloatScalar | ScalarFloatArray | FloatColumn | None = ...,
m: FloatScalar | ScalarFloatArray | FloatColumn | None = ...,
) -> Self
Return a geometry with selected coordinate ordinates replaced.
Pass one (N, dims) matrix (including a Coordinates view), or
replace any of x=, y=, z=, and m= by a scalar or a
column over the flattened coordinate sequence. Omitted ordinates are
preserved. z=None and m=None remove those dimensions; X and Y
cannot be removed. Matrix and column modes cannot be mixed. Calling
without arguments returns an unchanged value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coordinates
|
sequence of float
|
Replacement |
None
|
x
|
float, sequence of float, or None
|
Replace one ordinate by a scalar broadcast over vertices or a
column with one value per coordinate. Omitted ordinates are
preserved. |
...
|
y
|
float, sequence of float, or None
|
Replace one ordinate by a scalar broadcast over vertices or a
column with one value per coordinate. Omitted ordinates are
preserved. |
...
|
z
|
float, sequence of float, or None
|
Replace one ordinate by a scalar broadcast over vertices or a
column with one value per coordinate. Omitted ordinates are
preserved. |
...
|
m
|
float, sequence of float, or None
|
Replace one ordinate by a scalar broadcast over vertices or a
column with one value per coordinate. Omitted ordinates are
preserved. |
...
|
Returns:
| Type | Description |
|---|---|
Geometry
|
|
Examples:
>>> import gometry as gm
>>> gm.LineString([(0, 0), (1, 1)]).with_coordinates([(5, 5), (6, 6)]).to_wkt()
'LINESTRING (5 5, 6 6)'
with_space
¶
with_space(space: Space, *, overwrite: bool = False) -> Self
Reinterpret stored coordinates in one complete Space.
Coordinates, axes and geometry kind are preserved. The new model changes their geometric meaning; this does not promise whole-geometry validity. Interpretation-dependent computational products are acquired afresh. Planar polygon rings first entering a geographic model select their left side. Existing geographic polygons retain their selected sides when switching between Chart and Spherical edges. A Planar target drops selected-side metadata only when each shell and hole selects its bounded planar region; clockwise shells selecting their right side remain bounded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
space
|
Space
|
Complete target interpretation, including CRS, model and epoch. |
required |
overwrite
|
bool
|
Allow replacing a present, different CRS or epoch. Attaching, clearing and restating metadata, or changing only the model, need no flag. |
False
|
Returns:
| Type | Description |
|---|---|
Geometry
|
A value in the requested Space, sharing its immutable coordinates. |
Raises:
| Type | Description |
|---|---|
CRSError
|
If a present CRS or epoch would change without |
GeometryError
|
If coordinates are outside the target geographic domain or a newly spherical edge has antipodal endpoints without a waypoint, or Full or a selected ring support cannot be represented by a bounded Planar shell or hole. |
See Also
to_space_vertices : Transform stored vertices.
Examples:
>>> import gometry as gm
>>> gm.Point(1, 2).with_space(gm.Space(crs=4326)).crs
CRS("EPSG:4326")