Search code examples
juliageojsongdal

Convert GeoJSON to ArchGDAL geometry


When I attempt to convert a GeoJSON to an ArchGDAL geometry like seen below, I end up with a NULL Geometry. How would one convert a String GeoJSON notation to a geometry object?

using ArchGDAL

test = """{ "type": "FeatureCollection",
  "features": [
    { "type": "Feature",
      "geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
      "properties": {"prop0": "value0"}
    }
  ]
}"""

ArchGDAL.fromJSON(test)
# NULL Geometry

Solution

  • Turns out the GeoJSON can be read by simply using ArchGDAL.read(), (and, in this example extracting the first layer using ArchGDAL.getlayer())

    ArchGDAL.getlayer(ArchGDAL.read(test), 0)
    # Layer: OGRGeoJSON
    #   Geometry 0 (): [wkbPoint], POINT (102.0 0.5)
    #      Field 0 (prop0): [OFTString], value0