Search code examples
pythongdalogr

Type error: reading ESRI shapefile driver using OGR/GDAL in Python


I'm trying to use gdal_polygonize within Python to convert a raster to a shapefile using the following code:

# define output shapefile
driver_name = "ESRI Shapefile"
drv = ogr.GetDriverByName(driver_name)
dst_ds = drv.CreateDataSource(DataDirectory+OutputShapefile)
dst_layer = dst_ds.CreateLayer(DataDirectory+dst_layername, srs = Projection)

However I keep getting the following error when reading in the driver by name:

File "/home/s0923330/miniconda2/lib/python2.7/site-packages/osgeo/ogr.py", line 7262, in GetDriverByName
    return _ogr.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'

The raster that I'm reading in is perfectly fine, and I can open it with gdal from the command line with no problems. It just seems to be a problem with OGR and Python. I was wondering if anybody has come across this problem before? It's GDAL version 2.1.0.

Thank you in advance!


Solution

  • I solved this problem by commented line in my code (or just remove):

    # from __future__ import unicode_literals