Skip to content

Instantly share code, notes, and snippets.

@ThomasG77
Last active April 4, 2021 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasG77/c4a8fcc25bf7f635562d8367e2a3a660 to your computer and use it in GitHub Desktop.
Save ThomasG77/c4a8fcc25bf7f635562d8367e2a3a660 to your computer and use it in GitHub Desktop.

Read nested element from GeoJSON and GDAL SQLite dialect

ogrinfo -dialect SQlite -sql "SELECT a_property, json_extract(some_object, '$.another_property') AS another_property, json_extract(some_object, '$.last_prop[1]') AS subarrayelement, geometry FROM demo" /tmp/demo.geojson

We use functions presented at https://www.sqlite.org/json1.html to manipulate JSON in SQLite

Display the source blob
Display the rendered blob
Raw
{
"type": "FeatureCollection",
"features":
[
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ 2, 49 ]
},
"properties": {
"a_property": "foo",
"some_object": {
"a_property": 1,
"another_property": 2,
"last_prop": [35, 67]
}
}
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment