This is my first time submitting an issue, so sorry if doing this wrong.
In the documentation for open_rasterio there's an example on how to generate 2D coordinates from a GeoTiff file using it:
|
from affine import Affine |
|
da = xr.open_rasterio('path_to_file.tif') |
|
transform = Affine.from_gdal(*da.attrs['transform']) |
|
nx, ny = da.sizes['x'], da.sizes['y'] |
|
x, y = np.meshgrid(np.arange(nx)+0.5, np.arange(ny)+0.5) * transform |
However, this method does not really work because the da.attrs['transform'] attribute is not coded in the GDAL standard, but as affine.Affine expects directly (maybe it wasn't so in a previous version. So, at least for me (v0.16.2), getting the affine transformation right is done by simply replacing that line with the simpler:
transform = Affine(*da.attrs['transform'])
Again, sorry if this is not how this should be done, I just took a while to figure this out for my application and thought other people might benefit from it. If I can do something to fix it (if it's really broken) please let me know.
This is my first time submitting an issue, so sorry if doing this wrong.
In the documentation for open_rasterio there's an example on how to generate 2D coordinates from a GeoTiff file using it:
xarray/xarray/backends/rasterio_.py
Lines 177 to 181 in 37522e9
However, this method does not really work because the
da.attrs['transform']attribute is not coded in the GDAL standard, but asaffine.Affineexpects directly (maybe it wasn't so in a previous version. So, at least for me (v0.16.2), getting the affine transformation right is done by simply replacing that line with the simpler:transform = Affine(*da.attrs['transform'])Again, sorry if this is not how this should be done, I just took a while to figure this out for my application and thought other people might benefit from it. If I can do something to fix it (if it's really broken) please let me know.