rioxarray
rioxarray copied to clipboard
Switching back to rasterio datasets
As rioxarray
can read rasterio
's datasets and implements some wrapping to rasterio
functions (but not all of it, such as mask), it could be a good thing to have a function creating back a rasterio
dataset from a xarray
in order to have the possibility to use other rasterio functions.
I have a snippet, but I am not sure if it's the best way to do it:
meta = {'driver': 'GTiff',
'dtype': xds.dtype,
'nodata': xds.rio.encoded_nodata,
'width': xds.rio.width,
'height': xds.rio.height,
'count': xds.rio.count,
'crs': xds.rio.crs,
'transform': xds.rio.transform()
}
arr = np.where(np.isnan(xds.data), xds.rio.encoded_nodata, xds.data)
with MemoryFile() as memfile:
with memfile.open(**meta) as dst:
dst.write(arr)
Related: https://github.com/corteva/rioxarray/discussions/204
Arf sorry for the duplicate !
Arf sorry for the duplicate !
No worries. It is good to have an issue for it as you currently cannot transfer a discussion to an issue.
Related #668