# `GeoFrame.GeoSeries`
[🔗](https://github.com/CountlinkX-Solutions/geoframe/blob/v0.3.4/lib/geo_frame/geo_series.ex#L1)

A column of nullable geometries held in Rust as a GeoArrow array.

The geometry never lives in Elixir terms: a `%GeoSeries{}` wraps a reference to a
`geoarrow.geometry` column (mixed geometry types, CRS stored as GeoArrow extension
metadata). Constructors parse WKT/WKB into that column and outputs serialise it back, so
chained operations stay in native memory.

Geometries can be XY, XYZ, XYM or XYZM (`has_z/1`, `force_2d/1`, ...). Measures return
`Explorer.Series` and are planar unless you ask for `method: :geodesic` (or call
`area_geodesic/1`, `length_geodesic/1`, `distance/3` with `method:`), which measures on the
WGS 84 ellipsoid. A measure that overflows or is undefined is `:infinity`, `:neg_infinity` or
`:nan` in the series, as GeoPandas gives `inf`/`nan`. Nulls propagate: `nil` rows, and rows
that cannot be expressed as a `geo` geometry (such as `POINT EMPTY`), yield `nil`.

The CRS is a label such as `"EPSG:4326"` (`crs/1`, `set_crs/2`); `to_crs/2` reprojects with
`proj4rs` and accepts EPSG codes as well as PROJJSON and WKT definitions (see
`GeoFrame.Grids` for datum grids). Binary operations, joins and overlays raise when the CRS
of the two sides differ. The module follows GeoPandas 1.2 / Shapely 2.2; the known
differences are listed in `docs/parity.md` ("GeoPandas parity" in these docs).

## Example

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 4 0, 4 3, 0 3, 0 0))", nil])
    iex> GeoFrame.GeoSeries.area(s) |> Explorer.Series.to_list()
    [12.0, nil]

# `bounds`

```elixir
@type bounds() ::
  {number() | atom(), number() | atom(), number() | atom(), number() | atom()}
```

Four ordinates; a non-finite one is `:nan`, `:infinity` or `:neg_infinity`.

# `other`

```elixir
@type other() :: t() | String.t()
```

The right-hand side of a binary operation: a series, or a WKT string that broadcasts.

# `param`

```elixir
@type param() :: number() | [number() | nil] | Explorer.Series.t()
```

A number, or a list or `Explorer.Series` with one number (or `nil`) per row.

# `t`

```elixir
@type t() :: %GeoFrame.GeoSeries{precision: float(), ref: reference()}
```

# `vertex`

```elixir
@type vertex() :: {number(), number()} | {number(), number(), number()} | [number()]
```

A vertex: an `{x, y}` or `{x, y, z}` tuple, or an `[x, y]` or `[x, y, z]` list of numbers.

# `affine_transform`

```elixir
@spec affine_transform(t(), [number()]) :: t()
```

Applies an affine matrix to every coordinate (Shapely order).

The 6-element form `[a, b, d, e, xoff, yoff]` is `x' = a*x + b*y + xoff`,
`y' = d*x + e*y + yoff` and leaves Z alone. The 12-element form
`[a, b, c, d, e, f, g, h, i, xoff, yoff, zoff]` also transforms Z:
`x' = a*x + b*y + c*z + xoff`, `y' = d*x + e*y + f*z + yoff`, `z' = g*x + h*y + i*z + zoff`.
A geometry without Z only uses `a, b, d, e, xoff, yoff`. M is dropped (Shapely).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 2)"])
    iex> s |> GeoFrame.GeoSeries.affine_transform([0, 1, 1, 0, 0, 0]) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(2 1)"]

# `aggregate_groups`

```elixir
@spec aggregate_groups(t(), [non_neg_integer()], non_neg_integer(), atom()) :: t()
```

Grouped geometry aggregation: `group_ids` assigns each row to a group in `0..n_groups-1`
and the result has one row per group (same CRS), computed in one NIF call.

`aggregation` is one of `[:union_all, :intersection_all, :collect, :envelope, :convex_hull, :centroid, :first, :last]`. Each group gets what the whole-series
method gives for its rows alone: `union_all/1`, `intersection_all/1`, `collect/2` (without
`multi`), the `envelope/1` of the group's collection (its total bounds box), the
`convex_hull/1` of all its geometries, the `centroid/1` of its `union_all/1`, or its first /
last non-null geometry (`nil` for a group without any). Raises `ArgumentError` for an unknown
aggregation, a `group_ids` of the wrong length or an out-of-range id.

# `area`

```elixir
@spec area(t(), keyword()) :: Explorer.Series.t()
```

Unsigned area. Zero for points and lines.

Option `:method` - `:planar` (default, CRS units squared) or `:geodesic` (square metres,
see `area_geodesic/1`).

# `area_geodesic`

```elixir
@spec area_geodesic(t()) :: Explorer.Series.t()
```

Geodesic, unsigned area in square metres (GeoPolars `area_geodesic`). Holes are
subtracted, ring orientation does not matter, points and lines are zero.

Geodesic measures use the WGS 84 ellipsoid (Karney's algorithms). A geographic CRS is read
as lon/lat as it is, so one on another datum is still measured on WGS 84; a projected CRS
is reprojected to lon/lat first; a series without a CRS raises `ArgumentError`
(`set_crs` first).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))"], crs: "EPSG:4326")
    iex> [area] = s |> GeoFrame.GeoSeries.area_geodesic() |> Explorer.Series.to_list()
    iex> round(area / 1.0e9)
    12

# `boundary`

```elixir
@spec boundary(t()) :: t()
```

The topological boundary: a polygon's rings as a line (or multi-line with holes), a line's
endpoints as a multi-point (mod-2 rule; empty for closed lines), and an empty collection
for points. Geometry collections give `nil` (Shapely raises).

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `bounds`

```elixir
@spec bounds(t()) :: Explorer.DataFrame.t()
```

Per-row bounds as a dataframe with `minx`, `miny`, `maxx`, `maxy`.

Null and empty geometries give nulls.

# `buffer`

```elixir
@spec buffer(t(), param(), keyword()) :: t()
```

Buffers each geometry by `distance` (in CRS units; negative shrinks polygons and can empty
them). The result is a polygon or multipolygon.

`distance` is a number, or one distance per row as a list (numbers or `nil`) or an
`Explorer.Series` of the same length as the series; a `nil` distance gives a `nil` row.

Options (Shapely names):

  * `:cap_style` - `:round` (default), `:flat` or `:square`; the ends of lines.
  * `:join_style` - `:round` (default), `:mitre` or `:bevel`; corners of lines and of
    expanded polygons.
  * `:quad_segs` - segments per quarter circle for round caps and joins, default `16`.
    The backend clamps the resulting arc step, so values above about 50 or below 2 behave
    as those bounds.
  * `:mitre_limit` - for `:mitre` joins, the longest mitre as a multiple of `distance`,
    default `5.0`, at least `1.0`.
  * `:single_sided` - default `false`. Buffers only one side of a line: the left of its
    direction for a positive distance, the right for a negative one. Ends are flat (the
    cap style is ignored) and outside corners use the join style, as GEOS. A point gives
    its buffer for a positive distance and an empty polygon otherwise. A polygon is treated as GEOS
    does (single-sided only shapes lines): its ordinary buffer, unless the polygon boundary
    together with the buffer boundary encloses several faces, in which case the largest one
    (holes subtracted) is returned. For a square of side `s` and distance `d` that is the
    band between square and buffer while `s / d` is below about 4.68 (positive distance) or
    6.83 (negative distance, the band is the square minus its erosion), and the square itself
    or the ordinary negative buffer above; a square of side at most `2 * abs(d)` gives an
    empty polygon. A multipolygon is buffered per member and united. Closed lines and bands
    that overlap themselves can differ from GeoPandas (see `docs/parity.md`).

Invalid options raise `ArgumentError`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)"])
    iex> [area] = s |> GeoFrame.GeoSeries.buffer(1) |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    iex> Float.round(area, 1)
    3.1

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.buffer(1, single_sided: true) |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [10.0]

# `build_area`

```elixir
@spec build_area(t(), keyword()) :: t()
```

The area enclosed by the linework of the whole series, even-odd (GeoPandas `build_area`):
polygons as `polygonize/2` finds them, but a ring inside a ring becomes a hole, a ring inside
that an island again, and polygons sharing an edge merge. All geometries are used together;
the result has one row per polygon (none when the linework encloses nothing).

Option `:node` as for `polygonize/2`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0, 10 10, 0 10, 0 0)", "LINESTRING (2 2, 4 2, 4 4, 2 4, 2 2)"])
    iex> s |> GeoFrame.GeoSeries.build_area() |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [96.0]

# `centroid`

```elixir
@spec centroid(t()) :: t()
```

Centroids as a new series of points, keeping the CRS.

# `clip_by_rect`

```elixir
@spec clip_by_rect(t(), number(), number(), number(), number()) :: t()
```

Shapely's `clip_by_rect`: every geometry clipped to the rectangle, row by row.

This is the fast rectangle clip of GEOS. Only what reaches into the interior of the
rectangle survives: a point or line touching the edge, or a polygon sharing only an edge with
the rectangle, gives `GEOMETRYCOLLECTION EMPTY`. Empty results are **kept** (use
`GeoFrame.clip/3` to drop them) and the result of a polygon is not guaranteed valid. Null and
`GeometryCollection` rows give `nil`. Raises `ArgumentError` for an inverted rectangle.

# `collect`

```elixir
@spec collect(t(), keyword()) :: t()
```

Combines all non-null geometries into a **one-row** series (GeoPandas `tools.collect`).

Geometries of one family (points, lines or polygons) become the matching `Multi*`
geometry, with multi-part inputs flattened; mixed families become a `GeometryCollection`
of the inputs. A single geometry is returned as it is unless `multi: true` forces the
`Multi*` form. No geometries give `GEOMETRYCOLLECTION EMPTY`. The CRS is kept.

# `concat`

```elixir
@spec concat([t()]) :: t()
```

Appends the rows of several series in order, like `pandas.concat` on GeoSeries.

Every series must have the same CRS (both unset counts as equal); a mismatch or an empty
list raises `ArgumentError`.

# `concave_hull`

```elixir
@spec concave_hull(t(), keyword()) :: t()
```

The concave hull of each geometry's vertices (GEOS `ConcaveHull`, as GeoPandas
`concave_hull`).

The hull erodes the border of the Delaunay triangulation of the vertices. `ratio` (a number
from `0.0` to `1.0`, default `0.0`) is the share of the triangulation's edge-length range
above which border triangles are removed: `0.0` erodes as much as possible and `1.0` is the
convex hull. With `allow_holes: true` long interior triangles are removed too, which can
leave holes. One vertex gives a point and two (or collinear) vertices a line.

Hulls on exactly tied Delaunay choices (cocircular vertices, equal edge lengths) can differ
from GEOS; see `docs/parity.md`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["MULTIPOINT ((0 0), (4 0), (4 4), (0 4), (2 3))"])
    iex> s |> GeoFrame.GeoSeries.concave_hull(ratio: 1.0) |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [16.0]

