Skip to content

Features & attributes

Use Features when each geometry has properties or an ID. It keeps those values aligned as you select and transform rows.

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))
['C', 'A']
[12, 10]

Integer indexing returns a Feature row. Slices, integer selections, and boolean masks return Features, carrying the corresponding properties and ids with the geometries.

Filter and update

Compute a mask from the GeometryArray with a free predicate such as gm.intersects, then apply it to the feature snapshot:

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")))
['A', 'B']

Snapshots are immutable. Use with_geometries, with_columns, or with_ids to create a replacement, and select_columns to choose properties. Unchanged data can be shared with the original.

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")))
[2, 1]

Selections can keep their parent storage alive. Call materialize() when a small selection should own compact storage instead.

Exchange features