write#
- 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 nowrioxarray
to_raster doesn’t work as expected)Metadata will be created with the
xarray
metadata (i.e. width, height, count, type…) The driver isGTiff
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
: 255int8
: -128uint16
,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 thecompress=None
parameter.predictor
set to 2 for float data, to 3 for interger data by default. To disable it, add thepredictor=None
parameter.tiled
set to True by default.driver
isGTiff
by default. BigTiff option is set according to the estimated output weight
- Parameters:
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
ordtype=np.uint8
Examples
>>> raster_path = "path/to/raster.tif" >>> raster_out = "path/to/out.tif" >>> >>> # Read raster >>> xds = read(raster_path) >>> >>> # Rewrite it >>> write(xds, raster_out)