Source: https://gometry.monicz.dev/api/conventions/

# API conventions

gometry follows a consistent set of naming, typing, and protocol rules across
every geometry, CRS, grid, and index operation.

## Naming and call shape

- **Properties, methods, and free functions** — facts are properties
  (`geom.area`, `geom.bounds`), unary operations are methods (`geom.buffer(1)`,
  `geom.to_space(target)`), and binary relationships are free functions
  (`gm.intersects(a, b)`, `gm.distance(a, b)`). Measurement overrides use free
  functions ([`gm.area`](https://gometry.monicz.dev/api/measurement/#gometry.area "area"), [`gm.length`](https://gometry.monicz.dev/api/measurement/#gometry.length "length")) with `metric=` and `unit=`.
- **Immutable updates and conversions** — `with_<field>` returns a modified copy
  without moving coordinates ([`with_space`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.with_space "with_space")); `to_<format>` serializes or
  transforms ([`to_space`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.to_space "to_space"), `to_wkb`); `from_<format>`
  parses. [`force_2d`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.force_2d "force_2d") and
  [`force_3d`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.force_3d "force_3d") change coordinate dimensions.
- **Whole-collection `_all` functions** — array methods run row by row
  (`arr.polygonize()`), while `_all` free functions pool an entire sequence
  ([`union_all`](https://gometry.monicz.dev/api/overlay/#gometry.union_all "union_all"), [`polygonize_all`](https://gometry.monicz.dev/api/constructive/#gometry.polygonize_all "polygonize_all")).
- **Constructors and grids** — classes construct scalars ([`Point`](https://gometry.monicz.dev/api/geometry-types/#gometry.Point "Point"),
  [`LineString`](https://gometry.monicz.dev/api/geometry-types/#gometry.LineString "LineString")); plural functions build packed arrays
  ([`points`](https://gometry.monicz.dev/api/constructors/#gometry.points "points"), [`line_strings`](https://gometry.monicz.dev/api/constructors/#gometry.line_strings "line_strings")). Grid
  functions use `h3_`, `s2_`, `geohash_`, and `tile_` prefixes with domain
  depth names (`resolution`, `level`, `precision`, `zoom`).
- **Typed output options** — keywords such as
  [`CRS.to_projjson(as_dict=True)`](https://gometry.monicz.dev/api/crs/#gometry.CRS.to_projjson "to_projjson") select alternate
  representations under one name and narrow the static return type.

## Scalar, array, and ragged outputs

Operations accept one value or a sequence under one name (for example,
[`from_wkt`](https://gometry.monicz.dev/api/io/#gometry.from_wkt "from_wkt")). Binary operations broadcast a scalar against an
array or pair equal-length arrays row by row; unequal array lengths raise
[`GeometryError`](https://gometry.monicz.dev/api/errors/#gometry.GeometryError "GeometryError").

- Dense numeric results are read-only [NumPy](https://numpy.org/) `ndarray`s.
- Geometry batches are [`GeometryArray`](https://gometry.monicz.dev/api/geometry-array/#gometry.GeometryArray "GeometryArray").
- Variable-length per-row results are [`ListArray`](https://gometry.monicz.dev/api/coordinates/#gometry.ListArray "ListArray") (a missing
  row is `None`; a present row with no matches is an empty group).
- Text and diagnostics return Python `list`s when no dense shape fits.

Type annotations preserve geometry kind, nullability, and scalar vs. array
outputs (for example, `Point.buffer` returns `Polygon`; buffering a nullable
array preserves `None` rows). See [Arrays & performance](https://gometry.monicz.dev/guide/arrays/).

## Python protocols

Geometries and arrays implement standard Python protocols: `a & b` / `a | b` /
`a - b` / `a ^ b` overlays, `str(geom)` / `f"{geom:.2f}"` / `f"{geom:x}"`
formatting, `bool(geom)` (falsy when empty), structural `match`/`case` patterns,
hashing, and sequence indexing/slicing/iteration.

```python
import gometry as gm

geom = gm.from_wkt("POINT (1.20517 5)")
print(str(geom), "|", f"{geom:.2f}", "|", bool(gm.from_wkt("POINT EMPTY")))

match geom:
    case gm.Point(x, y):
        print("matched point:", x, y)

arr = gm.GeometryArray([gm.Point(0, 0), gm.Point(3, 4)])
print(gm.Point(3, 4) in arr, arr.index(gm.Point(3, 4)))
```

```text
POINT (1.20517 5) | POINT (1.21 5.00) | False
matched point: 1.20517 5.0
True 1
```

## Equality and comparison

Choose the comparison that matches your intent:

- [`equals`](https://gometry.monicz.dev/api/predicates/#gometry.equals "equals"): topologically identical point sets (ignores vertex
  order and Z/M).
- [`equals_exact`](https://gometry.monicz.dev/api/predicates/#gometry.equals_exact "equals_exact"): same coordinate sequence within a
  tolerance, in compatible frames.
- [`equals_identical`](https://gometry.monicz.dev/api/predicates/#gometry.equals_identical "equals_identical"): exact coordinates, Z/M, and complete
  `Space`. Scalar `==` and `hash()` use this value equality.

`GeometryArray == GeometryArray` compares whole arrays and returns one `bool`;
use `equals_identical(left, right)` for an elementwise boolean mask. For
[`CRS`](https://gometry.monicz.dev/api/crs/#gometry.CRS "CRS"), `==` compares stored definitions; use
[`CRS.same_as`](https://gometry.monicz.dev/api/crs/#gometry.CRS.same_as "same_as") for operational equivalence.

## Error hierarchy

Invalid geometry, parameter, CRS, and parse errors inherit from
[`GeometryError`](https://gometry.monicz.dev/api/errors/#gometry.GeometryError "GeometryError") (a `ValueError` subclass):
[`InvalidGeometryError`](https://gometry.monicz.dev/api/errors/#gometry.InvalidGeometryError "InvalidGeometryError"),
[`CRSError`](https://gometry.monicz.dev/api/errors/#gometry.CRSError "CRSError") (with
[`CRSMismatchError`](https://gometry.monicz.dev/api/errors/#gometry.CRSMismatchError "CRSMismatchError") and
[`TransformError`](https://gometry.monicz.dev/api/errors/#gometry.TransformError "TransformError")), and
[`ParseError`](https://gometry.monicz.dev/api/errors/#gometry.ParseError "ParseError").

Three domain exceptions inherit directly from standard built-ins instead of
`GeometryError`:

- [`GeometryTypeError`](https://gometry.monicz.dev/api/errors/#gometry.GeometryTypeError "GeometryTypeError") subclasses `TypeError` (wrong
  geometry kind for the operation).
- [`RepresentabilityError`](https://gometry.monicz.dev/api/errors/#gometry.RepresentabilityError "RepresentabilityError") subclasses
  `OverflowError` (exact geometric output cannot be represented in binary64).
- [`ResourceLimitError`](https://gometry.monicz.dev/api/errors/#gometry.ResourceLimitError "ResourceLimitError") subclasses `RuntimeError`
  (configured output or computation budget exhausted).

Ordinary Python protocol errors keep their built-in types (`TypeError`,
`IndexError`, `StopIteration`). See [Errors & exceptions](https://gometry.monicz.dev/guide/errors/).

## Z/M, overlay linework, and interchange

- **Z and M layouts** — XY, XYZ, XYM, and XYZM are supported; per-operation
  propagation is summarized in
  [Geometry & dimensions](https://gometry.monicz.dev/guide/geometry/#zm-under-operations).
- **Overlay linework** — overlays merge degree-two nodes and split only at true
  junctions (matching [`line_merge`](https://gometry.monicz.dev/api/geometry/#gometry.Geometry.line_merge "line_merge")), so clipping
  a line with a covering polygon leaves one continuous line.
- **Interchange boundaries** — homogeneous arrays export native
  [GeoArrow](https://geoarrow.org/) coordinate buffers, while mixed types fall
  back to WKB. See [Arrow & storage](https://gometry.monicz.dev/ecosystem/arrow/),
  [Text & binary formats](https://gometry.monicz.dev/ecosystem/text-formats/), and
  [Security & untrusted input](https://gometry.monicz.dev/about/security/).