# `constrained_delaunay_triangles`

```elixir
@spec constrained_delaunay_triangles(t()) :: t()
```

Triangles that fill each polygon (holes respected, no extra vertices), as a
`GeometryCollection`. Rows that are not polygons give an empty collection. The triangulation
is constrained Delaunay: where several are valid (cocircular vertices) the choice can differ
from GEOS.

# `contains`

```elixir
@spec contains(t(), other()) :: Explorer.Series.t()
```

Whether no point of `other` lies outside the geometry and their interiors share a point.

Boundary points are **not** contained: a polygon does not `contains` a point on its edge,
nor a line lying along its boundary (use `covers/2` for that). `contains(a, b)` equals
`within(b, a)`.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `contains_properly`

```elixir
@spec contains_properly(t(), other()) :: Explorer.Series.t()
```

Whether `other` lies in the interior of the geometry with no contact with its boundary
(DE-9IM `T**FF*FF*`). Stricter than `contains/2`: a polygon contains a line that starts
on its edge but does not contain it properly.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `convex_hull`

```elixir
@spec convex_hull(t()) :: t()
```

The smallest convex polygon containing each geometry. Degenerate inputs collapse: one
distinct point gives a point, collinear points a line. Empty geometries give `nil`.

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `count_coordinates`

```elixir
@spec count_coordinates(t()) :: Explorer.Series.t()
```

Number of coordinates in each geometry as an s64 series (a closed ring counts its closing
vertex). Empty geometries give `0`; null rows `nil`.

# `count_geometries`

```elixir
@spec count_geometries(t()) :: Explorer.Series.t()
```

Number of parts in each geometry as an s64 series: the members of a multi-part geometry or
collection, `1` for a single geometry, `0` for empty ones. Null rows are `nil` (Shapely
counts them as `0`).

# `count_interior_rings`

```elixir
@spec count_interior_rings(t()) :: Explorer.Series.t()
```

Number of holes in each polygon as an s64 series. Every other geometry type, including
multipolygons, gives `0` (as Shapely); null rows are `nil`.

# `covered_by`

```elixir
@spec covered_by(t(), other()) :: Explorer.Series.t()
```

Whether no point of the geometry lies outside `other`. The converse of `covers/2`; unlike
`within/2` it is true for boundary points.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `covers`

```elixir
@spec covers(t(), other()) :: Explorer.Series.t()
```

Whether no point of `other` lies outside the geometry. Unlike `contains/2` this is true for
points and lines on the boundary: a square covers a point on its edge.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `crosses`

```elixir
@spec crosses(t(), other()) :: Explorer.Series.t()
```

Whether the interiors intersect and the intersection has a lower dimension than the larger
geometry, such as two lines crossing at a point or a line passing through a polygon.
Polygons never cross polygons.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `crs`

```elixir
@spec crs(t()) :: String.t() | nil
```

The CRS as a string, or `nil` when unknown.

# `cx`

```elixir
@spec cx(t(), number() | nil, number() | nil, number() | nil, number() | nil) :: t()
```

Rows whose geometry intersects the box `xmin..xmax` by `ymin..ymax`, like GeoPandas
`s.cx[xmin:xmax, ymin:ymax]`.

A `nil` bound is unbounded: it takes the matching side of `total_bounds/1`. The test is the
exact `intersects/2` against the box polygon (touching the edge counts). Returns a
`GeoSeries` of the selected rows in their original order; null rows are dropped.

## Example

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 1)", "POINT (9 9)"])
    iex> GeoFrame.GeoSeries.cx(s, 0, 0, 2, 2) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(1 1)"]

# `cx_positions`

```elixir
@spec cx_positions(
  t(),
  number() | nil,
  number() | nil,
  number() | nil,
  number() | nil
) :: [
  non_neg_integer()
]
```

The zero-based row positions `cx/5` selects, for aligning other data with the selection.

# `delaunay_triangles`

```elixir
@spec delaunay_triangles(t(), keyword()) :: t()
```

The Delaunay triangulation of the vertices of the whole series, as GeoPandas does: every
geometry contributes its vertices to one point cloud, and the result has one row per triangle
(a new series, not aligned with the input). Fewer than three or collinear vertices give an
empty series.

Options: `:tolerance` (default `0.0`) merges vertices closer than that; `:only_edges`
(default `false`) returns one `LineString` per unique edge instead.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)", "POINT (4 0)", "POINT (0 4)", "POINT (4 4)"])
    iex> s |> GeoFrame.GeoSeries.delaunay_triangles() |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [8.0, 8.0]

# `difference`

```elixir
@spec difference(t(), other()) :: t()
```

The part of the geometry that is not in `other`. Element-wise; returns a GeoSeries with the CRS of the left side.

Pairing, null and CRS rules are those of `intersects/2` (`other` may be a series of the
same length, or a single geometry / WKT string that broadcasts).

Every combination of points, lines and polygons is supported, with GEOS results: lines are
noded (crossings, overlaps), the lower-dimensional parts of a result are kept (two squares
sharing an edge intersect in that `LINESTRING`, sharing a corner in a `POINT`), and a result
of several dimensions is a `GEOMETRYCOLLECTION` with one member per part. A
`GeometryCollection` input is supported by `intersection` only (member by member); the other
operations give `nil` for it. Empty results are empty geometries
(`POLYGON EMPTY`, `LINESTRING EMPTY`, `MULTIPOINT EMPTY`), not `nil`.

# `disjoint`

```elixir
@spec disjoint(t(), other()) :: Explorer.Series.t()
```

Whether the geometries share no point at all. This is the negation of `intersects/2`.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `distance`

```elixir
@spec distance(t(), other(), keyword()) :: Explorer.Series.t()
```

Distance between each pair, as an f64 series. Zero when they intersect.

Option `:method`:

  * `:planar` (default) - Euclidean, in CRS units (degrees for `EPSG:4326`).
  * `:geodesic` - metres on the WGS 84 ellipsoid. `Point` to `Point` is exact (Karney).
    For any other pair the nearest points are found *planar, in lon/lat degrees* and the
    geodesic distance between them is returned: an approximation that can drift at high
    latitudes or across the antimeridian.
  * `:haversine` - as `:geodesic` on a sphere of radius 6 371 008.8 m.

Geodesic measures use the WGS 84 ellipsoid (Karney's algorithms). A geographic CRS is read
as lon/lat as it is, so one on another datum is still measured on WGS 84; a projected CRS
is reprojected to lon/lat first; a series without a CRS raises `ArgumentError`
(`set_crs` first).

Pairing, null and CRS rules are those of `intersects/2`.

# `dwithin`

```elixir
@spec dwithin(t(), other(), number(), keyword()) :: Explorer.Series.t()
```

Whether each pair is within `limit` of each other: `distance(a, b) <= limit` (inclusive).

Option `:method` is that of `distance/3`; with `:geodesic` or `:haversine`, `limit` is in
metres. Pairing, null and CRS rules are those of `intersects/2`.

# `envelope`

```elixir
@spec envelope(t()) :: t()
```

The axis-aligned bounding rectangle as a polygon. A point gives a point and a horizontal
or vertical line gives a line (the degenerate rectangles). Empty geometries give `nil`.

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `estimate_utm_crs`

```elixir
@spec estimate_utm_crs(t(), keyword()) :: String.t()
```

The UTM CRS to use for this series, as GeoPandas `estimate_utm_crs`: the first EPSG UTM CRS of
the datum, by code, whose area of use contains the centre of the total bounds (the answer of
`pyproj.database.query_utm_crs_info/2`). Returns an `"EPSG:<code>"` string.

A geographic series is centred on its raw bounds. For any other CRS the bounds are first
converted to lon/lat (edges densified, a pole inside the box or a box crossing the
antimeridian handled as PROJ's `transform_bounds` does) and the centre of that box is used.

The zone exceptions of Norway (32V) and Svalbard (32X, 34X, 36X) are **not** applied: pyproj
and GeoPandas do not apply them either (EPSG defines plain 6-degree zones), so `5 E, 60 N` is
`"EPSG:32631"`. A point on a zone edge belongs to both zones and the lower code wins.

Options:

  * `:datum_name` - the datum in the CRS name, `"WGS 84"` by default; `"NAD83"`, `"NAD27"`,
    `"ETRS89"`, `"SIRGAS 2000"`, ... Spaces are ignored, case is not. A datum with no UTM CRS
    over the centre (WGS 84 covers 80 S to 84 N; `"ETRS89"` only 6 W to 36 E, northern
    Europe) raises, as GeoPandas does.

Raises `ArgumentError` for a series without a CRS or bounds, or without a UTM CRS for the
datum at the centre.

## Examples

    iex> GeoFrame.GeoSeries.from_wkt!(["POINT (-80.2 25.7)"], crs: "EPSG:4326")
    ...> |> GeoFrame.GeoSeries.estimate_utm_crs()
    "EPSG:32617"

    iex> GeoFrame.GeoSeries.from_wkt!(["POINT (-80.2 25.7)"], crs: "EPSG:4326")
    ...> |> GeoFrame.GeoSeries.estimate_utm_crs(datum_name: "NAD83")
    "EPSG:26917"

# `explode`

```elixir
@spec explode(t(), keyword()) ::
  {t(), [non_neg_integer()]} | {t(), [non_neg_integer()], [non_neg_integer()]}
```

Splits multi-part geometries and collections into their parts, like `GeoSeries.explode`.

Returns `{parts, positions}`: a `GeoSeries` with one row per part and the parallel list of
zero-based **source row positions** (what the pandas index holds in GeoPandas). Multi-part
geometries give their members and collections their direct members (one level, as
`shapely.get_parts`; nested collections do not exist because storage flattens them). An
atomic geometry, even an empty polygon or line, is its own single part. Null rows and empty
multi-geometries or collections have no parts and disappear. The CRS is kept.

Option `index_parts: true` returns `{parts, positions, part_numbers}` where `part_numbers`
holds the zero-based number of each part within its source row (the second level of the
pandas MultiIndex).

## Example

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)", "MULTIPOINT ((1 1), (2 2))"])
    iex> {parts, positions} = GeoFrame.GeoSeries.explode(s)
    iex> {GeoFrame.GeoSeries.to_wkt(parts), positions}
    {["POINT(0 0)", "POINT(1 1)", "POINT(2 2)"], [0, 1, 1]}

# `exterior`

```elixir
@spec exterior(t()) :: t()
```

The exterior ring of each polygon as a line. Every non-polygon row gives `nil`, where
GeoPandas raises. Interior rings are not returned.

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `extract_unique_points`

```elixir
@spec extract_unique_points(t()) :: t()
```

The distinct vertices of each geometry as a `MULTIPOINT`, in first-seen order.

# `fillna`

```elixir
@spec fillna(t(), String.t() | t() | nil) :: t()
```

Replaces null rows with `value`: a WKT string, or a one-row `GeoSeries`.

With no value, nulls become `GEOMETRYCOLLECTION EMPTY`, as in GeoPandas. Empty geometries
are kept. A WKT value takes the series' CRS; a series value with a different CRS (both
set) raises `ArgumentError`, as does one that does not have exactly one row.

