I have a GeoJSON file, example.geojson
:
{
"type": "FeatureCollection",
"name": "example",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -21.987, 64.208 ] } },
{ "type": "Feature", "properties": { }, "geometry": { "type": "Point", "coordinates": [ -21.012, 65.123 ] } }
]
}
I would like to add a Foreign Member to each feature. Foreign Members are described in Section 6.1 of the RFC7946 specification. I can achieve this via jq
:
jq '.features |= map(. + {"foreign-key": "foreign-value"})' example.geojson > with_foreign_member.geojson
Result:
{
"type": "FeatureCollection",
"name": "example",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:OGC:1.3:CRS84"
}
},
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-21.987,
64.208
]
},
"foreign-key": "foreign-value"
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Point",
"coordinates": [
-21.012,
65.123
]
},
"foreign-key": "foreign-value"
}
]
}
The problem with this approach is that it does not work for large GeoJSONs, my jq
command gets Killed
. I generate the large GeoJSON file using ogr2ogr
, so it would be nice if I could write the Foreign Members too, when I generate the file.
How can I write Foreign Members to GeoJSON files using ogr2ogr
?