PostgreSQL & PostGIS¶
Gres 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.
uv add "gres[postgis]"
Who owns what¶
| Concern | Owner |
|---|---|
| Storage, spatial indexes, SQL predicates over tables | PostGIS |
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 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.
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 in the
Gres guide covers SRIDs and database-local definitions, index-backed queries,
GeoArrow streaming and COPY, exact EWKB transport, and
curves and surfaces, 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.