# `force_2d`

```elixir
@spec force_2d(t()) :: t()
```

Drops the Z and M coordinates of every geometry. The CRS is kept.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT ZM (1 2 3 4)"])
    iex> s |> GeoFrame.GeoSeries.force_2d() |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(1 2)"]

# `force_3d`

```elixir
@spec force_3d(t(), param()) :: t()
```

Gives every geometry without Z a Z coordinate (Shapely `force_3d`). `z` is a number
(default `0.0`), or a list or `Explorer.Series` with one number per row (`nil` is NaN).

Like Shapely 2.2, a geometry that already has Z keeps it and loses its M, and a geometry
with M but no Z is left unchanged.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 2)", "POINT Z (1 2 3)"])
    iex> s |> GeoFrame.GeoSeries.force_3d(9) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT Z(1 2 9)", "POINT Z(1 2 3)"]

# `frechet_distance`

```elixir
@spec frechet_distance(t(), other(), keyword()) :: Explorer.Series.t()
```

Discrete Fréchet distance between each pair of geometries (the shortest leash for two
walkers that never turn back), as GEOS computes it: over the flat sequence of every vertex of
each geometry, all parts and rings in order, whatever its type. Null and empty rows give
`nil`.

Options: `:densify` as for `hausdorff_distance/3`, except that a geometry made of points only
is not densified (GEOS). Pairing and CRS rules are those of
`intersects/2`.

# `from_arrow`

```elixir
@spec from_arrow(binary(), keyword()) :: {:ok, t()} | {:error, String.t()}
```

Decodes an Arrow IPC stream with a geometry column into a series.

Accepts WKB (`geoarrow.wkb` or a plain binary column), WKT (`geoarrow.wkt` or a plain
string column) and every native GeoArrow extension type (point, linestring, polygon and
the multi types, interleaved or separated coordinates). The geometry column is found from
the `geo` schema metadata, else the first GeoArrow extension column, else a column named
`"geometry"`.

Options: `:geometry` - the geometry column name when it cannot be detected; `:crs` - a
CRS used only when the data carries none.

Returns `{:error, message}` for invalid IPC data or a stream without a geometry column.

# `from_arrow!`

```elixir
@spec from_arrow!(binary(), keyword()) :: t()
```

Like `from_arrow/2` but raises `ArgumentError` on failure.

# `from_file`

```elixir
@spec from_file(Path.t(), keyword()) :: {:ok, t()} | {:error, String.t()}
```

Reads the geometry column of a vector file as a series (GeoPandas `GeoSeries.from_file`).

Reads the file with `GeoFrame.read_file/2`, so the format comes from the extension or
`driver:` and the other options are those of the format's reader; the attributes are
dropped. Returns `{:ok, series}` or `{:error, message}`.

# `from_file!`

```elixir
@spec from_file!(Path.t(), keyword()) :: t()
```

Like `from_file/2` but raises `ArgumentError` on failure.

# `from_wkb`

```elixir
@spec from_wkb([binary() | nil], keyword()) :: {:ok, t()} | {:error, String.t()}
```

Builds a series from WKB binaries (`nil` entries become null geometries).

Accepts the same options as `from_wkt/2`.

# `from_wkb!`

```elixir
@spec from_wkb!([binary() | nil], keyword()) :: t()
```

Like `from_wkb/2` but raises `ArgumentError` on invalid input.

# `from_wkt`

```elixir
@spec from_wkt([String.t() | nil], keyword()) :: {:ok, t()} | {:error, String.t()}
```

Builds a series from WKT strings (`nil` entries become null geometries).

Options: `:crs` - a CRS string such as `"EPSG:4326"`, or `nil` (default).

Returns `{:error, message}` naming the first invalid row.

# `from_wkt!`

```elixir
@spec from_wkt!([String.t() | nil], keyword()) :: t()
```

Like `from_wkt/2` but raises `ArgumentError` on invalid input.

# `from_xy`

```elixir
@spec from_xy(
  [number() | nil] | Explorer.Series.t(),
  [number() | nil] | Explorer.Series.t(),
  keyword()
) ::
  t()
```

Builds a series of points from coordinate columns, like GeoPandas `points_from_xy`.

`x` and `y` are lists or `Explorer.Series` of equal length. A row is a null geometry when
either coordinate is `nil` or not a finite number (including `NaN`).

Options:

  * `:crs` - a CRS string such as `"EPSG:4326"`, or `nil` (default).
  * `:z` - a list or `Explorer.Series` of the same length: the result is `POINT Z`
    (`nil` or NaN is a NaN Z ordinate, as `points_from_xy(x, y, z)` in GeoPandas). A row
    whose `x` or `y` is missing stays a null geometry.

Raises `ArgumentError` when the columns differ in length or an option is unknown.

    iex> s = GeoFrame.GeoSeries.from_xy([1, 2], [3, nil])
    iex> GeoFrame.GeoSeries.to_wkt(s)
    ["POINT(1 3)", nil]
    iex> s = GeoFrame.GeoSeries.from_xy([1, 2], [3, 4], z: [5, 6])
    iex> GeoFrame.GeoSeries.to_wkt(s)
    ["POINT Z(1 3 5)", "POINT Z(2 4 6)"]

# `geom_equals`

```elixir
@spec geom_equals(t(), other()) :: Explorer.Series.t()
```

Topological equality: both geometries describe the same set of points, regardless of vertex
order, start vertex, ring orientation or redundant vertices. Named `geom_equals` after
GeoPandas' `geom_equals`; see `geom_equals_exact/3` and `geom_equals_identical/2` for the
structural comparisons.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `geom_equals_exact`

```elixir
@spec geom_equals_exact(t(), other(), number()) :: Explorer.Series.t()
```

Structural equality: same geometry type and structure, with every vertex in the same order
and within `tolerance` (planar distance, inclusive) of its counterpart. Shapely
`equals_exact`.

Unlike `geom_equals/2` a reversed ring or a different start vertex is a difference, and NaN
never equals NaN. `tolerance` must be a finite, non-negative number. Pairing, null and CRS
rules are those of `intersects/2`.

## Example

    iex> a = GeoFrame.GeoSeries.from_wkt!(["POINT (1 1)"])
    iex> b = GeoFrame.GeoSeries.from_wkt!(["POINT (1.0004 1)"])
    iex> GeoFrame.GeoSeries.geom_equals_exact(a, b, 0.001) |> Explorer.Series.to_list()
    [true]

# `geom_equals_identical`

```elixir
@spec geom_equals_identical(t(), other()) :: Explorer.Series.t()
```

Exact equality of structure and coordinates, without tolerance; NaN coordinates are equal
to each other. Shapely `equals_identical`. Pairing, null and CRS rules are those of
`intersects/2`.

# `geom_type`

```elixir
@spec geom_type(t()) :: Explorer.Series.t()
```

The geometry type name per row, as GeoPandas/Shapely spell it: `"Point"`, `"LineString"`,
`"Polygon"`, `"MultiPoint"`, `"MultiLineString"`, `"MultiPolygon"` or
`"GeometryCollection"`; `nil` for null rows.

Note that a one-member `GEOMETRYCOLLECTION` is stored as that member when parsed, so it
reports the member's type.

# `get_coordinates`

```elixir
@spec get_coordinates(t(), keyword()) :: Explorer.DataFrame.t()
```

Every vertex of every geometry as a dataframe with `x` and `y` (f64), in row order.

Null and empty geometries contribute no rows. A polygon ring includes its closing vertex,
so the row count equals the sum of `count_coordinates/1`. Option `:include_index` (default
`false`) adds a leading `index` column (s64) with the zero-based row position, GeoPandas'
index. GeoPandas' `ignore_index` and `index_parts` are not supported (there is no
multi-index).

Options `:include_z` and `:include_m` (default `false`) append `z` and `m` columns (f64),
after `x` and `y`, with NaN for a vertex whose geometry lacks that ordinate (Shapely
`get_coordinates`). An XYM geometry therefore has a NaN `z`.

# `get_geometry`

```elixir
@spec get_geometry(t(), integer() | [integer() | nil] | Explorer.Series.t()) :: t()
```

The `n`th part of each geometry (zero-based); a negative `n` counts from the end.

A single geometry is its own part `0`. Out-of-range indices and null rows give `nil`.

`n` is an integer (the same index for every row) or one index per row: a list of integers
(or `nil`) or an Explorer integer series, as long as the series (otherwise `ArgumentError`),
like `shapely.get_geometry(array, indices)`. A `nil` index gives a `nil` row.

# `get_m`

```elixir
@spec get_m(t()) :: Explorer.Series.t()
```

Alias of `m/1`.

# `get_precision`

```elixir
@spec get_precision(t()) :: Explorer.Series.t()
```

The grid size of each geometry (`shapely.get_precision`): the value given to
`set_precision/3`, or `0.0` for floating precision; `nil` for null rows.

GeoArrow carries no precision, so it lives on the series: only the result of
`set_precision/3` has a non-zero precision.

# `get_z`

```elixir
@spec get_z(t()) :: Explorer.Series.t()
```

Alias of `z/1`.

# `has_m`

```elixir
@spec has_m(t()) :: Explorer.Series.t()
```

Whether each geometry has an M coordinate; same rules as `has_z/1`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT M (1 2 4)", "POINT Z (1 2 3)"])
    iex> s |> GeoFrame.GeoSeries.has_m() |> Explorer.Series.to_list()
    [true, false]

# `has_z`

```elixir
@spec has_z(t()) :: Explorer.Series.t()
```

Whether each geometry has a Z coordinate; `false` for null rows (like Shapely `has_z`).
An empty geometry keeps the dimension it was declared with (`POINT Z EMPTY` has Z) and a
collection has Z when any member does.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT Z (1 2 3)", "POINT (1 2)", nil])
    iex> s |> GeoFrame.GeoSeries.has_z() |> Explorer.Series.to_list()
    [true, false, false]

# `hausdorff_distance`

```elixir
@spec hausdorff_distance(t(), other(), keyword()) :: Explorer.Series.t()
```

Discrete Hausdorff distance between each pair: the largest distance from a vertex of one
geometry to the *whole* other one, taken both ways (GEOS, so a vertex that lies on a segment
of the other geometry counts as distance zero).

Options: `:densify` - a fraction in `(0, 1]`; each segment is first split into
`round(1 / densify)` parts so the vertices sample the geometry more finely. Default `nil`
(vertices only). Pairing, null and CRS rules are those of `intersects/2`.

# `interiors`

```elixir
@spec interiors(t()) :: t()
```

The holes of each polygon.

GeoPandas returns a Python list of rings per row; a series cannot hold lists, so each row
is a `MULTILINESTRING` of the holes (`MULTILINESTRING EMPTY` for a polygon without holes).
Every non-polygon row, multipolygons included, and null rows give `nil`.

# `interpolate`

```elixir
@spec interpolate(t(), param(), keyword()) :: t()
```

