SPARQL to GeoJSON¶
app.sparql_to_geojson_translator
¶
Decode SPARQL instance rows into a GeoJSON FeatureCollection.
extract_property(shape, instance)
¶
Decode one EntityShape value from a SPARQL result row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
shape
|
EntityShape
|
Property descriptor describing how the row was projected. |
required |
instance
|
dict[str, Any]
|
One SPARQL result row as a dict. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Decoded value: IRI/label dict(s), bool, list of strings, or a scalar. |
Source code in src/backend/app/sparql_to_geojson_translator.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
_parse_coordinates(instance)
¶
Build a GeoJSON Point from lat/long bindings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instance
|
dict[str, Any]
|
SPARQL result row. |
required |
Returns:
| Type | Description |
|---|---|
Point | None
|
|
Source code in src/backend/app/sparql_to_geojson_translator.py
52 53 54 55 56 57 58 59 60 61 62 63 64 | |
instances_to_geojson(instances, shapes, lang='en')
¶
Build one Feature per SPARQL instance, decoded via EntityShape descriptors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
list[dict[str, Any]]
|
SPARQL result rows from |
required |
shapes
|
list[EntityShape]
|
Descriptors used to decode property columns. |
required |
lang
|
str
|
UI language for the stories URL. |
'en'
|
Returns:
| Type | Description |
|---|---|
FeatureCollection
|
GeoJSON FeatureCollection, one Point feature per pin. A row without |
FeatureCollection
|
usable coordinates is logged and skipped. |
Source code in src/backend/app/sparql_to_geojson_translator.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |