write(xds: DataArray | Dataset, path: str | CloudPath | Path, tags: dict = None, **kwargs) None[source]#

Write raster to disk. (encapsulation of rasterio’s function, because for now rioxarray to_raster doesn’t work as expected)

Metadata will be created with the xarray metadata (i.e. width, height, count, type…) The driver is GTiff by default, and no nodata value is provided. The file will be compressed if the raster is a mask (saved as uint8).

If not overwritten, sets the nodata according to dtype:

  • uint8: 255

  • int8: -128

  • uint16, uint32, int32, int64, uint64, int: 65535

  • :code:int16, float32, float64, float128, float: -9999

Default parameters

  • Compress with LZW option by default. To disable it, add the compress=None parameter.

  • predictor set to 2 for float data, to 3 for interger data by default. To disable it, add the predictor=None parameter.

  • tiled set to True by default.

  • driver is GTiff by default. BigTiff option is set according to the estimated output weight

  • xds (AnyXrDataStructure) – Path to the raster or a rasterio dataset or a xarray

  • path (AnyPathStrType) – Path where to save it (directories should be existing)

  • **kwargs – Overloading metadata, ie nodata=255 or dtype=np.uint8


>>> raster_path = "path/to/raster.tif"
>>> raster_out = "path/to/out.tif"
>>> # Read raster
>>> xds = read(raster_path)
>>> # Rewrite it
>>> write(xds, raster_out)