TimTom
TimTom

Reputation: 11

Set CRS to shapefile

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

Answers (2)

Zev_Zide
Zev_Zide

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

pyaj
pyaj

Reputation: 640

Use GeoDataFrame.to_crs

gpf.to_crs('EPSG:4326')

Upvotes: 2

Related Questions