0

I am trying to reproject a polygon so that it has the same projection than a raster dataset.

raster.crs
CRS({'proj': 'tmerc', 'lat_0': 0, 'lon_0': -183, 'k': 0.9996, 'x_0': 500000, 'y_0': 0, 'datum': 'WGS84', 'units': 'm', 'no_defs': True})

polygon.crs
{'init': 'epsg:3035', 'no_defs': True}

I believe I should be using an instruction like the one below:

polygon = polygon.to_crs(epsg=XXXX) 

where XXXX is the epsg code that tells the coordinate system of the raster dataset. However, I don't know hot to obtain such code. (I know that the epsg code of WGS84 is 4326, but I would like to know how to obtain this number programmatically)

  • It has been answered here: gis.stackexchange.com/questions/267321/… – pan Jul 16 at 18:28
  • That link provides an answer using ogr. Is there any way of doing it by using the method 'crs'? – Pitrako Junior Jul 16 at 19:21
  • 1
    Show how you create raster – BERA Jul 16 at 19:35
  • It's a .tif file that I open with rasterio - fp = r'C:\...................\file_name.tif' - raster = rasterio.open(fp) – Pitrako Junior Jul 16 at 21:10
1

The epsg code is only one way to reproject the dataset, but is not the only way. As mentioned here you can also use PROJ strings or dictionaries. You can use the to_dict() method of the rasterio CRS class.

In your use case, you can reproject your geopandas dataframe like so:

polygon = polygon.to_crs(raster.crs.to_dict()) 

In future versions of geopandas, you will be able to pass in the raster.crs directly to the to_crs() function. This will occur after this PR is merged (https://github.com/geopandas/geopandas/pull/998).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.