corteva / rioxarray

geospatial xarray extension powered by rasterio
https://corteva.github.io/rioxarray
Other
518 stars 82 forks source link

Transform assignation is different? #546

Closed RichardScottOZ closed 2 years ago

RichardScottOZ commented 2 years ago

Code Sample, a copy-pastable example if possible

Generally I fix this with rasterio, thought I would have a look here:-

# Your code here
dtm = rioxarray.open_rasterio(r'F:\Depth Modelling\Features008_200\dtm_SA_200_3107.tif')
dtm.rio.transform()

Affine(200.0, 0.0, 339300.0,
       0.0, -200.0, 2732900.0)

dtb= rioxarray.open_rasterio(r'F:\Depth Modelling\dtb.tif')
dtb.rio.transform()

Affine(200.0, 0.0, 339300.0,
       0.0, 200.0, 1209900.0)

newtransform = dtm.rio.transform()

dtb.rio.write_transform(newtransform,inplace=True)
dtb.rio.transform()

Affine(200.0, 0.0, 339300.0,
       0.0, -200.0, 1210100.0)

Problem description

New transform is not quite right?.

Expected Output

Affine(200.0, 0.0, 339300.0,
       0.0, -200.0, 2732900.0)

presumably this is some affine handling would have to do differently - as updating rasterio metadata directly just assign a new transform tuple to the dictionary

Environment Information

Installation method

Conda environment information (if you installed with conda):


Environment (conda list):

``` $ conda list | grep -E "rasterio|xarray|gdal" ![image](https://user-images.githubusercontent.com/72196131/178165021-c61ae467-abf4-4e4a-82a9-a3b7d349d6b1.png) ```
RichardScottOZ commented 2 years ago

e.g. flipping data, bounds, affine elements, access to/updating etc.

snowman2 commented 2 years ago

The different value in the transform has to do with the coordinates loaded in from the original raster. Since rasters can be sliced and subsets extracted from the raster, the value of the transform is calculated from the ooordinates and not from the transform alone.

If you want the transform to be the same in the second raster, you also have to copy over the coordinates of the original raster.

RichardScottOZ commented 2 years ago

Thanks Alan, figured it was something along those lines - stuck in a meeting before I could do some more tests.

RichardScottOZ commented 2 years ago

image