Source: https://gometry.monicz.dev/ecosystem/postgis/

# PostgreSQL & PostGIS

[Gres](https://gres.monicz.dev/) is the PostgreSQL driver for gometry. With
`gres[postgis]`, PostGIS `geometry` and `geography` values arrive as gometry
geometries and bind back as query parameters, so spatial data moves between the
database and Python without WKT, per-row WKB handling or a second geometry
library.

```bash
uv add "gres[postgis]"
```

## Who owns what

| Concern | Owner |
| --- | --- |
| Storage, spatial indexes, SQL predicates over tables | [PostGIS](https://postgis.net/documentation/) |
| Binary transport, SRID ↔ CRS resolution through the database's `spatial_ref_sys`, model and SRID checks on bind | Gres |
| Geometry operations, measurement, CRS transforms, validation, Arrow, GeoParquet and dataframes | gometry |

Neither layer moves coordinates on the way through: Gres refuses a value whose
CRS or edge model does not match its destination rather than transforming it.
Transform with [`to_space`](https://gometry.monicz.dev/guide/crs/) or with PostGIS `ST_Transform`.
EWKB carries no coordinate epoch. If you need it on readback, store the
decimal year alongside the geometry.

## Edge models

| PostGIS type | gometry model |
| --- | --- |
| `geometry` | Planar |
| `geography` | Spherical |

A Planar value binds to `geometry` and a Spherical value to `geography`. The
Chart model has no PostGIS type; choose the stored meaning explicitly with
`with_space` before binding.

partial: requires gres[postgis] and a PostGIS database

```python
import gometry as gm
from gres import Connection, scalar

async with Connection() as db:
    parcel = await db.fetch_one('SELECT boundary FROM parcel WHERE id = $1', (7,), row=scalar(gm.Geometry))
    setback = parcel.buffer(-3, metric='cartesian')  # parcel.space: Planar, CRS from spatial_ref_sys
    await db.execute('UPDATE parcel SET buildable = $1 WHERE id = $2', (setback, 7))
```

[PostGIS geometry and geography](https://gres.monicz.dev/guide/spatial/) in the
Gres guide covers SRIDs and database-local definitions, index-backed queries,
GeoArrow streaming and `COPY`, exact EWKB transport, and
[curves and surfaces](https://gometry.monicz.dev/guide/curves/), which arrive as gometry's
`CircularString`, `CurvePolygon`, `TIN` and related types.

## Without Gres

Any PostgreSQL client that exposes binary values can exchange EWKB with
gometry directly: write with `to_wkb(srid=...)` and read with
`from_wkb(payloads, srids=...)`, supplying the database's SRID mapping as
described in [The database boundary](https://gometry.monicz.dev/ecosystem/text-formats/#the-database-boundary).
