Source: https://gometry.monicz.dev/api/features/

# Features & attributes

Immutable geometry, property and ID snapshots, aligned selections, and exact Arrow values.

**Related:** [Arrow & storage](https://gometry.monicz.dev/ecosystem/arrow/)

## Feature

Accepted call forms

```python
Feature(
    geometry: NewFeatureG,
    *,
    properties: Mapping[str, FeatureScalarT],
    id: NewFeatureId | None = None,
) -> Feature[NewFeatureG, FeatureScalarT, NewFeatureId]
```

```python
Feature(
    geometry: NewFeatureG,
    *,
    properties: Mapping[str, FeatureInput] | None = None,
    id: NewFeatureId | None = None,
) -> Feature[NewFeatureG, FeatureValue, NewFeatureId]
```

```python
Feature(
    geometry: NewFeatureG,
    *,
    properties: Mapping[str, FeatureScalarT],
    id: str | int | float | integer[Any] | floating[Any],
) -> Feature[NewFeatureG, FeatureScalarT, str | int | float]
```

```python
Feature(
    geometry: NewFeatureG,
    *,
    properties: Mapping[str, FeatureInput] | None = None,
    id: str | int | float | integer[Any] | floating[Any],
) -> Feature[NewFeatureG, FeatureValue, str | int | float]
```

One immutable geometry, property and ID snapshot.

Create a feature snapshot.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometry` | `NewFeatureG` | The geometry, or `None` for an unlocated feature. | *required* |
| `properties` | `Mapping[str, FeatureScalarT] \| (Mapping[str, FeatureInput] \| None)` | Property values to snapshot recursively. `None` denotes null properties; an empty mapping remains distinct. | `varies by call form` |
| `id` | `NewFeatureId \| None \| (str \| int \| float \| integer[Any] \| floating[Any])` | The optional feature identifier. Numeric IDs must be finite and boolean IDs are not accepted. | `varies by call form` |

Returns:

| Type | Description |
| --- | --- |
| `Feature` | The immutable feature snapshot. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If `geometry`, `properties`, or `id` has an unsupported type. |
| `GeometryError` | If a numeric `id` is non-finite or a mapping contains duplicate keys. |

### geometry `property`

```python
geometry: FeatureG_co
```

The feature geometry.

Returns:

| Type | Description |
| --- | --- |
| `Geometry or None` | The geometry, or `None` for an unlocated feature. |

### id `property`

```python
id: FeatureId_co | None
```

The explicit feature ID.

Returns:

| Type | Description |
| --- | --- |
| `(str, int, float or None)` | The ID, or `None` when absent. |

### properties `property`

```python
properties: Mapping[str, FeatureV_co] | None
```

The feature properties.

Returns:

| Type | Description |
| --- | --- |
| `mapping or None` | Read-only values, or `None` for null properties. |

### to\_geojson

```python
to_geojson() -> str
```

Serialize this feature as an RFC 7946 GeoJSON Feature string.

Coordinate epoch metadata is not represented in GeoJSON Feature
strings; the complete Space remains on the source feature.

Returns:

| Type | Description |
| --- | --- |
| `str` | Compact RFC 7946 GeoJSON Feature JSON string. |

Raises:

| Type | Description |
| --- | --- |
| `InvalidGeometryError` | If the geometry has an M ordinate or coordinates outside WGS 84 longitude/latitude bounds. |
| `CRSError` | If a CRS-tagged geometry is not WGS 84 longitude/latitude. |
| `TypeError` | If a property value is not JSON-serializable. |

## Features

Accepted call forms

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureScalarT]
    | Iterable[Mapping[str, FeatureScalarT] | None],
    ids: ndarray[Any, dtype[integer[Any] | floating[Any]]] | None = None,
) -> Features[NewFeatureG, FeatureScalarT, str | int | float]
```

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureInput]
    | Iterable[Mapping[str, FeatureInput] | None]
    | None = None,
    ids: ndarray[Any, dtype[integer[Any] | floating[Any]]] = ...,
) -> Features[NewFeatureG, FeatureValue, str | int | float]
```

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureScalarT]
    | Iterable[Mapping[str, FeatureScalarT] | None],
    ids: Iterable[NewFeatureId | None] | None = None,
) -> Features[NewFeatureG, FeatureScalarT, NewFeatureId]
```

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureInput]
    | Iterable[Mapping[str, FeatureInput] | None]
    | None = None,
    ids: Iterable[NewFeatureId | None] | None = None,
) -> Features[NewFeatureG, FeatureValue, NewFeatureId]
```

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureScalarT]
    | Iterable[Mapping[str, FeatureScalarT] | None],
    ids: Iterable[str | int | float | integer[Any] | floating[Any] | None],
) -> Features[NewFeatureG, FeatureScalarT, str | int | float]
```

```python
Features(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    properties: Mapping[str, FeatureInput]
    | Iterable[Mapping[str, FeatureInput] | None]
    | None = None,
    ids: Iterable[str | int | float | integer[Any] | floating[Any] | None]
    | None = None,
) -> Features[NewFeatureG, FeatureValue, str | int | float]
```

Immutable, row-aligned geometries, properties and feature IDs.

Build row-aligned feature columns.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometries` | `GeometryArray[NewFeatureG] \| Iterable[NewFeatureG]` | One geometry or `None` for each input feature. | *required* |
| `properties` | `Mapping[str, FeatureScalarT] \| Iterable[Mapping[str, FeatureScalarT] \| None] \| (Mapping[str, FeatureInput] \| Iterable[Mapping[str, FeatureInput] \| None] \| None)` | A mapping or object with a callable `keys()` is snapshotted once and broadcast. An iterable supplies one mapping or `None` per geometry and is consumed once. `None` supplies null properties. | `varies by call form` |
| `ids` | `ndarray[Any, dtype[integer[Any] \| floating[Any]]] \| None \| ndarray[Any, dtype[integer[Any] \| floating[Any]]] \| (Iterable[NewFeatureId \| None] \| None) \| Iterable[str \| int \| float \| integer[Any] \| floating[Any] \| None] \| (Iterable[str \| int \| float \| integer[Any] \| floating[Any] \| None] \| None)` | One string, non-boolean integer, finite float, or `None` per geometry. `None` supplies one missing id per geometry. | `varies by call form` |

Returns:

| Type | Description |
| --- | --- |
| `Features` | The geometry, property, and id columns aligned by input row. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If a property input is not a mapping or row iterable, a property key is not a string, or an id is not a string, non-boolean integer, finite float, or `None`. |
| `GeometryError` | If property or id rows do not match the geometry count, property keys repeat, or a numeric id is not finite. |

### geometries `property`

```python
geometries: GeometryArray[FeatureG_co]
```

The geometry column.

Returns:

| Type | Description |
| --- | --- |
| `GeometryArray` | One parsed geometry or `None` per input feature. |

### ids `property`

```python
ids: Sequence[FeatureId_co | None]
```

The feature IDs.

Returns:

| Type | Description |
| --- | --- |
| `Sequence` | Row-aligned IDs, with `None` for missing IDs. |

### properties `property`

```python
properties: Sequence[Mapping[str, FeatureV_co] | None]
```

The property rows.

Returns:

| Type | Description |
| --- | --- |
| `Sequence` | Immutable row-aligned snapshots, with `None` for null properties. |

### \_\_getitem\_\_

Accepted call forms

```python
__getitem__(
    index: ndarray[tuple[()], dtype[signedinteger[Any] | unsignedinteger[Any]]],
    /,
) -> Feature[FeatureG_co, FeatureV_co, FeatureId_co]
```

```python
__getitem__(
    index: ndarray[tuple[int], dtype[signedinteger[Any] | unsignedinteger[Any]]]
    | ndarray[tuple[int], dtype[bool_]],
    /,
) -> Features[FeatureG_co, FeatureV_co, FeatureId_co]
```

```python
__getitem__(
    index: ndarray[
        tuple[int, ...], dtype[signedinteger[Any] | unsignedinteger[Any]]
    ],
    /,
) -> (
    Feature[FeatureG_co, FeatureV_co, FeatureId_co]
    | Features[FeatureG_co, FeatureV_co, FeatureId_co]
)
```

```python
__getitem__(
    index: SupportsIndex, /
) -> Feature[FeatureG_co, FeatureV_co, FeatureId_co]
```

```python
__getitem__(
    index: slice | Sequence[bool] | Sequence[SupportsIndex], /
) -> Features[FeatureG_co, FeatureV_co, FeatureId_co]
```

Select a row or select aligned rows by slice, indices or mask.

### \_\_iter\_\_

```python
__iter__() -> Iterator[Feature[FeatureG_co, FeatureV_co, FeatureId_co]]
```

Iterate feature rows in their current order.

### \_\_len\_\_

```python
__len__() -> int
```

Number of aligned feature rows.

### column

```python
column(name: str) -> Sequence[FeatureV_co | None]
```

View a property column, using `None` for missing keys and rows.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `name` | `str` | The property name. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `Sequence` | Row-aligned property values. |

### from\_columns `classmethod`

Accepted call forms

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureScalarT]],
    ids: ndarray[Any, dtype[integer[Any] | floating[Any]]],
) -> Features[NewFeatureG, FeatureScalarT, str | int | float]
```

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureInput]],
    ids: ndarray[Any, dtype[integer[Any] | floating[Any]]],
) -> Features[NewFeatureG, FeatureValue, str | int | float]
```

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureScalarT]],
    ids: Iterable[NewFeatureId | None] | None = None,
) -> Features[NewFeatureG, FeatureScalarT, NewFeatureId]
```

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureInput]],
    ids: Iterable[NewFeatureId | None] | None = None,
) -> Features[NewFeatureG, FeatureValue, NewFeatureId]
```

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureScalarT]],
    ids: Iterable[str | int | float | integer[Any] | floating[Any] | None],
) -> Features[NewFeatureG, FeatureScalarT, str | int | float]
```

