Curves & surfaces¶
Gometry represents the curve and surface types of PostGIS and ISO SQL/MM beside
the seven simple-feature types. A circular arc from a cadastral
survey retains its control points; a TIN from a terrain model retains its
triangle patches. Both can round-trip without linearization through WKB,
EWKB, WKT, Arrow, pickle and PostGIS geometry.
| Type | Made of | linearize() returns |
|---|---|---|
CircularString |
Arcs through (start, mid, end) control points; adjacent arcs share an endpoint |
LineString |
CompoundCurve |
Contiguous LineString and CircularString sections |
LineString |
CurvePolygon |
A closed shell and holes, each a line, circular string or compound curve | Polygon |
MultiCurve |
Line, circular-string and compound-curve members | MultiLineString |
MultiSurface |
Polygon and CurvePolygon members |
MultiPolygon |
PolyhedralSurface |
Polygon patches joined at shared edges, such as the faces of a solid | MultiPolygon |
TIN |
Triangle patches of a triangulated irregular network | MultiPolygon |
Triangle |
One triangle | Polygon |
Build and measure¶
import gometry as gm
arc = gm.CircularString([(0, 0), (1, 1), (2, 0)])
print(arc.length) # half of a circle of radius 1: π
print(arc.centroid().to_wkt())
road = gm.CompoundCurve([arc, [(2, 0), (4, 0)]])
print(road.to_wkt())
disc = gm.CurvePolygon(gm.CircularString([(-1, 0), (1, 0), (-1, 0)]))
print(disc.area) # a full circle of radius 1: π
3.141592653589793
POINT (1 0.6366197723675814)
COMPOUNDCURVE (CIRCULARSTRING (0 0, 1 1, 2 0), (2 0, 4 0))
3.141592653589793
An arc whose first and last points coincide is the full circle whose diameter joins them to the middle point, as in PostGIS.
What works on curves and surfaces¶
- Storage and measurement. WKB, EWKB, WKT, Arrow, pickle and PostGIS keep
the control points with their Z and M.
length,area,boundsandcentroiduse the circular arc rather than a chord approximation.envelope()includes the arc’s XY extrema, not just its control points. Measurements and generated vertices use double precision. If adjacent segments differ by hundreds of orders of magnitude, the computed sweep can lose precision even when all coordinates are finite. - Collection area. Points and curves contribute no area. Straight-edged
patches count once where they overlap. A lone curved parcel, or a curved
parcel whose shell can be separated from the other surfaces, keeps its
analytic area. If the enclosing bounds cannot establish separation,
arearaisesGeometryTypeError; uselinearize()to choose the chords before measuring the union. Intersecting bounds do not prove overlap. - Similarity transforms.
rotate,translate, reflection and uniformscalekeep arcs circular. A non-uniform scale or a shear would turn them into ellipses and raises; straight-edged surfaces such as aTINaccept any affine transform. - Planar only. Arcs are drawn in the coordinate plane, so curves and
surfaces need a planar
Space. On a geographic CRS, where measurement defaults to geodesic, measure in coordinate units withgm.length(value, metric='cartesian'),gm.area(...)orcentroid(metric='cartesian'), or linearize first. - Linearize first for
predicates, distances, overlay, polygonization, grid covers, buffers,
simplification, hulls, validity and repair, CRS transformation with
to_space, and GeoJSON. Grid bounding-cell queries can use true bounds directly when no reprojection is needed. Gometry never approximates an arc without that call, so no result depends silently on a segment count.
Linearize¶
linearize() returns the simple-feature type shown
above, in the same Space. It draws each arc with equal-angle chords between its
endpoints, using at least two chords so a shallow curved ring does not collapse.
Z and M are interpolated along each arc. At a compound join, two stations with
the same XY but different Z or M are both kept. Straight-edged surfaces convert
exactly.
- The default is 32 chords per quarter circle, as in PostGIS
ST_CurveToLine;quadrant_segments=sets that count. max_deviation=instead bounds the distance between the arc and its chords, in coordinate units.
import gometry as gm
arc = gm.CircularString([(0, 0), (1, 1), (2, 0)])
print(len(arc.linearize().coords))
print(len(arc.linearize(max_deviation=0.01).coords))
print(arc.linearize(quadrant_segments=2).to_wkt())
65
13
LINESTRING (0 0, 0.29289321881345254 0.7071067811865476, 1 1, 1.7071067811865475 0.7071067811865476, 2 0)
- arc
- control points
- arc
- chords
A circular arc and its linearization
Interchange¶
- WKB, EWKB and WKT use the ISO and PostGIS spellings, with Z and M.
- Arrow. GeoArrow has no curve encoding, so an array holding curves or
surfaces exports as
geoarrow.wkb, andgm.from_arrowrestores the types. - Dataframes. Gometry’s pandas extension array keeps the native values. Polars
can carry them losslessly as binary EWKB. For GeoPandas or GeoJSON, call
linearize()first and choose the tolerance in the geometry’s coordinate units. - GeoParquet. Linearize for the geometry column. To archive exact curves instead, store the original WKB in an ordinary binary column and retain its Space separately.
- PostGIS. Gres reads and writes these types
natively, and PostGIS
geographystores none of them.