1

I want to convert all lines from a .osm-File to a geojson with the gdal Python API.
My Code so far:

from osgeo import gdal
from osgeo import ogr

gdal.UseExceptions()

srcds = gdal.OpenEx("infile.osm")
gdaloptions = gdal.VectorTranslateOptions(format="GEOJSON", layers = ["lines"])

ds = gdal.VectorTranslate("outfile.geojson", srcds, options=gdaloptions)

This returns a lot of erros like: ERROR 1: Non increasing node id. Use OSM_USE_CUSTOM_INDEXING=NO

According to the Documenation of VectorTranslateOptions() I changed gdaloptions to:

gdaloptions = gdal.VectorTranslateOptions(options=['OSM_USE_CUSTOM_INDEXING=NO'],
                                          format="GEOJSON",
                                          layers = ["lines"])

But this returns an other error: Couldn't fetch requested layer OSM_USE_CUSTOM_INDEXING=NO!

How do I set this "Open Options" of the osm-Format within the VectorTranslateOptions?

1 Answer 1

1

It is also possible to set OSM_USE_CUSTOM_INDEXING as a config option https://gdal.org/drivers/vector/osm.html#internal-working-and-performance-tweaking

Usage:

gdal.SetConfigOption("USE_CUSTOM_INDEXING", "NO")

With open options this should work:

ds = gdal.OpenEx(
        "file.osm",
        open_options=["OSM_USE_CUSTOM_INDEXING=NO"],
2
  • 1
    gdal.SetConfigOption("OSM_USE_CUSTOM_INDEXING", "NO") works great! But ds = gdal.OpenEx("file.osm",open_options=["OSM_USE_CUSTOM_INDEXING=NO"]) doesn't -> Warning 6: driver OSM does not support open option OSM_USE_CUSTOM_INDEXING Commented Feb 7, 2023 at 13:25
  • Closer look at the documentation gdal.org/drivers/vector/osm.html#open-options reveals that the name of the open option is shortened to USE_CUSTOM_INDEXING. I will edit the answer.
    – user30184
    Commented Feb 8, 2023 at 7:43

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.