```python
from_columns(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
    *,
    columns: Mapping[str, Iterable[FeatureInput]],
    ids: Iterable[str | int | float | integer[Any] | floating[Any] | None],
) -> Features[NewFeatureG, FeatureValue, str | int | float]
```

Build features from aligned named attribute columns.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometries` | `GeometryArray or iterable` | One geometry or `None` per row. | *required* |
| `columns` | `mapping` | Property names and equally sized value columns. Inputs are snapshotted so later changes cannot alter the features. Masked NumPy cells in columns and IDs become `None`. | *required* |
| `ids` | `iterable or None` | Optional row-aligned feature IDs. | `None` |

Returns:

| Type | Description |
| --- | --- |
| `Features` | The immutable, aligned feature collection. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If column names are not strings or inputs have unsupported types. |
| `GeometryError` | If any column or `ids` length mismatches `geometries`, a numeric column is not 1D, or a numeric ID is non-finite. |

### materialize

```python
materialize() -> Features[FeatureG_co, FeatureV_co, FeatureId_co]
```

Detach selected geometry and properties from their parent storage.

Returns:

| Type | Description |
| --- | --- |
| `Features` | A compact independent collection containing the selected rows. |

### select\_columns

```python
select_columns(names: Iterable[str]) -> Self
```

Return a feature collection containing the named properties.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `names` | `iterable of str` | Property names to retain. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `Features` | A new collection with the selected property columns. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If `names` is a string/bytes object or not an iterable of strings. |

### to\_arrow

```python
to_arrow(
    *,
    geometry: str | None = None,
    id_column: str | None = None,
    encoding: Literal['auto', 'wkb'] = 'auto',
) -> PyArrowTable
```

Export a feature table, normalizing absent sparse properties to null.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometry` | `str or None` | Geometry column name. `None` retains the imported name when available, otherwise uses the default name. | `None` |
| `id_column` | `str or None` | ID column name. `None` retains the existing name when available. | `None` |
| `encoding` | `('auto', 'wkb')` | Geometry encoding for the Arrow column. | `'auto'` |

