Skip to content

Quickstart

Find which blocks intersect a station's 500-meter radius, then cover the area with H3 cells. Requires CPython 3.11 or newer — see Installation to install gometry (uv add gometry or pip install gometry).

1. Create a station

Create a Point in WGS 84 (EPSG:4326) with a Chart Space:

import gometry as gm

geographic = gm.Space(crs=4326, model="chart")
station = gm.Point(2.2945, 48.8584, space=geographic)
print(station)
POINT (2.2945 48.8584)

2. Buffer by 500 meters

On a geographic CRS, buffer(500) uses a physical radial distance of 500 meters rather than 500 degrees (on Planar values, metric='cartesian' selects coordinate-plane distance instead):

service_area = station.buffer(500)
print("service area m²:", round(service_area.area))
service area m²: 783767

3. Load GeoJSON features

gm.from_geojson(...) parses a GeoJSON FeatureCollection into an immutable Features snapshot with aligned geometries and properties, then with_space assigns the Chart model without moving coordinates:

payload = '''
{"type":"FeatureCollection","features":[
  {"type":"Feature","id":"champ-edge","properties":{"name":"Champ-de-Mars edge"},
   "geometry":{"type":"Polygon","coordinates":[[[2.290,48.855],[2.296,48.855],[2.296,48.858],[2.290,48.858],[2.290,48.855]]]}},
  {"type":"Feature","id":"trocadero-side","properties":{"name":"Trocadero side"},
   "geometry":{"type":"Polygon","coordinates":[[[2.287,48.860],[2.293,48.860],[2.293,48.864],[2.287,48.864],[2.287,48.860]]]}},
  {"type":"Feature","id":"out-of-range","properties":{"name":"Out-of-range block"},
   "geometry":{"type":"Polygon","coordinates":[[[2.305,48.865],[2.311,48.865],[2.311,48.870],[2.305,48.870],[2.305,48.865]]]}}
]}
'''
geojson_space = gm.Space(crs=4326, model="planar")
features = gm.from_geojson(payload, space=geojson_space)
blocks = features.geometries.with_space(geographic)
properties = features.properties
names = [row["name"] for row in properties]
print(len(blocks), "blocks loaded:", names)
3 blocks loaded: ['Champ-de-Mars edge', 'Trocadero side', 'Out-of-range block']
The station, its 500 m service area, and the three blocks.
A station anchors a 500 m service area drawn over three nearby polygon blocks.
  • input
  • query
  • anchor

4. Query with SpatialIndex

Build a SpatialIndex over the blocks and query with predicate='intersects'. query runs a bounding-box prefilter followed by exact refinement (use candidates for prefilter row indices only):

idx = gm.SpatialIndex(blocks)
reachable = idx.query(service_area, predicate="intersects")
print("rows intersecting:", reachable.tolist(), "| matched:", [names[i] for i in reachable])
rows intersecting: [0, 1] | matched: ['Champ-de-Mars edge', 'Trocadero side']
Two blocks intersect the service area; the third is out of range.
The query returns the two intersecting blocks and excludes the out-of-range block.
  • query
  • result
  • excluded
  • anchor

5. Cover the service area with H3 cells

gm.h3_cover returns H3 candidate keys for joining or binning; exact membership still uses the source geometry with gm.covers:

cells = gm.h3_cover(service_area, resolution=10)
print("H3 cells:", len(cells), "| source covers station:", gm.covers(service_area, station))
H3 cells: 76 | source covers station: True
H3 cells cover the service area; the geometry still decides membership.
H3 cells extend past the source service area, so exact membership uses the source geometry.
  • candidates
  • input
  • anchor

Next: read The mental model, browse the User guide (including Curves & surfaces and PostgreSQL & PostGIS), or look up symbols in the API reference.