Source: https://gometry.monicz.dev/guide/curves/

# Curves & surfaces

Gometry represents the curve and surface types of PostGIS and ISO SQL/MM beside
the seven [simple-feature types](https://gometry.monicz.dev/guide/geometry/). 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`](https://gometry.monicz.dev/ecosystem/postgis/).

| Type | Made of | `linearize()` returns |
| --- | --- | --- |
| [`CircularString`](https://gometry.monicz.dev/api/geometry-types/#gometry.CircularString "CircularString") | Arcs through `(start, mid, end)` control points; adjacent arcs share an endpoint | `LineString` |
| [`CompoundCurve`](https://gometry.monicz.dev/api/geometry-types/#gometry.CompoundCurve "CompoundCurve") | Contiguous `LineString` and `CircularString` sections | `LineString` |
| [`CurvePolygon`](https://gometry.monicz.dev/api/geometry-types/#gometry.CurvePolygon "CurvePolygon") | A closed shell and holes, each a line, circular string or compound curve | `Polygon` |
| [`MultiCurve`](https://gometry.monicz.dev/api/geometry-types/#gometry.MultiCurve "MultiCurve") | Line, circular-string and compound-curve members | `MultiLineString` |
| [`MultiSurface`](https://gometry.monicz.dev/api/geometry-types/#gometry.MultiSurface "MultiSurface") | `Polygon` and `CurvePolygon` members | `MultiPolygon` |
| [`PolyhedralSurface`](https://gometry.monicz.dev/api/geometry-types/#gometry.PolyhedralSurface "PolyhedralSurface") | Polygon patches joined at shared edges, such as the faces of a solid | `MultiPolygon` |
| [`TIN`](https://gometry.monicz.dev/api/geometry-types/#gometry.TIN "TIN") | Triangle patches of a triangulated irregular network | `MultiPolygon` |
| [`Triangle`](https://gometry.monicz.dev/api/geometry-types/#gometry.Triangle "Triangle") | One triangle | `Polygon` |

## Build and measure

```python
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: π
```

```text
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`, `bounds` and
  `centroid` use 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,
  `area` raises `GeometryTypeError`; use `linearize()` to choose the chords
  before measuring the union. Intersecting bounds do not prove overlap.
- **Similarity transforms.** `rotate`, `translate`, reflection and uniform
  `scale` keep arcs circular. A non-uniform scale or a shear would turn them
  into ellipses and raises; straight-edged surfaces such as a `TIN` accept any
  affine transform.
- **Planar only.** Arcs are drawn in the coordinate plane, so curves and
  surfaces need a planar [`Space`](https://gometry.monicz.dev/api/crs/#gometry.Space "Space"). On a geographic CRS, where
  measurement defaults to geodesic, measure in coordinate units with
  `gm.length(value, metric='cartesian')`, `gm.area(...)` or
  `centroid(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()`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.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`](https://postgis.net/docs/ST_CurveToLine.html);
  `quadrant_segments=` sets that count.
- `max_deviation=` instead bounds the distance between the arc and its chords,
  in coordinate units.

```python
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())
```

```text
65
13
LINESTRING (0 0, 0.29289321881345254 0.7071067811865476, 1 1, 1.7071067811865475 0.7071067811865476, 2 0)
```

the stored arc

A half circle passes through its three control points.

- arc
- control points

linearize(quadrant\_segments=2)

Four chords run just inside the arc.

- 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`, and [`gm.from_arrow`](https://gometry.monicz.dev/ecosystem/arrow/)
  restores 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](https://gometry.monicz.dev/ecosystem/postgis/) reads and writes these types
  natively, and PostGIS `geography` stores none of them.
