I’ve been using GDAL with python to manipulate shapefiles. When opening a source file I first set the driver to “ESRI Shapefile” before calling the driver’s "Open" method with the required shapefile.

I have had no issues with this; however I am curious what the difference is between the Driver instance method “Open” and the ogr function “Open”. For example, what is the difference between:

driver = ogr.GetDriverByName("ESRI Shapefile")
source = driver.Open(“O:\myshp.shp”,0)


source = ogr.Open(“O:\myshp.shp”,0)

Is there a particular scenario where you would use one over the other?

  • Followup question: it seems like driver = gdal.GetDriverByName works, and gdal.Open works, but driver.Open doesn't. Is there no equivalent for raster files? I know GDAL and OGR were originally developed by different people, but these API inconsistencies and utter lack of documentation are really painful... Commented Jul 13, 2018 at 20:05

1 Answer 1


If you specify a driver, OGR will only try to open your file with the specified driver.

If you don't specify it, OGR will try to open your file with all the drivers. It will loop over all the drivers until it finds a driver with that it can open your file. The order it tries to open them is the same order as listed in ogrinfo --formats.

See also this question: Force OGR to use specific driver for input format


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.