Source: https://gres.monicz.dev/api/spatial/

# PostGIS

[PostGIS](https://gres.monicz.dev/guide/spatial/) explains exact and computational transport.

## EwkbGeometry

```python
EwkbGeometry(
    wkb: Buffer | EwkbGeometry | EwkbGeography, /, *, srid: int | None = None
)
```

A PostGIS `geometry` value as stored, in extended well-known binary (EWKB).

Results use this carrier for `geometry` columns under
`Decoding(geometry='exact')`, and it binds only to `geometry`
parameters and columns. Reading or binding it needs neither gometry nor
access to `spatial_ref_sys`. Construction checks the binary structure but
does not interpret coordinates. Values compare and hash by their bytes,
pickle, and export a read-only buffer.

Every PostGIS geometry kind is accepted, including curves and polyhedral
surfaces.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `wkb` | `Buffer \| EwkbGeometry \| EwkbGeography` | EWKB or ISO WKB bytes, any byte buffer, or another carrier. | *required* |
| `srid` | `int \| None` | SRID to record when `wkb` has none or has SRID 0. | `None` |

Raises:

| Type | Description |
| --- | --- |
| `ValueError` | The bytes are not a well-formed PostGIS value, nested parts carry different SRIDs, or `srid` conflicts with a nonzero SRID already in `wkb`. |

### ewkb `property`

```python
ewkb: bytes
```

The EWKB bytes, including the SRID when it is nonzero.

### srid `property`

```python
srid: int
```

The database SRID, or 0 when unspecified. Not necessarily an EPSG code.

### geometry\_type `property`

```python
geometry_type: str
```

The PostGIS shape kind, such as `'Point'` or `'CircularString'`.

### has\_z `property`

```python
has_z: bool
```

Whether coordinates carry a Z ordinate.

### has\_m `property`

```python
has_m: bool
```

Whether coordinates carry an M ordinate.

## EwkbGeography

```python
EwkbGeography(
    wkb: Buffer | EwkbGeometry | EwkbGeography, /, *, srid: int | None = None
)
```

A PostGIS `geography` value as stored, in extended well-known binary (EWKB).

Results use this carrier for `geography` columns under
`Decoding(geometry='exact')`, and it binds only to `geography`
parameters and columns. Reading or binding it needs neither gometry nor
access to `spatial_ref_sys`. Construction checks the binary structure but
does not interpret coordinates. Values compare and hash by their bytes,
pickle, and export a read-only buffer.

Kinds that PostGIS geography does not support, such as curves, are
rejected.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `wkb` | `Buffer \| EwkbGeometry \| EwkbGeography` | EWKB or ISO WKB bytes, any byte buffer, or another carrier. | *required* |
| `srid` | `int \| None` | SRID to record when `wkb` has none or has SRID 0. | `None` |

Raises:

| Type | Description |
| --- | --- |
| `ValueError` | The bytes are not a well-formed PostGIS value, nested parts carry different SRIDs, or `srid` conflicts with a nonzero SRID already in `wkb`. |

### ewkb `property`

```python
ewkb: bytes
```

The EWKB bytes, including the SRID when it is nonzero.

### srid `property`

```python
srid: int
```

The database SRID, or 0 when unspecified. Not necessarily an EPSG code.

### geometry\_type `property`

```python
geometry_type: str
```

The PostGIS shape kind, such as `'Point'` or `'MultiPolygon'`.

### has\_z `property`

```python
has_z: bool
```

Whether coordinates carry a Z ordinate.

### has\_m `property`

```python
has_m: bool
```

Whether coordinates carry an M ordinate.

## SpatialParameter `dataclass`

```python
SpatialParameter(value: Geometry, srid: int)
```

Bind a gometry value with an explicit SRID from the destination database.

Use it when more than one SRID in the database's `spatial_ref_sys`
defines the value's CRS, or to state the destination SRID explicitly. The
SQL parameter type selects `geometry` or `geography`. Gres checks that
the value's CRS matches that SRID's definition and that its model matches
the family; it never transforms coordinates. A typed destination column
with a different SRID rejects the value.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `value` | `Geometry` | A gometry geometry with a declared CRS. | *required* |
| `srid` | `int` | A positive SRID from the destination database's `spatial_ref_sys`. Not necessarily an EPSG code. | *required* |

Raises:

| Type | Description |
| --- | --- |
| `ValueError` | `srid` is not a positive PostgreSQL `int4`. |

### value `instance-attribute`

```python
value: Geometry
```

### srid `instance-attribute`

```python
srid: int
```
