3

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?

1 Answer 1

5

Will be available in GDAL 3.9 per https://github.com/OSGeo/gdal/pull/8830

ogr2ogr out.json in.whatever -lco "FOREIGN_MEMBERS_FEATURE={\"foreign-key\": \"foreign-value\"}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.