Reputation: 11
Good afternoon,
I have a question: how to set CRS to shapefile in python?
Using gdal.Polygonize(), I converted raster to vector (shapefile) and then I put it in QGIS, shapefile is without CRS.
how to set CRS to shapefile in python?
Upvotes: 1
Views: 941
Reputation: 3
Assuming you are creating a shapefile with ogr where you store your data from the gdal.Polygonize()-process, you can set your crs while initializing it.
srs=osr.SpatialReference()
srs.ImportFromEPSG(21781)
driver = ogr.GetDriverByName('ESRI Shapefile')
output_file = os.path.join(out_path, v_out)
out_data_source = driver.CreateDataSource(output_file)
out_layer = out_data_source.CreateLayer(output_file.split('.')[0], srs, geom_type=ogr.wkbPolygon)
Upvotes: 0