0

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?

TimTom
  • 1

2 Answers2

1

Use GeoDataFrame.to_crs

gpf.to_crs('EPSG:4326')
pyaj
  • 545
  • 5
  • 15
  • Do gdal.polygonize() can transfer CRS without setting with your solution? Maybe I did something wrong in polygozing? – TimTom Mar 29 '22 at 11:22
0

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)
Zev_Zide
  • 3
  • 2