The point at `distance` along each line.

`distance` is a number, or a list or `Explorer.Series` with one entry per row (a `nil`
entry nulls that row). A negative distance counts from the end of the line; distances past
either end clamp to that end. A `MultiLineString` is measured as its parts laid end to end.
Rows that are not lines (points, polygons) are `nil`, where Shapely raises.

Options: `:normalized` - when `true`, `distance` is a fraction of the length (default
`false`).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.interpolate(0.25, normalized: true) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(2.5 0)"]

# `intersection`

```elixir
@spec intersection(t(), other()) :: t()
```

The part shared by both geometries. Element-wise; returns a GeoSeries with the CRS of the left side.

Pairing, null and CRS rules are those of `intersects/2` (`other` may be a series of the
same length, or a single geometry / WKT string that broadcasts).

Every combination of points, lines and polygons is supported, with GEOS results: lines are
noded (crossings, overlaps), the lower-dimensional parts of a result are kept (two squares
sharing an edge intersect in that `LINESTRING`, sharing a corner in a `POINT`), and a result
of several dimensions is a `GEOMETRYCOLLECTION` with one member per part. A
`GeometryCollection` input is supported by `intersection` only (member by member); the other
operations give `nil` for it. Empty results are empty geometries
(`POLYGON EMPTY`, `LINESTRING EMPTY`, `MULTIPOINT EMPTY`), not `nil`.

# `intersection_all`

```elixir
@spec intersection_all(t()) :: t()
```

The intersection of all non-null geometries as a **one-row** GeoSeries (GeoPandas
`intersection_all`, which returns a scalar).

Rows are folded left to right with `intersection/2`, so the lower-dimensional parts of
touching geometries survive (two squares sharing an edge give that edge). A step whose result
is a `GEOMETRYCOLLECTION` (mixed dimensions) cannot be intersected further and gives a `nil`
row. No non-null input gives `GEOMETRYCOLLECTION EMPTY`.

# `intersects`

```elixir
@spec intersects(t(), other()) :: Explorer.Series.t()
```

Whether the geometries share at least one point (boundary contact counts).
This is the negation of `disjoint/2`.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `invalid_coverage_edges`

```elixir
@spec invalid_coverage_edges(t(), keyword()) :: t()
```

The edges that make the coverage invalid, per row (GeoPandas `invalid_coverage_edges`).

Each row gets the stretches of its polygon's rings that overlap a neighbour, fail to match a
neighbour's edge vertex for vertex, or (with `:gap_width`) border a narrow gap: a
`LINESTRING`, a `MULTILINESTRING` when there are several, or `LINESTRING EMPTY` when the row
is valid (also for rows that are not polygons). Null rows stay null. Options and limits as
for `is_valid_coverage/2`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 1 1, 1 0, 0 0))", "POLYGON ((0 0, 0.5 0.5, 1 1, 0 1, 0 0))"])
    iex> s |> GeoFrame.GeoSeries.invalid_coverage_edges() |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(0 0,1 1)", "LINESTRING(0 0,0.5 0.5,1 1)"]

# `is_ccw`

```elixir
@spec is_ccw(t()) :: Explorer.Series.t()
```

Whether each geometry is a closed line wound counter-clockwise (Shapely `is_ccw`). Open
lines and every non-line type are `false`; only null rows are `nil`.

# `is_closed`

```elixir
@spec is_closed(t()) :: Explorer.Series.t()
```

Whether each geometry is closed, following Shapely: a non-empty line string whose ends
meet, or a multi-line string all of whose members do. Every other geometry type and empty
lines give `false`; null rows give `nil`.

# `is_empty`

```elixir
@spec is_empty(t()) :: Explorer.Series.t()
```

Whether each geometry is empty (such as `POINT EMPTY`); `nil` for null rows.

# `is_geographic`

```elixir
@spec is_geographic(t()) :: boolean() | nil
```

Whether the series' CRS is geographic (lon/lat): `true` for `EPSG:4326`, `OGC:CRS84` and any
other longlat EPSG code, `false` for projected CRSs, `nil` without a CRS or when the CRS
cannot be resolved.

# `is_ring`

```elixir
@spec is_ring(t()) :: Explorer.Series.t()
```

Whether each geometry is a ring: a closed line string with at least four vertices and no
self-intersection except at the closing vertex. Every other geometry type gives `false`;
null rows give `nil`. The check compares all segment pairs, so it is quadratic in the
number of vertices.

# `is_simple`

```elixir
@spec is_simple(t()) :: Explorer.Series.t()
```

Whether each geometry is simple, with Shapely's `is_simple` semantics.

Points are simple; a multipoint is not if a point repeats. A line is simple unless it
crosses or touches itself anywhere but at the shared vertex of consecutive segments (and,
for a closed line, at its start); a multi-line also needs its members to meet only at end
points of both (the end points of a closed line count as interior). A polygon or
multipolygon is simple when each of its rings is, valid or not. Every collection is `false`,
as in Shapely. Null rows give `nil`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 4 4, 4 0, 0 4)", "LINESTRING (0 0, 4 4)"])
    iex> s |> GeoFrame.GeoSeries.is_simple() |> Explorer.Series.to_list()
    [false, true]

# `is_valid`

```elixir
@spec is_valid(t()) :: Explorer.Series.t()
```

Boolean series: whether each geometry is valid per the OGC rules.

# `is_valid_coverage`

```elixir
@spec is_valid_coverage(t(), keyword()) :: boolean()
```

Whether the polygons of the whole series form a valid coverage (GeoPandas
`is_valid_coverage`, GEOS `CoverageValidator`; a single boolean, not one per row).

A polygonal coverage is valid when its polygons do not overlap and the edges they share match
vertex for vertex. Holes (regions without a polygon) are allowed. Geometries that are not
polygons or multipolygons, and null rows, are ignored; an empty series is valid.

Option `:gap_width` (default `0.0`) also rejects gaps narrower than it: a segment that runs
alongside a neighbour's for more than that length, closer than that width, is invalid. A
negative width counts as `0.0`. Raises `ArgumentError` when the width is not a finite number,
or when the check needs over 50,000,000 segment pairs.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 1 1, 1 0, 0 0))", "POLYGON ((0 0, 1 1, 0 1, 0 0))"])
    iex> GeoFrame.GeoSeries.is_valid_coverage(s)
    true
    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 1 1, 1 0, 0 0))", "POLYGON ((0 0, 0.5 0.5, 1 1, 0 1, 0 0))"])
    iex> GeoFrame.GeoSeries.is_valid_coverage(s)
    false

# `is_valid_reason`

```elixir
@spec is_valid_reason(t()) :: Explorer.Series.t()
```

A string series saying why each geometry is invalid, or `"Valid Geometry"` (Shapely's text)
for valid ones; null rows give `nil`.

Only the first problem is reported, in GEOS' words and check order, as `"<reason>[<x> <y>]"`
(for example `"Self-intersection[2 2]"`, `"Hole lies outside shell[20 20]"`). When a geometry
has several errors of one class, the coordinate may be another one than GEOS reports; a hole
that disconnects the interior is not detected (see `docs/parity.md`).

# `isna`

```elixir
@spec isna(t()) :: Explorer.Series.t()
```

Boolean series: whether each row is a missing (null) geometry. Empty geometries are *not*
missing (GeoPandas >= 0.6).

# `length`

```elixir
@spec length(t(), keyword()) :: Explorer.Series.t()
```

Length: line length, polygon perimeter, zero for points.

Option `:method` - `:planar` (default, CRS units) or `:geodesic` (metres, see
`length_geodesic/1`).

# `length_geodesic`

```elixir
@spec length_geodesic(t()) :: Explorer.Series.t()
```

Geodesic length in metres: line length, polygon perimeter (holes included), zero for
points.

Geodesic measures use the WGS 84 ellipsoid (Karney's algorithms). A geographic CRS is read
as lon/lat as it is, so one on another datum is still measured on WGS 84; a projected CRS
is reprojected to lon/lat first; a series without a CRS raises `ArgumentError`
(`set_crs` first).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 0 1)"], crs: "EPSG:4326")
    iex> [m] = s |> GeoFrame.GeoSeries.length_geodesic() |> Explorer.Series.to_list()
    iex> Float.round(m, 1)
    110574.4

# `line_merge`

```elixir
@spec line_merge(t(), keyword()) :: t()
```

Joins line parts that meet end to end. A point where exactly two parts end is merged
through; a junction of three or more is not. Returns a `LineString` when everything forms
one chain, otherwise a `MultiLineString`. A `LineString` comes back unchanged and a row with
no lines (a point or polygon) becomes `GEOMETRYCOLLECTION EMPTY`, as in Shapely.

Options: `:directed` - when `true`, parts only join head to tail, never flipped (default
`false`, where parts may be reversed to fit).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["MULTILINESTRING ((0 0, 1 1), (1 1, 2 2))"])
    iex> s |> GeoFrame.GeoSeries.line_merge() |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(0 0,1 1,2 2)"]

# `line_strings_from_vertices`

```elixir
@spec line_strings_from_vertices([[vertex()] | nil], keyword()) :: t()
```

Builds line strings from vertex lists, one list per row (GeoPolars `line_string`).

A row is a list of vertices, `[]` for an empty line or `nil` for a null geometry; a vertex is
`{x, y}` or `[x, y]`, or `{x, y, z}` or `[x, y, z]` for a Z geometry. A line needs at least two
vertices. As in Shapely, the vertices of one list must all have the same number of values (a
mix, or a fourth value, is an error), while the rings of a polygon, the lines of a
multi-line and the polygons of a multipolygon may differ: the 2D ones next to a Z one get a NaN
Z. A row is 2D or Z on its own, so one column can hold both. Option: `:crs`.

    iex> s = GeoFrame.GeoSeries.line_strings_from_vertices([[{0, 0}, {1, 1}], nil])
    iex> GeoFrame.GeoSeries.to_wkt(s)
    ["LINESTRING(0 0,1 1)", nil]

# `m`

```elixir
@spec m(t()) :: Explorer.Series.t()
```

M (measure) of each point as an f64 series (`GeoSeries.m` in GeoPandas, also available as
`get_m/1`); same rules as `z/1`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT M (1 2 4)", "POINT ZM (1 2 3 5)"])
    iex> s |> GeoFrame.GeoSeries.m() |> Explorer.Series.to_list()
    [4.0, 5.0]

# `make_grid`

```elixir
@spec make_grid(t(), number(), keyword()) :: t()
```

A square or hexagonal grid over the total bounds of the series (GeoPandas `make_grid`),
with the series' CRS.

`cell_size` is the side of a square cell, or the distance between opposite sides of a
hexagon. Options:

  * `:grid_type` - `:square` (default) or `:hexagon`;
  * `:feature_type` - `:polygons` (default), `:centers` or `:corners`;
  * `:offset` - `{x, y}` of the grid origin (default: the lower left corner of the bounds);
  * `:intersect` - keep only the elements that intersect a geometry (default `true`);
  * `:flat_topped` - orient hexagons with a flat top (default: a corner points up).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))"])
    iex> s |> GeoFrame.GeoSeries.make_grid(2) |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [4.0, 4.0, 4.0, 4.0]

