Constructive & validation¶
Split, snap, polygonize, and validate geometry.
Related: Validation & repair
polygonize_all
¶
Accepted call forms
polygonize_all(
values: Geometry
| GeometryArray[Geometry | None]
| Iterable[
Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
],
*,
diagnostics: Literal[False] = False,
) -> GeometryArray[Polygon]
polygonize_all(
values: Geometry
| GeometryArray[Geometry]
| Iterable[Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface],
*,
diagnostics: Literal[True],
) -> PolygonizeResult[Never]
polygonize_all(
values: Geometry
| GeometryArray[Geometry | None]
| Iterable[
Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
],
*,
diagnostics: Literal[True],
) -> PolygonizeResult[None]
polygonize_all(
values: Geometry
| GeometryArray[Geometry]
| Iterable[Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface],
*,
diagnostics: bool,
) -> GeometryArray[Polygon] | PolygonizeResult[Never]
polygonize_all(
values: Geometry
| GeometryArray[Geometry | None]
| Iterable[
Geometry | Buffer | Mapping[str, Any] | SupportsGeoInterface | None
],
*,
diagnostics: bool,
) -> GeometryArray[Polygon] | PolygonizeResult[None]
Build polygons from pooled linework, optionally returning full diagnostics.
All input geometries' edges are pooled into one linework graph, so a ring can
close across inputs. diagnostics=False returns the enclosed polygons;
diagnostics=True returns those same polygons together with cut edges,
dangles, and invalid rings grouped by source row. Missing source rows are
None groups; present rows with no diagnostic linework are empty groups.
For geographic input, polygon faces and diagnostic lines use the same classification, so an edge of a returned face is not also reported as an invalid ring.
GeometryArray.polygonize() instead preserves one result group per input
row, so use this function when different rows' edges should close together.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
Geometry, GeometryArray, or iterable of Geometry-like values
|
One geometry or linework values to node and polygonize together. Array
and iterable inputs may contain |
required |
diagnostics
|
bool
|
Return a |
required |
Returns:
| Type | Description |
|---|---|
GeometryArray or PolygonizeResult
|
With the default |
See Also
Geometry.polygonize : Polygonize one geometry's own linework. GeometryArray.polygonize : Polygonize each array row independently. union_all : Union of many geometries into one. intersection_all : Common region shared by many geometries.
Examples:
>>> import gometry as gm
>>> edges = [
... gm.LineString([(0, 0), (1, 0)]),
... gm.LineString([(1, 0), (1, 1)]),
... gm.LineString([(1, 1), (0, 0)]),
... ]
>>> gm.polygonize_all(edges).to_wkt()
['POLYGON ((0 0, 1 0, 1 1, 0 0))']
>>> result = gm.polygonize_all(edges, diagnostics=True)
>>> result.polygons.to_wkt()
['POLYGON ((0 0, 1 0, 1 1, 0 0))']
require
¶
Accepted call forms
require(
value: GeometryT,
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryT
require(
value: GeometryArray[GeometryRowT],
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryArray[GeometryRowT]
require(
value: ListArray[GeometryArray[GeometryRowT]],
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryArray[GeometryRowT]
require(
value: ListArray[GeometryArray[GeometryRowT] | None],
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryArray[GeometryRowT]
require(
value: str | Buffer | Mapping[str, Any] | SupportsGeoInterface,
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> Geometry
require(
value: Iterable[GeometryRowT],
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryArray[GeometryRowT]
require(
value: Iterable[
Geometry
| str
| Buffer
| Mapping[str, Any]
| SupportsGeoInterface
| None
],
*,
space: Space | None = None,
crs: CrsInput | None = None,
model: Literal['planar', 'chart', 'spherical'] | None = None,
epoch: SupportsFloat
| SupportsIndex
| FloatScalar
| ScalarFloatArray
| None = None,
axes: Literal['XY', 'XYZ', 'XYM', 'XYZM'] | None = None,
) -> GeometryArray[Geometry | None]
Parse and require a geometry contract at an input boundary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
geometry-like or iterable of geometry-like
|
One geometry, a |
required |
space
|
Space
|
Require the complete interpretation, including frame, model and epoch.
Cannot be combined with |
None
|
crs
|
CrsInput
|
Expected CRS for the result. Native values are checked without changing
their labels or interpretation; compatible CRS spellings are accepted.
Raw formats can use the expected CRS to supply absent source metadata
before validation. A conflicting CRS raises |
None
|
model
|
('planar', 'chart', 'spherical')
|
Require the declared interpretation, including for point-only values. |
'planar'
|
epoch
|
numeric scalar
|
Require the coordinate epoch in decimal years. |
None
|
axes
|
('XY', 'XYZ', 'XYM', 'XYZM')
|
If given, require the geometry's coordinate axes to match exactly, otherwise raise. |
'XY'
|
Returns:
| Type | Description |
|---|---|
Geometry or GeometryArray
|
The validated input. Iterables return a |
Raises:
| Type | Description |
|---|---|
CRSError
|
If |
ParseError
|
If foreign GeoJSON is malformed, or its legacy |
CRSMismatchError
|
If an already-decoded / native / non-GeoJSON geometry's CRS conflicts
with |
GeometryError
|
If the geometry model conflicts with the requested interpretation. |
TypeError
|
If |
InvalidGeometryError
|
If the geometry is invalid, or its axes differ from |
See Also
Geometry.validate : Structured validity report. Geometry.repair : Fix the geometry.
Examples:
>>> import gometry as gm
>>> gm.require(gm.Point(1, 2, space=gm.Space(crs=4326)), crs=4326).to_wkt()
'POINT (1 2)'
shared_paths
¶
Accepted call forms
shared_paths(left: Geometry, right: Geometry) -> GeometryCollection
shared_paths(
left: Geometry,
right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
) -> GeometryArray[GeometryCollection]
shared_paths(
left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
right: Geometry,
) -> GeometryArray[GeometryCollection]
shared_paths(
left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT
],
) -> GeometryArray[GeometryCollection]
shared_paths(
left: Geometry,
right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryT | None
],
) -> GeometryArray[GeometryCollection | None]
shared_paths(
left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryT | None
],
right: Geometry,
) -> GeometryArray[GeometryCollection | None]
shared_paths(
left: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryT | None
],
right: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT | None
],
) -> GeometryArray[GeometryCollection | None]
shared_paths(
left: Geometry
| (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
right: Geometry
| (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[Geometry | None],
) -> GeometryCollection | GeometryArray[GeometryCollection | None]
Shared paths between two lineal geometries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
left
|
Geometry, GeometryArray, or iterable of Geometry or None
|
Two lineal operands. Scalar and sequence inputs broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames. |
required |
right
|
Geometry, GeometryArray, or iterable of Geometry or None
|
Two lineal operands. Scalar and sequence inputs broadcast pairwise; sequences must have equal length and compatible CRS/epoch frames. |
required |
Returns:
| Type | Description |
|---|---|
Geometry or GeometryArray
|
The shared linework. |
Raises:
| Type | Description |
|---|---|
CRSMismatchError
|
If operands' CRS or coordinate-epoch metadata differ. |
GeometryTypeError
|
If either operand is not lineal. |
Examples:
>>> import gometry as gm
>>> gm.shared_paths(gm.LineString([(0, 0), (2, 0)]), gm.LineString([(1, 0), (3, 0)])).to_wkt()
'GEOMETRYCOLLECTION (MULTILINESTRING ((1 0, 2 0)), MULTILINESTRING EMPTY)'
snap
¶
Accepted call forms
snap(
geom: GeometryT,
reference: Geometry,
tolerance: float,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryT
snap(
geom: MultiPoint,
reference: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT
],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[MultiPoint]
snap(
geom: MultiPoint,
reference: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT | None
],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[MultiPoint | None]
snap(
geom: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryT],
reference: Geometry
| (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[GeometryOtherT],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[GeometryT]
snap(
geom: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryT | None
],
reference: Geometry
| (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT | None
],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[GeometryT | None]
snap(
geom: GeometryT,
reference: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT
],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[GeometryT]
snap(
geom: GeometryT,
reference: (GeometryArray[GeometryRowT] | Iterable[GeometryRowT])[
GeometryOtherT | None
],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[GeometryT | None]
snap(
geom: Geometry | GeometryArray[Geometry | None],
reference: Geometry | GeometryArray[Geometry | None],
tolerance: FloatInput,
*,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> Geometry | GeometryArray[Geometry | None]
Snap vertices of geom onto reference within tolerance.
Each source vertex snaps independently to its nearest reference vertex at
or below tolerance; if none is in range, it stays unchanged. An exact
model-position match takes precedence over physically coincident aliases.
Otherwise a computed-distance tie goes to the reference vertex with the smaller X,
then Y, using IEEE total order. Multiple source vertices may snap to the
same reference vertex.
On each line segment, every reference vertex whose projection lies in the
open segment, whose segment distance is at or below tolerance, and
whose distance from both endpoints is greater than tolerance is
inserted at its reference X/Y. Insertions follow segment order; equal
projections are ordered by reference X/Y.
Snapped source vertices retain their own Z/M. Insertions interpolate fields at the original source parameter: affine fields on Planar edges and source-ellipsoid arclength fields on Chart and Spherical edges. Selecting a measuring sphere does not change that source-field ellipsoid. Reference Z/M never contributes. Geographic aliases retain the source-side longitude or pole spelling needed for their incident branches.
Consecutive line redundant source positions are emitted once, keeping the first. Necessary Chart half-turn and pole-departure records survive. If only one coordinate remains, the snapped start and end are retained as two endpoints, which may share X/Y. Closed rings are reclosed.
Snapping may collapse polygon rings: collapsed holes are dropped and a collapsed shell produces an empty polygon. Snapping does not validate or repair topology, so a snapped polygon may be invalid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Geometry, GeometryArray, or iterable of Geometry or None
|
Geometry whose vertices are moved. Missing rows remain missing. |
required |
reference
|
Geometry, GeometryArray, or iterable of Geometry or None
|
Target geometry to snap onto. |
required |
tolerance
|
float or sequence of float
|
Maximum finite non-negative proximity in the selected metric's units. Geographic CRSs default to metres, including Planar values; projected CRSs use native linear units and CRS-free values use coordinate units. Zero uses exact model identity and incidence. Positive physical snapping can copy another longitude sheet into a Planar value; its edges remain literal Planar edges. This bounds vertex/projection proximity, not the deviation of the resulting curves. |
required |
metric
|
None, "cartesian", or Sphere
|
Measuring surface, independently of the input curve model. Cartesian distance is available only for Planar values. |
None
|
unit
|
None or 'meters'
|
Override the tolerance's distance units. |
None
|
Returns:
| Type | Description |
|---|---|
Geometry or GeometryArray
|
Snapped result(s), with missing rows preserved. |
Raises:
| Type | Description |
|---|---|
CRSMismatchError
|
If operands' CRS or coordinate-epoch metadata differ. |
GeometryError
|
If |
Examples:
>>> import gometry as gm
>>> gm.snap(gm.Point(0.01, 0), gm.Point(0, 0), 0.1).to_wkt()
'POINT (0 0)'
split
¶
Accepted call forms
split(
geom: LineString | MultiLineString,
splitter: Point | MultiPoint | GeometryArray[Point | MultiPoint | None],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[LineString]
split(
geom: GeometryArray[LineString | MultiLineString],
splitter: Point | MultiPoint | GeometryArray[Point | MultiPoint],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString]]
split(
geom: GeometryArray[LineString | MultiLineString | None],
splitter: Point | MultiPoint | GeometryArray[Point | MultiPoint],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString] | None]
split(
geom: GeometryArray[LineString | MultiLineString],
splitter: GeometryArray[Point | MultiPoint | None],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString] | None]
split(
geom: GeometryArray[LineString | MultiLineString | None],
splitter: GeometryArray[Point | MultiPoint | None],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString] | None]
split(
geom: Geometry,
splitter: Geometry | GeometryArray[Geometry | None],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> GeometryArray[LineString]
split(
geom: GeometryArray[Geometry],
splitter: Geometry | GeometryArray[Geometry],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString]]
split(
geom: GeometryArray[Geometry | None],
splitter: Geometry | GeometryArray[Geometry | None],
*,
tolerance: float = 0.0,
metric: Literal['cartesian'] | Sphere | None = None,
unit: Literal['meters'] | None = None,
) -> ListArray[GeometryArray[LineString] | None]
Split lineal geometry by point splitter(s).
Each piece retains source vertices, including consecutive equal-X/Y vertices whose active Z/M ordinates differ and necessary pole-departure records. Inserted fields use the original source parameter: affine fields for Planar edges and original-ellipsoid arclength for Chart/Spherical edges.
Positive tolerance positions each cutter at one nearest location across the source's complete linework, choosing the earliest source part and parameter in a tie. Every interior visit to that model position is cut. Distinct cut parameters remain distinct even when closer than the tolerance. Stationary runs retain their records in the following piece; endpoint runs do not create extra fragments. No source vertex moves to an off-line cutter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geom
|
Geometry or GeometryArray
|
Lineal geometry to split. |
required |
splitter
|
Geometry or GeometryArray
|
Point or multipoint cutter. |
required |
tolerance
|
(float, keyword - only)
|
Finite non-negative positioning allowance. Geographic CRSs default to
metres, including Planar values; projected CRSs use native linear units
and CRS-free values use raw coordinate units. The default |
0.0
|
metric
|
None, "cartesian", or Sphere
|
Measuring surface, independently of the source curve model. Cartesian distance is available only for Planar values. |
None
|
unit
|
None or 'meters'
|
Override the positioning allowance's distance units. |
None
|
Returns:
| Type | Description |
|---|---|
GeometryArray or ListArray[GeometryArray]
|
A scalar line returns all split parts in one |
Raises:
| Type | Description |
|---|---|
GeometryError
|
If |
CRSMismatchError
|
If operands' CRS or coordinate-epoch metadata differ. |
GeometryTypeError
|
If |
Examples:
>>> import gometry as gm
>>> gm.split(gm.LineString([(0, 0), (2, 0)]), gm.Point(1, 0)).to_wkt()
['LINESTRING (0 0, 1 0)', 'LINESTRING (1 0, 2 0)']
>>> pieces = gm.split(gm.GeometryArray([gm.LineString([(0, 0), (2, 0)])]), gm.Point(1, 0))
>>> pieces.offsets.tolist()
[0, 2]