rioxarray icon indicating copy to clipboard operation
rioxarray copied to clipboard

Switching back to rasterio datasets

Open remi-braun opened this issue 3 years ago • 5 comments

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)

remi-braun avatar Apr 21 '21 06:04 remi-braun

Related: https://github.com/corteva/rioxarray/discussions/204

snowman2 avatar Apr 21 '21 12:04 snowman2

Arf sorry for the duplicate !

remi-braun avatar Apr 21 '21 13:04 remi-braun

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.

snowman2 avatar Apr 21 '21 13:04 snowman2

Related #668

snowman2 avatar May 24 '23 01:05 snowman2