# `make_valid`

```elixir
@spec make_valid(t()) :: t()
```

Repairs invalid polygons and multipolygons (self-intersections, bowties) into valid
(multi)polygons, using `geo`'s triangulation-based repair, which differs from GEOS'
`make_valid` in vertex detail but not in the area it yields for simple cases. Valid
geometries and non-polygons are returned unchanged. A polygon whose ring is collinear (zero
area, invalid as in GEOS) collapses to its lines, as GEOS does. A repair that fails gives `nil`.

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `maximum_inscribed_circle`

```elixir
@spec maximum_inscribed_circle(t(), keyword()) :: t()
```

The largest circle that fits inside each polygon, as the line from its center to the nearest
boundary point (its length is the radius). The center is found by the cell search of
JTS/GEOS and lies within `:tolerance` of the optimum; the default is the longer side of the
bounding box divided by 1000. Rows that are not polygons are `nil`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 8 0, 8 4, 0 4, 0 0))"])
    iex> s |> GeoFrame.GeoSeries.maximum_inscribed_circle(tolerance: 0.001) |> GeoFrame.GeoSeries.length() |> Explorer.Series.to_list() |> Enum.map(&Float.round(&1))
    [2.0]

# `mean_coordinate`

```elixir
@spec mean_coordinate(t()) :: t()
```

The mean of each geometry's vertices as a point (GeoPolars `mean_coordinate`).

Polygon rings do not count their closing vertex twice; a closed line string does. This is
a vertex average, not a centroid. Empty and null rows give `nil`.

# `minimum_bounding_circle`

```elixir
@spec minimum_bounding_circle(t()) :: t()
```

The minimum bounding circle of each geometry as a 32-sided polygon laid out like Shapely's
(a buffered center, starting east and turning clockwise). A zero radius gives the point. The
polygon is inscribed in the true circle, so a vertex of the input between two circle
vertices can lie a hair outside it (use `minimum_bounding_radius/1` for the exact radius).

# `minimum_bounding_radius`

```elixir
@spec minimum_bounding_radius(t()) :: Explorer.Series.t()
```

The radius of the minimum bounding circle of each geometry (`0.0` for a point; `nil` for null
and empty rows).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.minimum_bounding_radius() |> Explorer.Series.to_list()
    [5.0]

# `minimum_clearance`

```elixir
@spec minimum_clearance(t()) :: Explorer.Series.t()
```

The minimum clearance of each geometry (`shapely.minimum_clearance`): the smallest distance
by which a vertex could move to make the geometry invalid, found as the least distance
between two vertices at different positions or between a vertex and a segment that does not
end in it.

A geometry without such a pair (a point, an empty geometry, one repeated position) reports
`:infinity`, as Shapely does; null rows give `nil`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0, 5 0.5)", "POINT (1 1)"])
    iex> s |> GeoFrame.GeoSeries.minimum_clearance() |> Explorer.Series.to_list()
    [0.5, :infinity]

# `minimum_clearance_line`

```elixir
@spec minimum_clearance_line(t()) :: t()
```

The line between the two points that realise `minimum_clearance/1`
(`shapely.minimum_clearance_line`); `LINESTRING EMPTY` when no clearance exists, `nil` for
null rows. Among equally close pairs the one reported, and the direction of the line, can
differ from GEOS.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0, 5 0.5)"])
    iex> s |> GeoFrame.GeoSeries.minimum_clearance_line() |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(5 0.5,5 0)"]

# `minimum_rotated_rectangle`

```elixir
@spec minimum_rotated_rectangle(t()) :: t()
```

The minimum-area rotated rectangle around each geometry's vertices. Fewer than three or
collinear vertices give a point or the line between the extreme vertices.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["MULTIPOINT ((0 0), (4 0), (4 2))"])
    iex> s |> GeoFrame.GeoSeries.minimum_rotated_rectangle() |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list() |> Enum.map(&Float.round(&1, 6))
    [8.0]

# `multi_line_strings_from_lines`

```elixir
@spec multi_line_strings_from_lines([[[vertex()]] | nil], keyword()) :: t()
```

Builds multi-line strings from lists of vertex lists, one list of lines per row
(GeoPolars `multi_line_string`). Option: `:crs`.

# `multi_points_from_vertices`

```elixir
@spec multi_points_from_vertices([[vertex()] | nil], keyword()) :: t()
```

Builds multipoints from vertex lists, one list per row (GeoPolars `multi_point`). See
`line_strings_from_vertices/2` for the row format.

# `multi_polygons_from_polygons`

```elixir
@spec multi_polygons_from_polygons([[[[vertex()]]] | nil], keyword()) :: t()
```

Builds multipolygons from lists of polygons (each a list of rings), one per row
(GeoPolars `multi_polygon`). Option: `:crs`.

# `normalize`

```elixir
@spec normalize(t()) :: t()
```

The canonical form of every geometry, as GEOS (`shapely.normalize`).

Polygon shells are clockwise and holes counter-clockwise, each ring starts at its smallest
coordinate, holes are sorted in descending order; an open line runs from its smaller end
and a closed line is normalised like a ring; the parts of multi-geometries and collections
are normalised and sorted in descending order. Null rows stay null; the CRS is kept.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (3 3, 1 1)"])
    iex> s |> GeoFrame.GeoSeries.normalize() |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(1 1,3 3)"]

# `notna`

```elixir
@spec notna(t()) :: Explorer.Series.t()
```

Boolean series: the negation of `isna/1`.

# `null_out_invalid`

```elixir
@spec null_out_invalid(t()) :: t()
```

Keeps valid geometries and turns invalid ones into nulls (GeoPolars `null_out_invalid`).

# `offset_curve`

```elixir
@spec offset_curve(t(), param(), keyword()) :: t()
```

The line parallel to each line at `distance` (`shapely.offset_curve`): positive distances
offset to the left of the line's direction, negative to the right. The result is a
`LINESTRING`, a `MULTILINESTRING` when the curve breaks (loops and spirals are cut away
where the offset comes closer to the line than `distance`) or `LINESTRING EMPTY`.

`distance` is a number, or a list or `Explorer.Series` with one entry per row (`nil` nulls
the row). Options (Shapely names):

  * `:quad_segs` - segments per quarter circle of round joins, default `8`; like GEOS, never
    fewer than 8 are drawn. At most `10000`.
  * `:join_style` - `:round` (default), `:mitre` or `:bevel`, for the outside corners.
  * `:mitre_limit` - for `:mitre`, the longest mitre as a multiple of the distance, default
    `5.0`, over 0.

Lines and multi-lines are offset part by part; a closed line is a line (no join at its
start). The rings of a polygon are offset as rings, so a positive distance grows it, and are
cut against each other; collections use their lines and polygons, points give an empty line.
Deviations from GEOS (see `docs/parity.md`): its input simplification is not applied, the
mitred outside offset of a closed line keeps the two pieces GEOS drops, and where the offset
of a polygon ring collapses to a line it is dropped only when it is clearly interior.

Raises when the vertices times `quad_segs` would exceed 10,000,000 (the raw curve is
proportional to both); a geometry whose cutting needs over 50,000,000 segment pairs is `nil`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.offset_curve(1) |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(0 1,10 1)"]

# `orient_polygons`

```elixir
@spec orient_polygons(t(), keyword()) :: t()
```

Orients polygon rings: counter-clockwise shells and clockwise holes by default, the
opposite with `exterior_cw: true`. Other types are unchanged.

# `overlaps`

```elixir
@spec overlaps(t(), other()) :: Explorer.Series.t()
```

Whether the geometries have the same dimension, their interiors intersect, and neither
contains the other.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `polygonize`

```elixir
@spec polygonize(t(), keyword()) :: t() | {t(), t(), t(), t()}
```

Polygons formed by the linework of the whole series (GeoPandas `polygonize`).

All geometries are used together and only their lines and rings count (points are ignored,
null rows skipped). Lines that do not close a polygon are left out. The result has one row
per polygon, in no particular order, shells clockwise and holes counter-clockwise like
GEOS; a polygon lying inside another's hole is a polygon of its own.

Options:

  * `:node` - `true` (default) merges the polygons of the input, drops lines inside them and
    nodes the linework (splits it wherever lines cross or touch) first; `false` takes every
    line as one edge from its first to its last vertex, so crossings that are not vertices
    of both lines are ignored.
  * `:full` - `true` returns `{polygons, cuts, dangles, invalid_rings}`, four series: the
    polygons, the edges that join two parts of the linework (cut edges), the edges that end
    in a dead end (dangles), and the rings that cross themselves.

Raises when the noding needs over 50,000,000 segment pairs. Deviation: the collinear
vertices at which merged input polygons met are dropped (see `docs/parity.md`).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 4 0, 4 4, 0 4, 0 0)", "LINESTRING (0 0, 4 4)"])
    iex> s |> GeoFrame.GeoSeries.polygonize() |> GeoFrame.GeoSeries.size()
    2

# `polygons_from_rings`

```elixir
@spec polygons_from_rings([[[vertex()]] | nil], keyword()) :: t()
```

Builds polygons from rings, one list of rings per row (GeoPolars `polygon`).

A row is `[shell, hole, ...]` where each ring is a list of vertices; open rings are closed,
and a ring needs three distinct vertices. `[]` is an empty polygon, `nil` a null geometry.
Option: `:crs`.

    iex> s = GeoFrame.GeoSeries.polygons_from_rings([[[{0, 0}, {4, 0}, {4, 4}]]])
    iex> GeoFrame.GeoSeries.to_wkt(s)
    ["POLYGON((0 0,4 0,4 4,0 0))"]

# `project`

```elixir
@spec project(t(), other(), keyword()) :: Explorer.Series.t()
```

The distance along each line to the point on it nearest `other` (Shapely `project`).

`other` is a series of points (positional) or a single point (a WKT string or a one-row
series, broadcast). With `normalized: true` the result is a fraction of the length
(default `false`). Rows that are not lines, or whose partner is not a point, are `nil`.
Pairing and CRS rules are those of `intersects/2`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.project("POINT (4 3)") |> Explorer.Series.to_list()
    [4.0]

# `relate`

```elixir
@spec relate(t(), other()) :: Explorer.Series.t()
```

The DE-9IM intersection matrix of each pair as a nine-character string series.

Characters are ordered interior/boundary/exterior of the left geometry against
interior/boundary/exterior of `other`, each one of `F` (empty), `0`, `1` or `2` (the
dimension of the intersection). For example two squares sharing an edge give `"FF2F11212"`.
Pairing, null and CRS rules are those of `intersects/2`.

# `relate_pattern`

```elixir
@spec relate_pattern(t(), other(), String.t()) :: Explorer.Series.t()
```

Whether each pair's DE-9IM matrix matches `pattern`, like Shapely `relate_pattern`.

`pattern` is nine characters (case-insensitive) from `T` (any intersection), `F` (none),
`*` (anything), or `0`, `1`, `2` (exactly that dimension). For example `"FF*F1****"`
matches polygons that touch along an edge. Anything else raises `ArgumentError`.
Pairing, null and CRS rules are those of `intersects/2`.

## Example

    iex> a = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))"])
    iex> b = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((4 0, 8 0, 8 4, 4 4, 4 0))"])
    iex> GeoFrame.GeoSeries.relate_pattern(a, b, "FF*F1****") |> Explorer.Series.to_list()
    [true]

# `remove_repeated_points`

```elixir
@spec remove_repeated_points(t(), number()) :: t()
```

Removes consecutive repeated vertices. With a `tolerance` (default `0.0`: exact repeats
only) a vertex within that distance of the last kept one is dropped too; the first and last
vertex of every line and ring are always kept. A ring or line that collapses becomes empty
(polygon) or keeps its two endpoints (line).

# `representative_point`

```elixir
@spec representative_point(t()) :: t()
```

A point guaranteed to lie within (or on) each geometry, unlike the centroid of a concave
polygon. The point chosen may differ from GEOS' choice. Empty geometries give `nil`.

Returns a `GeoSeries` with the same CRS. Null rows, and rows the operation is undefined
for, are `nil`. `boundary` and `exterior` keep Z and M; the other operations return 2D
geometries (Shapely drops Z there too).

# `reverse`

```elixir
@spec reverse(t()) :: t()
```

Reverses the vertex order of every line and ring. The parts of a multi-geometry keep their
order; points are unchanged.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 1 1, 2 0)"])
    iex> s |> GeoFrame.GeoSeries.reverse() |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(2 0,1 1,0 0)"]

# `rotate`

```elixir
@spec rotate(t(), param(), keyword()) :: t()
```

Rotates counter-clockwise by `angle` **degrees** about `:origin`.

`:origin` accepts the same values as in `scale/4` and defaults to `:center`; `angle` is a
number, list or `Explorer.Series`. Z is kept; M is dropped.

# `sample_points`

```elixir
@spec sample_points(t(), non_neg_integer() | [non_neg_integer()], keyword()) :: t()
```

Random points inside each polygon or along each line, one `MultiPoint` per row.

`size` is the number of points: one non-negative integer for every row, or a list with one
integer per row. Options:

  * `:method` - only `:uniform` (the GeoPandas `pointpats` methods are not available);
  * `:seed` - a non-negative integer. The same seed always gives the same points, but not
    NumPy's stream, so samples do not match GeoPandas'. Without a seed the clock decides.

Points, collections and zero-area polygons give an empty `MultiPoint`; null rows stay null.
A polygon that is too thin to hit by rejection sampling gives `nil`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 4 0, 4 4, 0 4, 0 0))"])
    iex> s |> GeoFrame.GeoSeries.sample_points(5, seed: 1) |> GeoFrame.GeoSeries.count_geometries() |> Explorer.Series.to_list()
    [5]

# `scale`

```elixir
@spec scale(t(), param(), param(), keyword()) :: t()
```

Scales by `xfact` and `yfact` about `:origin` (negative factors mirror).

`:origin` is `:center` (default; the centre of each geometry's bounding box, as in
GeoPandas), `:centroid`, an `{x, y}` pair used for every row, or a list with one `{x, y}`
(or `nil`) per row. The factors are numbers, lists or `Explorer.Series` (see `translate/4`).
Z is kept; the `:zfact` option (a number, default `1`) scales it about zero. M is dropped
(Shapely). `:zfact` is not available with per-row factors.

# `segmentize`

```elixir
@spec segmentize(t(), number()) :: t()
```

Adds vertices so that no segment is longer than `max_segment_length` (a positive number,
in CRS units; Euclidean). Each segment is split into equal parts. Points are unchanged.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 4 0)"])
    iex> s |> GeoFrame.GeoSeries.segmentize(2) |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(0 0,2 0,4 0)"]

# `self_intersects`

```elixir
@spec self_intersects(t()) :: Explorer.Series.t()
```

GeoPolars `self_intersects`: `true` for a line or multi-line that is not simple (see
`is_simple/1`), `false` for every other geometry type; null rows give `nil`.

# `set_crs`

```elixir
@spec set_crs(t(), String.t() | pos_integer() | nil, keyword()) :: t()
```

Replaces the CRS metadata without touching coordinates (no reprojection).

`crs` is stored as given: `"EPSG:<code>"`, `"OGC:CRS84"`, or a PROJJSON or WKT definition
(see `to_crs/2` for what a definition may hold). An integer EPSG code is accepted as in
`to_crs/2` (a positive integer; `4326` is stored as `"EPSG:4326"`). `nil` clears the CRS.

As in GeoPandas, a series that already has a CRS refuses a *different* one: it raises
`ArgumentError` unless `allow_override: true` is passed (use `to_crs/2` to reproject
instead). Setting the same CRS, setting one on a series without a CRS, and `nil` need no
option. CRSs are compared by their stored text, so `"OGC:CRS84"` and `"EPSG:4326"` count as
different, as in pyproj.

Options: `:allow_override` (boolean, default `false`).

# `set_precision`

```elixir
@spec set_precision(t(), number(), keyword()) :: t()
```

Snaps every coordinate to a grid of `grid_size`, like `shapely.set_precision`.

Options: `:mode` - `:valid_output` (default), `:pointwise` or `:keep_collapsed`.

  * `:pointwise` only rounds the coordinates (`floor(x / grid + 0.5) * grid`, halves round
    up also for negative numbers) and may leave invalid or degenerate geometry.
  * `:valid_output` also removes repeated vertices and collapsed parts (a line left with one
    point, a polygon or hole without area) and repairs a polygon that snapping made invalid.
  * `:keep_collapsed` is `:valid_output`, except that a line collapsed to a point stays a
    zero-length line.

`grid_size` `0` returns the geometry unchanged with floating precision; the sign is ignored.
The precision is stored on the series (`get_precision/1`), not in the GeoArrow data, so only
the result of `set_precision/3` carries it: any other operation returns floating precision.

Deviations from GEOS' snap-rounding overlay: lines are not noded (crossings between snapped
segments get no vertex), repaired polygons can differ in vertex order and start, and an
invalid input polygon is repaired instead of raising.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1.234 5.678)"])
    iex> s |> GeoFrame.GeoSeries.set_precision(0.1) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(1.2 5.7)"]

# `shared_paths`

```elixir
@spec shared_paths(t(), other()) :: t()
```

The paths two linear geometries share (GeoPandas `shared_paths`): per row a
`GEOMETRYCOLLECTION` of two `MULTILINESTRING`s, first the stretches that run the same way in
both inputs, then those that run in opposite ways (either can be empty).

Stretches are split where the overlap starts or ends, at every vertex they pass; a stretch
met twice is reported once. Both sides must be lines or multi-lines: any other geometry
(Shapely raises) and null rows give `nil`. `other` is a series, a one-row series or WKT, as
for `snap/3`.

    iex> a = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 4 0)"])
    iex> a |> GeoFrame.GeoSeries.shared_paths("LINESTRING (4 0, 1 0)") |> GeoFrame.GeoSeries.to_wkt()
    ["GEOMETRYCOLLECTION(MULTILINESTRING EMPTY,MULTILINESTRING((1 0,4 0)))"]

# `shortest_line`

```elixir
@spec shortest_line(t(), other()) :: t()
```

The `LineString` between the nearest points of each pair, running from the point on the
left geometry to the point on `other`. Its length equals `distance/2`. Geometries that
intersect give a zero-length line at a common point. Which of several equally near pairs is
returned may differ from GEOS. Pairing, null and CRS rules are those of `intersects/2`.

    iex> a = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> a |> GeoFrame.GeoSeries.shortest_line("POINT (4 3)") |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(4 0,4 3)"]

# `simplify`

```elixir
@spec simplify(t(), number(), keyword()) :: t()
```

Simplifies lines and polygon rings with `tolerance`; points are unchanged.

Option `:preserve_topology` (default `true`) picks the algorithm and, with it, the meaning
of `tolerance`:

  * `true` - Visvalingam-Whyatt with topology checks (`geo`'s `SimplifyVwPreserve`):
    `tolerance` is a minimum triangle **area** and rings never self-intersect or collapse.
  * `false` - Ramer-Douglas-Peucker as GEOS does it (Shapely's `preserve_topology=False`):
    `tolerance` is a maximum **distance** from the original. A ring that collapses to fewer
    than four vertices is removed: a hole disappears, a polygon whose shell collapses
    becomes empty, multipolygon parts and collection members drop, and a multi geometry
    with one part left is that part. A ring's start vertex is dropped when it lies within the
    tolerance of the chord between its neighbours. Lines keep their two end points at least. A
    polygonal result that is not valid (a self-crossing ring, parts that overlap or touch along
    an edge) is repaired with `buffer(0)` as GEOS does: a bowtie keeps its clockwise lobe,
    overlapping and touching parts are dissolved.

Shapely's topology-preserving mode is a distance-based Douglas-Peucker variant, so the
same `tolerance` yields different vertices here in the default mode.

# `simplify_coverage`

```elixir
@spec simplify_coverage(t(), number(), keyword()) :: t()
```

Simplifies the polygons of the whole series as one coverage, keeping it a valid coverage
(GeoPandas `simplify_coverage`, GEOS `CoverageSimplifier`).

The edges the polygons share are simplified once, with Visvalingam-Whyatt, so neighbours keep
matching vertex for vertex; no vertex is removed if that would make an edge cross or touch
another. `tolerance` is roughly the square root of the area of the triangles removed (in the
units of the coordinates; a negative value counts as its absolute value). Each polygon is
rebuilt from its edges, so a ring may start at another vertex (the first node of the coverage)
and, where a neighbour met a shared edge first, run the other way round.

Option `:simplify_boundary` (default `true`) - `false` only simplifies the edges two polygons
share and keeps the outer boundary of the coverage as it is.

Rows that are null, not polygons or multipolygons, or that hold a NaN or infinite
coordinate are `nil` (GeoPandas raises); empty polygons stay empty. The input is assumed to be
a valid coverage (see `is_valid_coverage/2`); an overlapping one is still simplified, but
the result may not be valid. Raises `ArgumentError` for a tolerance that is not a finite
number, and when the coverage has over 10,000,000 vertices or its checks visit over
50,000,000 vertices.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POLYGON ((0 0, 1 1.1, 2 0, 1.5 1, 2 2, 0 2, 0 0))", "POLYGON ((2 0, 4 0, 4 2, 2 2, 1.5 1, 2 0))"])
    iex> s |> GeoFrame.GeoSeries.simplify_coverage(1) |> GeoFrame.GeoSeries.to_wkt()
    ["POLYGON((2 0,2 2,0 2,2 0))", "POLYGON((2 0,4 0,4 2,2 2,2 0))"]

# `sindex_intersection`

```elixir
@spec sindex_intersection(t(), {number(), number(), number(), number()}) :: [
  non_neg_integer()
]
```

Zero-based positions of the rows whose bounding box intersects `{minx, miny, maxx, maxy}`
(edges inclusive), in row order. Like GeoPandas `sindex.intersection(bounds)`: it is an
envelope test, not an exact intersection (see `cx/5` for that). Null and empty rows never
match. Raises `ArgumentError` for an inverted box. A linear scan over the bounds.

# `sindex_nearest`

```elixir
@spec sindex_nearest(t(), t(), keyword()) ::
  {[non_neg_integer()], [non_neg_integer()], [float()]}
```

For each left geometry, the nearest right geometries by planar euclidean distance.

Returns `{left_idx, right_idx, distances}` as parallel lists ordered by left row then
right row. The distance is geometry to geometry (not centroids), so a point inside a
polygon is at distance `0.0`. Every right geometry at exactly the minimum distance is
returned (ties), like GeoPandas. Computed with a best-first R-tree walk, then exact
distances.

Options:

  * `:max_distance` - non-negative; left rows whose nearest geometry is farther have no
    match (the limit itself is inclusive).
  * `:exclusive` - when `true`, right geometries equal to the left one (topologically) are
    ignored, so a frame joined with itself finds each row's nearest *other* row.
    Default `false`.

Null and empty rows never match. Differing CRS (both set) raise `ArgumentError`.

# `sindex_query`

```elixir
@spec sindex_query(
  t() | [String.t() | nil] | String.t() | nil,
  t(),
  atom(),
  keyword()
) ::
  {[non_neg_integer()], [non_neg_integer()]} | [non_neg_integer()]
```

All pairs of rows `{i, j}` for which `left[i].predicate(right[j])` holds, found with an
R-tree built over the bounding boxes of `right` and refined with the exact predicate.
`left` plays the role of the input geometries and `right` of the tree, so GeoPandas'
`tree.sindex.query(geometry, ...)` is `sindex_query(geometry, tree, ...)`.

`left` is one of:

  * a series, or a list of WKT strings (`nil` for a null geometry), the array form:
    returns `{left_indices, right_indices}`, two parallel lists of zero-based row
    positions, ordered by left then right position. (Plain lists rather than series: they
    are consumed as `take/2` indices, and the pair count is data-dependent.)
  * a single WKT string (or `nil`), the scalar form: returns the list of matching `right`
    positions in ascending order.

A list or string is parsed with the CRS of `right`. The result equals evaluating the
predicate over every pair, only faster.

`predicate` is one of `:intersects` (default), `:within`, `:contains`, `:touches`,
`:crosses`, `:overlaps`, `:covers`, `:covered_by`, `:geom_equals`, `:contains_properly` or
`:dwithin` (see `sindex_valid_query_predicates/0`). The
predicate reads `left.predicate(right)`: `:within` means the left geometry is within the
right one. `:disjoint` is rejected because a spatial index cannot answer it.

Options:

  * `:distance` - required, non-negative, in CRS units for `:dwithin`.
  * `:sort` - boolean, accepted for GeoPandas compatibility. The result is always ordered
    by (left, right) position, which is what `sort: true` gives there, so it changes
    nothing (default `false`).

Null and empty rows never match. Differing CRS (both set) raise `ArgumentError`, as do
unknown predicates and a missing distance. Querying is single-threaded.

# `sindex_valid_query_predicates`

```elixir
@spec sindex_valid_query_predicates() :: [atom()]
```

The predicate names `sindex_query/4` (and `GeoFrame.GeoDataFrame.sjoin/3`) accept, like
GeoPandas `sindex.valid_query_predicates` (`:disjoint` is excluded, and GeoPandas' `nil`
default is spelled `:intersects`).

# `size`

```elixir
@spec size(t()) :: non_neg_integer()
```

Number of rows, nulls included.

# `skew`

```elixir
@spec skew(t(), param(), param(), keyword()) :: t()
```

Shears by `xs` along x and `ys` along y about `:origin` (Shapely `skew`; x' = x + tan(xs) *
(y - y0), y' = y + tan(ys) * (x - x0)).

Options: `:origin` as in `scale/4` (default `:center`), `:use_radians` (default `false`,
angles are degrees). `xs` and `ys` are numbers, lists or `Explorer.Series`. Z is kept; M is dropped.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 0 2)"])
    iex> skewed = GeoFrame.GeoSeries.skew(s, 45, 0, origin: {0, 0})
    iex> expected = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 2 2)"])
    iex> skewed |> GeoFrame.GeoSeries.geom_equals_exact(expected, 1.0e-9) |> Explorer.Series.to_list()
    [true]

# `snap`

```elixir
@spec snap(t(), other(), number()) :: t()
```

Snaps the vertices and segments of each geometry to the vertices of `other`, within
`tolerance` (GeoPandas `snap`, GEOS `GeometrySnapper`).

`other` is a series (paired by position), a one-row series or a WKT string (both broadcast).
Each snap point in turn moves the nearest vertex of a line or ring that lies closer than
`tolerance` onto itself, and a snap point closer than `tolerance` to a segment is inserted
into the nearest one. The result keeps the type of the input; it is not guaranteed to be
valid. `tolerance` is one number (GeoPandas also accepts an array-like). Rows that are null
on either side, and rows whose work (vertices times snap points) exceeds 50,000,000, are
`nil`. The order in which several snap points compete for one vertex follows GEOS in about
99 % of random cases (see `docs/parity.md`).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["LINESTRING (0 0, 10 0)"])
    iex> s |> GeoFrame.GeoSeries.snap("POINT (5 0.5)", 1) |> GeoFrame.GeoSeries.to_wkt()
    ["LINESTRING(0 0,5 0.5,10 0)"]

# `symmetric_difference`

```elixir
@spec symmetric_difference(t(), other()) :: t()
```

Points in exactly one of the two geometries. Element-wise; returns a GeoSeries with the CRS of the left side.

Pairing, null and CRS rules are those of `intersects/2` (`other` may be a series of the
same length, or a single geometry / WKT string that broadcasts).

Every combination of points, lines and polygons is supported, with GEOS results: lines are
noded (crossings, overlaps), the lower-dimensional parts of a result are kept (two squares
sharing an edge intersect in that `LINESTRING`, sharing a corner in a `POINT`), and a result
of several dimensions is a `GEOMETRYCOLLECTION` with one member per part. A
`GeometryCollection` input is supported by `intersection` only (member by member); the other
operations give `nil` for it. Empty results are empty geometries
(`POLYGON EMPTY`, `LINESTRING EMPTY`, `MULTIPOINT EMPTY`), not `nil`.

# `take`

```elixir
@spec take(t(), [non_neg_integer()] | binary()) :: t()
```

Selects rows by zero-based position; repeats and reordering are allowed.

`indices` is a list, or a binary of native-endian unsigned 32-bit integers (what
`Explorer.Series.from_binary(binary, {:u, 32})` reads), which avoids building a list when
millions of rows are selected.

Raises `ArgumentError` for out-of-bounds indices.

# `take_nullable`

```elixir
@spec take_nullable(t(), [non_neg_integer() | nil]) :: t()
```

Like `take/2` for a list of positions in which `nil` selects a null geometry (with the CRS
of the series). Used where rows may have no partner: joins and `dissolve`.

# `to_arrow`

```elixir
@spec to_arrow(t(), keyword()) :: binary()
```

Encodes the series as an Arrow IPC **stream** (a binary) holding one table with a
`geometry` column. The field carries the GeoArrow extension metadata
(`ARROW:extension:name` = `geoarrow.wkb` or a native `geoarrow.*` name,
`ARROW:extension:metadata` with the CRS as PROJJSON), so `pyarrow`, GeoPandas
(`GeoSeries.from_arrow`) and other GeoArrow readers consume it directly.

There is no Arrow C Data Interface binding on the BEAM, so IPC bytes are the interchange
(one copy).

Option `:geometry_encoding` - `:wkb` (default) or `:geoarrow`. The native encoding needs
one geometry kind (a type and its multi variant may mix and become the multi type) and
raises `ArgumentError` for mixed kinds or collections. Other failures also raise.

# `to_crs`

```elixir
@spec to_crs(t(), String.t() | pos_integer()) :: t()
```

Reprojects to `target`, returning a copy whose CRS is `target`.

`target` is `"EPSG:<code>"`, `"OGC:CRS84"` (lon/lat WGS 84), an integer EPSG code
(`3857` is `"EPSG:3857"`), or a full CRS definition as PROJJSON or WKT (WKT1 or WKT2) text,
as `pyproj.CRS.from_user_input` takes. The series must have a CRS (as in GeoPandas, a naive
series raises: use `set_crs/2` first). Reprojecting to the CRS the series already has returns
an unchanged copy.

The engine is pure Rust (`proj4rs` with the bundled EPSG tables), so no PROJ install is
needed. Every EPSG geographic, geocentric, projected and compound CRS is available: the
`crs-definitions` table plus a compact supplementary table generated from the PROJ database
(about 1 200 newer codes, 50 KB packed). A definition given as text is converted without a
code: ellipsoid, prime meridian, units, axes, a WKT1 `TOWGS84` or the abridged transformation
of a bound CRS, and these methods: Transverse Mercator (also south orientated), Lambert
Conic Conformal (1SP, 1SP variant B, 2SP, 2SP Belgium, 2SP Michigan, west orientated), Albers,
Lambert Azimuthal Equal Area, Azimuthal Equidistant (also Guam), Oblique and Polar
Stereographic, Hotine Oblique Mercator (A, B, the Swiss one), Mercator (A, B, Pseudo-Mercator),
Cassini-Soldner (also Hyperbolic), Equidistant Cylindrical, Lambert Cylindrical Equal Area,
Krovak (also Modified), Laborde, Colombia Urban, American Polyconic, New Zealand Map Grid and
Equal Earth. Any other method is an error that names it (Bonne, Tunisia Mining Grid, Local
Orthographic, Transverse Mercator Zoned Grid System, ...). A definition that carries the
EPSG identifier of its base geographic CRS shifts its datum exactly like the code does; a
geographic CRS without one finds its datum shifts by name (as PROJ identifies it), and any
other datum is left unshifted (PROJ's ballpark). The text is stored as given by `set_crs/2`
and by the result of `to_crs/2`.

Axis order is always x = easting/longitude, y = northing/latitude, for every CRS
including `EPSG:4326` (GeoPandas `always_xy=True`). Rows that are null, or whose transform fails
(outside the projection's domain), become null. Z is kept (unchanged between CRSs that are
not geocentric; transformed to or from a geocentric CRS such as `EPSG:4978`); M is dropped.

## Datum shifts and accuracy

A datum other than WGS 84 (NAD27, OSGB36, ED50, DHDN, Tokyo, ...) is shifted by a grid when
one is installed and otherwise by the Helmert (`+towgs84`) operation PROJ picks for the point
by area of use: the best-accuracy operation whose area holds it, from a table generated from
the PROJ database, and no shift where PROJ has only a ballpark transformation. Nothing is
downloaded. Without grids this agrees with pyproj to a few metres for about 99 % of the EPSG
codes; it is centimetres to a metre with NTv2 or GeoTIFF grids of PROJ-data (under a
millimetre of PROJ on the same file). A point outside every installed grid takes the Helmert
operation instead of failing. See `GeoFrame.Grids` to point at the grid files and
`docs/parity.md` for the measured numbers and the known deviations.

## Units, axes and projections

A geographic CRS is read and written in its own angular unit (grads for the Paris-meridian
CRSs such as `EPSG:4807`, with the Paris prime meridian applied), and a projected CRS keeps
its axis directions (`EPSG:5513` is southing/westing), both as pyproj with `always_xy`.
Cassini-Soldner, Hotine Oblique Mercator (variants A and B), Polyconic, Equal Earth,
`EPSG:4087`'s ellipsoidal Equidistant Cylindrical and the New Zealand Map Grid are
implemented on top of `proj4rs` after the PROJ formulas.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)"], crs: "EPSG:4326")
    iex> s |> GeoFrame.GeoSeries.to_crs(3857) |> GeoFrame.GeoSeries.crs()
    "EPSG:3857"

# `to_file`

```elixir
@spec to_file(t(), Path.t(), keyword()) :: :ok | {:error, String.t()}
```

Writes the series to a vector file (GeoPandas `GeoSeries.to_file`): a frame whose only
column is the geometry, written by `GeoFrame.write_file/3`, which documents the format
selection and options. Returns `:ok` or `{:error, message}`.

# `to_geo_dict`

```elixir
@spec to_geo_dict(t(), keyword()) :: map()
```

The series as a GeoJSON-like map, like GeoPandas `GeoSeries.to_geo_dict`; with the default
options it equals `to_geo_interface/1`.

Options: `:show_bbox` (default `true`) and `:drop_id` (default `false`); `:na` is accepted
for symmetry with `GeoFrame.GeoDataFrame.to_geo_dict/2` (a series has no properties).
Unknown options raise `ArgumentError`.

# `to_geo_interface`

```elixir
@spec to_geo_interface(t()) :: map()
```

The `__geo_interface__` of the series: a `FeatureCollection` map (string keys) with an `id`,
empty `properties`, `geometry` and `bbox` per feature, and the collection `bbox`.

See `to_geo_dict/2` for the variant with options.

# `to_geojson`

```elixir
@spec to_geojson(t()) :: [map() | nil]
```

GeoJSON geometry objects (RFC 7946), one decoded map per row.

Null rows, and rows that cannot be expressed as a `geo` geometry (such as `POINT EMPTY`),
give `nil`. Coordinates are emitted as stored: GeoJSON has no CRS member, so reproject to
longitude/latitude (`EPSG:4326`) first if the data is in another CRS.

The conversion runs in Rust and returns JSON text, which is decoded here with `Jason`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 2)", nil])
    iex> GeoFrame.GeoSeries.to_geojson(s)
    [%{"type" => "Point", "coordinates" => [1.0, 2.0]}, nil]

# `to_json`

```elixir
@spec to_json(t(), keyword()) :: String.t()
```

The series as a GeoJSON `FeatureCollection` string, like GeoPandas `GeoSeries.to_json`.

Every row is a `Feature` with a string `id` (the row position), empty `properties`, the
`geometry` (`null` for null or unrepresentable rows) and its `bbox`; the collection has the
`bbox` of all rows. A CRS other than EPSG:4326 adds the `crs` member as GeoPandas writes it
(`urn:ogc:def:crs:EPSG::32617`); CRS values that are not `AUTHORITY:CODE` add none. The JSON
is compact, where Python's `json.dumps` puts spaces after `,` and `:`.

Options: `:show_bbox` (default `true`), `:drop_id` (default `false`), `:to_wgs84` (default
`false`, reprojects to EPSG:4326 first; needs a CRS).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 2)"])
    iex> GeoFrame.GeoSeries.to_json(s, show_bbox: false, drop_id: true)
    ~s({"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[1.0,2.0]}}]})

# `to_wkb`

```elixir
@spec to_wkb(t(), keyword()) :: [binary() | nil]
```

Returns the geometries as WKB (`nil` for nulls).

Options:

  * `:hex` - when `true`, returns upper-case hexadecimal strings instead of binaries,
    like GeoPandas `to_wkb(hex=True)`. Default `false`.
  * `:srid` - an integer, or `true` to take it from an `"EPSG:<code>"` CRS, to emit PostGIS
    EWKB with that SRID (GeoPandas `to_wkb(include_srid=True)`). Default: plain WKB.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 2)"])
    iex> GeoFrame.GeoSeries.to_wkb(s, hex: true)
    ["0101000000000000000000F03F0000000000000040"]
    iex> GeoFrame.GeoSeries.to_wkb(s, hex: true, srid: 4326)
    ["0101000020E6100000000000000000F03F0000000000000040"]

# `to_wkt`

```elixir
@spec to_wkt(t()) :: [String.t() | nil]
```

Returns the geometries as WKT strings (`nil` for nulls).

# `total_bounds`

```elixir
@spec total_bounds(t()) :: bounds() | nil
```

Bounds over all rows as `{minx, miny, maxx, maxy}`, or `nil` if there is none.

# `touches`

```elixir
@spec touches(t(), other()) :: Explorer.Series.t()
```

Whether the geometries share boundary points but no interior points, such as two squares
sharing an edge or a point on a polygon edge.

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `translate`

```elixir
@spec translate(t(), param(), param(), keyword()) :: t()
```

Shifts every coordinate by `xoff` and `yoff`.

Each offset is a number, or a list or `Explorer.Series` with one entry per row (a `nil`
entry nulls that row). Z is kept; the `:zoff` option (a number, default `0`) shifts it.
M is dropped (Shapely). `:zoff` is not available with per-row offsets.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (1 1)"])
    iex> s |> GeoFrame.GeoSeries.translate(2, 3) |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(3 4)"]

# `union`

```elixir
@spec union(t(), other()) :: t()
```

All points in either geometry. Element-wise; returns a GeoSeries with the CRS of the left side.

Pairing, null and CRS rules are those of `intersects/2` (`other` may be a series of the
same length, or a single geometry / WKT string that broadcasts).

Every combination of points, lines and polygons is supported, with GEOS results: lines are
noded (crossings, overlaps), the lower-dimensional parts of a result are kept (two squares
sharing an edge intersect in that `LINESTRING`, sharing a corner in a `POINT`), and a result
of several dimensions is a `GEOMETRYCOLLECTION` with one member per part. A
`GeometryCollection` input is supported by `intersection` only (member by member); the other
operations give `nil` for it. Empty results are empty geometries
(`POLYGON EMPTY`, `LINESTRING EMPTY`, `MULTIPOINT EMPTY`), not `nil`.

# `union_all`

```elixir
@spec union_all(t()) :: t()
```

The union of all non-null geometries as a **one-row** GeoSeries (GeoPandas returns a scalar).

Polygons are merged with a single `unary_union`, lines are noded and overlaps merged, and
points are deduplicated. A mix of families gives a `GEOMETRYCOLLECTION` in which lines inside
a polygon and points on a polygon or line are absorbed. A `GeometryCollection` row gives a
`nil` row; no non-null input gives `GEOMETRYCOLLECTION EMPTY`.

# `union_groups`

```elixir
@spec union_groups(t(), [non_neg_integer()], non_neg_integer()) :: t()
```

Grouped `union_all/1`: `group_ids` assigns each row to a group in `0..n_groups-1`, and the
result has one row per group (same CRS).

Null rows are skipped; a group without non-null rows gives `GEOMETRYCOLLECTION EMPTY`, and
a group containing a `GeometryCollection` row gives a null row, as `union_all/1` does. Raises
`ArgumentError` when `group_ids` has the wrong length or an id is out of range.

# `voronoi_polygons`

```elixir
@spec voronoi_polygons(t(), keyword()) :: t()
```

The Voronoi diagram of the vertices of the whole series, as GeoPandas does: every geometry
contributes its vertices to one point cloud, and the result has one polygon per distinct
vertex, in vertex order (a new series, not aligned with the input). Fewer than two vertices
give an empty series.

The cells are clipped to the envelope of the vertices grown by its longer side on every
side, like GEOS. Options:

  * `:tolerance` - merge vertices closer than this (default `0.0`);
  * `:extend_to` - a geometry (series or WKT) whose envelope the diagram must also cover;
  * `:only_edges` - return one `LineString` per interior cell side instead of the cells;
  * `:ordered` - accepted for Shapely compatibility; cells always come in vertex order.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (0 0)", "POINT (2 0)", "POINT (5 0)"])
    iex> s |> GeoFrame.GeoSeries.voronoi_polygons() |> GeoFrame.GeoSeries.area() |> Explorer.Series.to_list()
    [60.0, 25.0, 65.0]

# `within`

```elixir
@spec within(t(), other()) :: Explorer.Series.t()
```

Whether the geometry lies inside `other` with interiors sharing a point. The converse of
`contains/2`, so a point on the boundary of `other` is not `within` it (see `covered_by/2`).

Element-wise, with GeoPandas semantics, returning a boolean `Explorer.Series`.

`other` is a `GeoSeries` of the same length, or a single geometry (a WKT string, or a
one-row `GeoSeries`) that is compared with every row. Rows where either side is null, or is
an empty geometry, are `nil`. A length mismatch raises `ArgumentError`, as does a CRS
mismatch between two series that both have a CRS (GeoPandas only warns; GeoFrame fails
loudly). Series with no CRS are compatible with any CRS.

# `wrap_longitude`

```elixir
@spec wrap_longitude(t()) :: t()
```

Wraps every x into `[-180, 180)` (so `180` becomes `-180`), like GeoPolars
`wrap_longitude`. Only coordinates move: geometries are not split at the antimeridian.

The series must have a geographic CRS or none (then degrees are assumed); a projected CRS
raises `ArgumentError`.

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT (190 10)"], crs: "EPSG:4326")
    iex> s |> GeoFrame.GeoSeries.wrap_longitude() |> GeoFrame.GeoSeries.to_wkt()
    ["POINT(-170 10)"]

# `x`

```elixir
@spec x(t()) :: Explorer.Series.t()
```

X coordinate of each point as an f64 series. Non-point geometries, empty points and nulls
give `nil` (GeoPandas raises for non-points).

# `y`

```elixir
@spec y(t()) :: Explorer.Series.t()
```

Y coordinate of each point; same rules as `x/1`.

# `z`

```elixir
@spec z(t()) :: Explorer.Series.t()
```

Z coordinate of each point as an f64 series (`GeoSeries.z` in GeoPandas, also available as
`get_z/1`). Non-point geometries, empty points, points without Z and nulls give `nil`
(GeoPandas raises for non-points and gives NaN for 2D points).

    iex> s = GeoFrame.GeoSeries.from_wkt!(["POINT Z (1 2 3)", "POINT (1 2)", nil])
    iex> s |> GeoFrame.GeoSeries.z() |> Explorer.Series.to_list()
    [3.0, nil, nil]

---

*Consult [api-reference.md](api-reference.md) for complete listing*