Returns:

| Type | Description |
| --- | --- |
| `Table` | A geometry-bearing Arrow table with aligned properties and IDs. |

Raises:

| Type | Description |
| --- | --- |
| `ModuleNotFoundError` | If pyarrow is not installed. |
| `TypeError` | If column names are not strings or a property column cannot be converted to Arrow. |
| `GeometryError` | If `id_column` is supplied when features have no ID column, or if the geometry or ID column name conflicts with another column. |

### to\_geojson

```python
to_geojson() -> str
```

Serialize these features as an RFC 7946 GeoJSON FeatureCollection string.

Coordinate epoch metadata is not represented in GeoJSON
FeatureCollection strings; the complete Space remains on the source
features.

Returns:

| Type | Description |
| --- | --- |
| `str` | Compact RFC 7946 GeoJSON FeatureCollection JSON string. |

Raises:

| Type | Description |
| --- | --- |
| `InvalidGeometryError` | If a geometry has an M ordinate or coordinates outside WGS 84 longitude/latitude bounds. |
| `CRSError` | If a CRS-tagged geometry is not WGS 84 longitude/latitude. |
| `TypeError` | If a property value is not JSON-serializable. |

### to\_geopandas

```python
to_geopandas() -> GeoPandasDataFrame
```

Export aligned geometries, properties, and IDs as a GeoDataFrame.

Returns:

| Type | Description |
| --- | --- |
| `GeoDataFrame` | GeoDataFrame with CRS retained from the geometry array. |

Raises:

| Type | Description |
| --- | --- |
| `ModuleNotFoundError` | If geopandas is not installed. |
| `GeometryError` | If a geometry column does not have Planar Space or if column names conflict. |

### to\_geoparquet

```python
to_geoparquet(
    path: str | PathLike[str] | BinaryIO | PyArrowNativeFile,
    *,
    encoding: Literal['wkb', 'geoarrow', 'geometry'] = 'wkb',
    **kwargs: Any,
) -> None
```

Write aligned geometries, properties and IDs as GeoParquet.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `path` | `path - like or file - like` | Destination accepted by PyArrow. | *required* |
| `encoding` | `('wkb', 'geoarrow', 'geometry')` | Geometry encoding. | `'wkb'` |
| `**kwargs` | `Any` | Additional options passed to the Parquet writer. | `{}` |

Raises:

| Type | Description |
| --- | --- |
| `ModuleNotFoundError` | If pyarrow is not installed. |
| `GeometryError` | If encoding options or column names are invalid. |

### to\_pandas

```python
to_pandas(
    *, geometry: str | None = None, id_column: str | None = None
) -> PandasDataFrame
```

Export aligned geometries, properties, and IDs as a pandas DataFrame.

Geometry columns use `GeometryExtensionArray` without copying native
storage.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometry` | `str or None` | Geometry column name. `None` retains the imported name when available, otherwise uses `'geometry'`. | `None` |
| `id_column` | `str or None` | ID column name. `None` retains the existing name when available. | `None` |

Returns:

| Type | Description |
| --- | --- |
| `DataFrame` | DataFrame containing the geometry column, property columns, and optional feature ID column. |

Raises:

| Type | Description |
| --- | --- |
| `ModuleNotFoundError` | If pandas is not installed. |
| `TypeError` | If `geometry` or `id_column` is not a string or `None`. |
| `GeometryError` | If `id_column` is supplied when features have no ID column, or if the geometry or ID column name conflicts with another column. |

### to\_polars

```python
to_polars(
    *,
    geometry: str | None = None,
    id_column: str | None = None,
    srids: Mapping[int, CrsInput] | None = None,
) -> PolarsDataFrame
```

Export aligned geometries, properties, and IDs as a Polars DataFrame.

Geometry columns are encoded as binary WKB/EWKB via
`GeometryArray.to_polars`.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometry` | `str or None` | Geometry column name. `None` retains the imported name when available, otherwise uses `'geometry'`. | `None` |
| `id_column` | `str or None` | ID column name. `None` retains the existing name when available. | `None` |
| `srids` | `Mapping[int, CRS - like]` | Validate any emitted nonzero SRID in this destination namespace. A supplied mapping is exclusive; a missing identifier or CRS mismatch fails rather than falling back to EPSG or dropping the identifier. | `None` |

Returns:

| Type | Description |
| --- | --- |
| `DataFrame` | DataFrame containing WKB/EWKB geometry columns, property columns, and optional feature ID column. |

Raises:

| Type | Description |
| --- | --- |
| `ModuleNotFoundError` | If polars is not installed. |
| `TypeError` | If `geometry` or `id_column` is not a string or `None`. |
| `GeometryError` | If `id_column` is supplied when features have no ID column, if a column name conflicts, or if a selected region has no WKB form. |

### with\_columns

Accepted call forms

```python
with_columns(
    columns: Mapping[str, Iterable[FeatureScalarT]],
) -> Features[FeatureG_co, FeatureV_co | FeatureScalarT, FeatureId_co]
```

```python
with_columns(
    columns: Mapping[str, Iterable[FeatureInput]],
) -> Features[FeatureG_co, FeatureV_co | FeatureValue, FeatureId_co]
```

Add or replace aligned property columns.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `columns` | `mapping` | Property names and value columns, each with one value per row. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `Features` | A new collection with the supplied columns snapshotted. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If column names are not strings or values have unsupported types. |
| `GeometryError` | If any column length does not match the feature count or a numeric column is not 1D. |

### with\_geometries

```python
with_geometries(
    geometries: GeometryArray[NewFeatureG] | Iterable[NewFeatureG],
) -> Features[NewFeatureG, FeatureV_co, FeatureId_co]
```

Replace the geometry column while retaining aligned attributes and IDs.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `geometries` | `GeometryArray or iterable` | Replacement geometries, with the same number of rows. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `Features` | A new collection sharing the existing properties and IDs. |

Raises:

| Type | Description |
| --- | --- |
| `GeometryError` | If `geometries` length does not match the feature count. |

### with\_ids

Accepted call forms

```python
with_ids(
    ids: ndarray[Any, dtype[integer[Any] | floating[Any]]],
) -> Features[FeatureG_co, FeatureV_co, str | int | float]
```

```python
with_ids(
    ids: Iterable[NewFeatureId | None] | None,
) -> Features[FeatureG_co, FeatureV_co, NewFeatureId]
```

```python
with_ids(
    ids: Iterable[str | int | float | integer[Any] | floating[Any] | None],
) -> Features[FeatureG_co, FeatureV_co, str | int | float]
```

Replace the feature IDs while retaining geometry and properties.

Parameters:

| Name | Type | Description | Default |
| --- | --- | --- | --- |
| `ids` | `iterable or None` | One ID or `None` per row, or `None` to clear all IDs. | *required* |

Returns:

| Type | Description |
| --- | --- |
| `Features` | A new collection with the replacement IDs. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If `ids` has an unsupported type or contains invalid ID values. |
| `GeometryError` | If `ids` length does not match the feature count or a numeric ID is non-finite. |

## ArrowValue

An immutable Arrow-backed property value.

Values retain their Arrow type and can be converted to a Python value or
detached from the parent Arrow storage.

### type `property`

```python
type: str
```

The Arrow data type.

Returns:

| Type | Description |
| --- | --- |
| `str` | The Arrow data type as a string. |

### value `property`

```python
value: int
```

The integer value of a temporal Arrow scalar.

Returns:

| Type | Description |
| --- | --- |
| `int` | The value in the Arrow type's native units. |

Raises:

| Type | Description |
| --- | --- |
| `TypeError` | If the Arrow value is not temporal. |

### as\_py

```python
as_py() -> Any
```

Convert this value to its Python representation.

Returns:

| Type | Description |
| --- | --- |
| `object` | The converted value. |

### materialize

```python
materialize() -> ArrowValue
```

Detach this value from its parent Arrow storage.

Returns:

| Type | Description |
| --- | --- |
| `ArrowValue` | An independently owned value with the same Arrow type. |
