Skip to content

Example documentation in open_rasterio #5005

Closed
@gabriel-abrahao

Description

@gabriel-abrahao

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions