1

I'm trying to reproject a raster dataset using a user-defined projection in Python. I was able to achieve the desired reprojection setting ArcGIS's arcpy.CreateCustomGeoTransformation_management tool and arcpy.ProjectRaster_management method.

However, I have difficulties in replicating the exact results using rasterio or rioxarray. Can anyone offer guidance on how to achieve this reprojection using these libraries?

I have also tried using the default_transformation in rasterio https://rasterio.readthedocs.io/en/stable/topics/reproject.html

from pyproj.transformer import Transformer
import pycrs
import rioxarray as rxr
from rasterio.enums import Resampling

prj = pycrs.load.from_file('projection_file.prj')
dst_crs = prj.to_proj4()
ds_crs
'+proj=laea +a=6378137.0 +f=0.0 +pm=0 +x_0=0.0 +y_0=0.0 +lon_0=20.0 +lat_0=5.0 +units=m +axis=enu +no_defs'
rain = rxr.open_rasterio('rain_20011.bil').squeeze()
rain_projected = rain.rio.reproject(dst_crs, resampling=Resampling.nearest)
# how can I include the transformation information in the reprojection? 
transform = Transformer.from_crs("EPSG:4326",dst_crs)

1 Answer 1

0

Does it work if you pass in the COORDINATE_OPERATION used under the hood by reproject GDALCreateGenImgProjTransformer2?

import pycrs
import rioxarray as rxr
from rasterio.enums import Resampling
prj = pycrs.load.from_file('projection_file.prj')
dst_crs=prj.to_proj4()
rain = rioxarray.open_rasterio('rain_20011.bil').squeeze()
rain.rio.write_crs("ESPG:4326", inplace=True)
transform = Transformer.from_crs("EPSG:4326",dst_crs)
rain_projected = rain.rio.reproject(
    dst_crs,
    resampling=Resampling.nearest,
    COORDINATE_OPERATION=transform.to_wkt(),  # can also use to_proj4()
)
5
  • I tried it and it didn't work out.
    – Liyuneh
    Commented Apr 18 at 20:02
  • What was the issue?
    – snowman2
    Commented Apr 19 at 3:45
  • there is no issue in execution though the output is different from arcpy projection result. I can share the input and the output from arcpy.
    – Liyuneh
    Commented Apr 19 at 6:10
  • Do you have the coordinate operation string arcpy used?
    – snowman2
    Commented Apr 19 at 12:26
  • here is the coordinate string: '+proj=laea +lat_0=5 +lon_0=20 +x_0=0 +y_0=0 +R=6378137 +units=m +no_defs +type=crs'. POSITIVE UPDATE When reading crs with pyproj is yielding approximate outcomes rather than with pycrs. prj=pyproj.CRS.from_string('+proj=laea +lat_0=5 +lon_0=20 +x_0=0 +y_0=0 +a=6378137 +units=m +no_defs ') Despite using identical resampling methods and output shape as in arcPy, there are still variations in some pixel values. What could be causing these differences, and how can I ensure consistent results?
    – Liyuneh
    Commented Aug 23 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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