I load a GeoJSON with OGR and apply the method GetLayerCount(). How must the GeoJSON look like that GetLayerCount() > 1?

driver = ogr.GetDriverByName("GeoJSON")
dataset = driver.Open(my.geojson, 0)
# should be 2 or higher
number_of_layers = dataset.GetLayerCount()

Unfortunately a FeatureCollection with Features of different Geometry Types does not lead to the desired result.

  • 1
    Perhaps your real problem is that you have one layer that contains different geometry types (points, lines, polygons) and you can't convert such data into some format that is more limited with this aspect, like shapefiles? That GDAL converts GeoJSON to one layer is documented gdal.org/drv_geojson.html A GeoJSON datasource is translated to single OGRLayer object. – user30184 Feb 3 at 21:00

I don't think there is any way in geojson to have more than one layer. You would need to split the file up into multiple files to achieve this effect.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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