Help with rasterio.transfrom.xy
The problem we are encountering is that rasterio.transform.xy is not returning the coordinates in lat/long but rather in their native projection. We think this is caused by using the incorrect transform (Affine.affine) parameter.
Our setup is below. Note in this case shapes is a GeoJSON LineString:
out_image, out_transform = rasterio.mask.mask(src, shapes, crop=True)
with MemoryFile() as memfile:
with memfile.open(driver="GTiff", height=out_image.shape, width=out_image.shape, count=1,
dtype=rasterio.float64, transform=out_transform) as dataset:
ds = dataset.read()
xs_to_mod = list(range(0, ds.shape))
ys_to_mod = list(range(0, ds.shape))
xs, ys = rasterio.transform.xy(out_transform, xs_to_mod, ys_to_mod, offset='center')
toggle quoted messageShow quoted text
The xy method always returns projected coordinates. If you want long and lat, you must reproject the xy values using https://rasterio.readthedocs.io/en/latest/api/rasterio.warp.html?#rasterio.warp.transform.
On Tue, Jun 29, 2021 at 11:55 AM Cooney,Tom (ECCC) <Tom.Cooney@...> wrote: