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

`dissolve/2`: merge rows that share a key into one row, like `geopandas.GeoDataFrame.dissolve`.

## How rows stay aligned

Group ids are computed once on the Elixir side from the key columns, one dense id per row,
numbered in result order (sorted key order, or first appearance with `sort: false`). The
same ids drive both halves:

  * the geometry: `GeoFrame.GeoSeries.union_groups/3` unions each group in one NIF call and
    returns one row per id;
  * the attributes: a temporary id column is grouped and summarised with Explorer, then
    sorted by id.

So result row `i` of the attributes and of the geometry always describe group `i`.

## Result

Group keys are kept as leading columns (GeoPandas makes them the index), followed by the
remaining attributes. Nulls sort last, as in GeoPandas.

# `dissolve`

```elixir
@spec dissolve(GeoFrame.GeoDataFrame.t(), keyword()) :: GeoFrame.GeoDataFrame.t()
```

Dissolves `gdf` by key columns.

Options:

  * `:by` - a column name (string or atom) or a list of names; `nil` (default) dissolves
    everything into a single row.
  * `:aggfunc` - `:first` (default), `:last`, `:sum`, `:mean`, `:min`, `:max` or `:count`,
    applied to every non-key attribute (numeric functions raise on
    non-numeric columns, so list the columns explicitly for mixed frames); or a keyword list / map of column to function, in
    which case only the listed columns are kept (after the keys). Secondary geometry columns
    are aggregated like the other columns, but only `:first`, `:last` (the first / last
    non-null geometry of the group, keeping the column's CRS) and `:count` (an integer
    attribute) apply to geometry: any other function raises `ArgumentError`, as GeoPandas
    raises `TypeError`. Dissolving by a geometry column raises `ArgumentError`.
  * `:dropna` - `true` (default) drops rows with a null key; `false` keeps them as a group.
  * `:sort` - `true` (default) orders groups by key, `false` by first appearance.
  * `:observed` - for `:category` key columns only. `true` (default) keeps the groups that
    occur in the data; `false` also adds every unobserved combination of the keys' values as
    an empty group, like `observed=False` in GeoPandas: the geometry is
    `GEOMETRYCOLLECTION EMPTY`, `:sum` and `:count` give 0 and the other functions null.
    Each key's levels are the values it holds: Explorer categoricals share one
    process-wide category mapping, so a column has no categories of its own beyond its
    values, and categories with no rows (which pandas can declare) are not added; with one
    key the option therefore adds nothing. Groups are ordered by key text; with
    `sort: false` each key's values come in order of appearance.
    Without category keys the option has no effect; mixing category and other keys raises
    `ArgumentError`. GeoPandas defaults to `false`; the default here stays `true` so existing
    calls keep their result.
  * `:as_index` - accepted for parity. There is no index: the keys are always leading
    columns, which is what `as_index=False` gives in GeoPandas (except that the geometry
    column is last). `false` is a no-op; `true` raises `ArgumentError`.
  * `:level` - not supported (no index levels); raises `ArgumentError`.

Geometries of a group are merged with `GeoFrame.GeoSeries.union_all/1` semantics (null
geometries skipped). The CRS is preserved. Raises `ArgumentError` for unknown columns or
aggregation functions, or when a key is the geometry column.

---

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