Skip to main content
6 of 8
added 510 characters in body
user2856
  • 69.6k
  • 6
  • 119
  • 203

You pass the geojson string directly to the ogr Open/gdal OpenEx function.

In python it's just:

#gdal 1.x
ds = ogr.Open('some geojson string')

or

#gdal 2.x
ds = gdal.OpenEx('some geojson string')

An example to demonstrate:

from osgeo import gdal

geojson = '{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[146.7,-41.9]}}]}'
ds = gdal.OpenEx(geojson)
layer = ds.GetLayer()
feature = layer.GetFeature(0)
feature.GetGeometryRef().ExportToWkt()

print(ds.GetDriver().ShortName)
print(feature.GetGeometryRef().ExportToWkt())

Output:

GeoJSON
POINT (146.7 -41.9)
user2856
  • 69.6k
  • 6
  • 119
  • 203