I'm using the GDAL .Net library to open a PBF file I've downloaded from the GeoFabrik website. The file opens fine in QGIS.

However when I call the Gdal.Open method on the file, it throws an exception stating:

System.ApplicationException: '`south-africa-and-lesotho-latest.osm.pbf' not recognized as a supported file format.'

My code:


var data = Gdal.Open("C:/south-africa-and-lesotho-latest.osm.pbf", OSGeo.GDAL.Access.GA_ReadOnly);

I find this weird since, when the ConfigureGdal method is called, it prints out a list of drivers to the output window, one of them being OSM PBF:

GDAL 180: PGDUMP-PostgreSQL SQL dump

GDAL 181: OSM-OpenStreetMap XML and PBF

GDAL 182: GPSBabel-GPSBabel

I've made some changes to the GdalConfiguration class that gets created when installing the GDAL Nuget package. These changes include adjusting the directories to set the correct gdal data and driver directory, as well as setting the osminfo.ini config file.

The problem is, I don't actually know what those directories should contain to know for certain I've chosen the right ones.

  • Pretty sure there's an OGR namespace you should use instead; the OpenGIS Simple Feature Reference implementation holds the GDAL vector processing tools. – geozelot Jan 9 '20 at 9:48
  • Ah... yep, I believe that was it, I switched to OSGeo.OGR.Ogr.Open("C:/south-africa-and-lesotho-latest.osm.pbf", 0); and it now loads fine. Thanks for the help, you can go ahead and add it as an answer and I'll mark it as correct. – Walter Jan 9 '20 at 10:07

While I'm not familiar with the C#/.NET bindings for GDAL, the library usually divides raster and vector functionality in different namespaces:

  • GDAL (Geospatial Data Abstraction Library) for raster data
  • OGR (OpenGIS Simple Feature Reference) for vector data

I assume you need to use the appropriate Open function within the OGR namespace, as you confirmed in the comments.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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