Reads an RDF Turtle topology model (geojson-topo vocabulary) and returns a dict of GeoJSON geometry objects for every feature, indexed by both full URI string and qname (prefix:local).
pip install topo-rdf-geojsonfrom topo_rdf_geojson import load_topo
geometries = load_topo("path/to/model.ttl")
# index by full URI
geom = geometries["http://csdm-example-surveys/DP-572532/8446454"]
# index by qname when a matching prefix is declared
geom = geometries["eg2:8446454"]
print(geom)
# {"type": "Polygon", "coordinates": [[[lon, lat], ...]]}topo-rdf-geojson <source.ttl> [--key URI_OR_QNAME] [--keys-only] [--indent N]| Option | Description |
|---|---|
--key |
Return geometry for a single feature (URI or qname) |
--keys-only |
Print only the index keys |
--indent N |
JSON indent level (default 2) |
| RDF type | GeoJSON output |
|---|---|
Point / geojson:geometry |
Point |
Edge / geojson:LineString |
LineString |
| Ring | Polygon (single ring) |
| Face | Polygon (multiple rings) |
| Shell | MultiPolygon |
| Solid | MultiPolygon (union of all faces) |
geojson:Polygon |
Polygon (edges auto-chained by adjacency) |
Multiple geojson:topology triples on the same feature are merged: all LineStrings → MultiLineString, all Polygons → MultiPolygon, mixed → GeometryCollection.
- rdflib >= 6.0