Skip to content

Instantly share code, notes, and snippets.

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 dbazile/3d5c2d16d04305dc159ebbab42cbb2c4 to your computer and use it in GitHub Desktop.
Save dbazile/3d5c2d16d04305dc159ebbab42cbb2c4 to your computer and use it in GitHub Desktop.
SELECT ST_AsText(ST_GeomFromGeoJSON(fc.features->>'geometry')) AS geometry,
row_number() OVER () AS feature_id
FROM (SELECT json_array_elements('{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
},
{
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": [
[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [105.0, 1.0]
]
},
"properties": {
"prop0": "value0",
"prop1": 0.0
}
}
]
}'::json->'features') AS features) fc;
geometry feature_id
POINT(102 0.5) 1
LINESTRING(102 0,103 1,104 0,105 1) 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment