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

# Features & attributes

Use [`Features`](https://gometry.monicz.dev/api/features/#gometry.Features "Features") when each geometry has properties or an ID.
It keeps those values aligned as you select and transform rows.

```python
import gometry as gm

places = gm.Features(
    gm.points([1, 2, 3], [4, 5, 6], space=gm.Space(crs=4326)),
    properties=[
        {"name": "A", "rank": 2},
        {"name": "B", "rank": 1},
        {"name": "C", "rank": 3},
    ],
    ids=[10, 11, 12],
)

selected = places[[2, 0]]
print(list(selected.column("name")))
print(list(selected.ids))
```

```text
['C', 'A']
[12, 10]
```

Integer indexing returns a [`Feature`](https://gometry.monicz.dev/api/features/#gometry.Feature "Feature") row. Slices, integer
selections, and boolean masks return [`Features`](https://gometry.monicz.dev/api/features/#gometry.Features "Features"), carrying
the corresponding [`properties`](https://gometry.monicz.dev/api/features/#gometry.Features.properties "properties property") and
[`ids`](https://gometry.monicz.dev/api/features/#gometry.Features.ids "ids property") with the [`geometries`](https://gometry.monicz.dev/api/features/#gometry.Features.geometries "geometries property").

## Filter and update

Compute a mask from the [`GeometryArray`](https://gometry.monicz.dev/api/geometry-array/#gometry.GeometryArray "GeometryArray") with a free
predicate such as [`gm.intersects`](https://gometry.monicz.dev/api/predicates/#gometry.intersects "intersects"), then apply it to the
feature snapshot:

```python
import gometry as gm

places = gm.Features(
    gm.points([1, 2, 3], [4, 5, 6], space=gm.Space(crs=4326)),
    properties=[{"name": "A"}, {"name": "B"}, {"name": "C"}],
)
area = gm.box(0, 0, 2, 5, space=gm.Space(crs=4326))
nearby = places[gm.intersects(places.geometries, area)]
print(list(nearby.column("name")))
```

```text
['A', 'B']
```

Snapshots are immutable. Use [`with_geometries`](https://gometry.monicz.dev/api/features/#gometry.Features.with_geometries "with_geometries"),
[`with_columns`](https://gometry.monicz.dev/api/features/#gometry.Features.with_columns "with_columns"), or
[`with_ids`](https://gometry.monicz.dev/api/features/#gometry.Features.with_ids "with_ids") to create a replacement, and
[`select_columns`](https://gometry.monicz.dev/api/features/#gometry.Features.select_columns "select_columns") to choose properties.
Unchanged data can be shared with the original.

```python
import gometry as gm

places = gm.Features(
    gm.points([1, 2], [4, 5]),
    properties=[{"name": "A"}, {"name": "B"}],
)
ranked = places.with_columns({"rank": [2, 1]})
print(list(ranked.column("rank")))
```

```text
[2, 1]
```

Selections can keep their parent storage alive. Call
[`materialize()`](https://gometry.monicz.dev/api/features/#gometry.Features.materialize "materialize") when a small selection should
own compact storage instead.

## Exchange features

- [GeoJSON](https://gometry.monicz.dev/ecosystem/text-formats/#__geo_interface__) reads features with
  [`gm.from_geojson`](https://gometry.monicz.dev/api/io/#gometry.from_geojson "from_geojson") and writes them with
  [`Feature.to_geojson()`](https://gometry.monicz.dev/api/features/#gometry.Feature.to_geojson "to_geojson"),
  [`Features.to_geojson()`](https://gometry.monicz.dev/api/features/#gometry.Features.to_geojson "to_geojson"), or `__geo_interface__`.
- [Arrow & GeoParquet](https://gometry.monicz.dev/ecosystem/arrow/#feature-tables) exchange typed
  columns through [`Features.to_arrow`](https://gometry.monicz.dev/api/features/#gometry.Features.to_arrow "to_arrow"),
  [`Features.to_geoparquet`](https://gometry.monicz.dev/api/features/#gometry.Features.to_geoparquet "to_geoparquet"),
  [`gm.from_arrow`](https://gometry.monicz.dev/api/io/#gometry.from_arrow "from_arrow"), and
  [`gm.from_geoparquet`](https://gometry.monicz.dev/api/interop/#gometry.from_geoparquet "from_geoparquet") while preserving the declared
  ID role.
- [DataFrames](https://gometry.monicz.dev/ecosystem/dataframes/) convert `Features` directly to
  [pandas](https://pandas.pydata.org/) via
  [`Features.to_pandas`](https://gometry.monicz.dev/api/features/#gometry.Features.to_pandas "to_pandas"),
  [Polars](https://pola.rs/) via
  [`Features.to_polars`](https://gometry.monicz.dev/api/features/#gometry.Features.to_polars "to_polars"), and
  [GeoPandas](https://geopandas.org/) via
  [`Features.to_geopandas`](https://gometry.monicz.dev/api/features/#gometry.Features.to_geopandas "to_geopandas") /
  [`gm.from_geopandas`](https://gometry.monicz.dev/api/interop/#gometry.from_geopandas "from_geopandas").
- [Mapbox Vector Tiles](https://gometry.monicz.dev/ecosystem/vector-tiles/) prepare `Features` for
  rendering as tiles with [`gm.mvt_prepare`](https://gometry.monicz.dev/api/vector-tiles/#gometry.mvt_prepare "mvt_prepare") and
  [`gm.to_mvt`](https://gometry.monicz.dev/api/vector-tiles/#gometry.to_mvt "to_mvt").
