I'm trying to create a shapefile layer based on the spatial projection of an already existing raster. (Ultimately, this will be used in gdal.Polygonize to get a shape from my raster data.) However, I am encountering an error when trying to use CreateLayer.
- raster_uri- location of the raster file that I want to make into a shapefile. I know this exists.
- out_uri- Location I want the new shapefile to print to.
- layer_name- String layer name input.
- filed_name- String field name input.
This is the code that I was using.
raster = gdal.Open(raster_uri) driver = ogr.GetDriverByName("ESRI Shapefile") ds = driver.CreateDataSource(out_uri) spat_ref = osr.SpatialReference() proj = raster.GetProjectionRef() spat_ref.InportFromWkt(proj) layer = ds.CreateLayer(layer_name, spat_ref, ogr.wkbPolygon)
It yields this error message:
TypeError: in method 'DataSource_CreateLayer', argument 2 of type 'char const *'
Outputing the type of spat_ref shows up as
<class 'osgeo.osr.SpatialReference'> so I'm unsure what char const * it's complaining about.
Interestingly, if I try to do this all from a python shell using the same file, layer creates just fine. Any ideas on what might be the issue?