write#
- write(xds: DataArray | Dataset, output_path: str | CloudPath | Path = None, tags: dict = None, write_cogs_with_dask: bool = True, compute: bool = True, **kwargs) None[source]#
Write raster to disk. (encapsulation of
rasterio’s function, because for nowrioxarrayto_raster doesn’t work as expected)Metadata will be created with the
xarraymetadata (i.e. width, height, count, type…) The driver isGTiffby 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
LZWoption by default. To disable it, add thecompress=Noneparameter.predictorset to 2 for float data, to 3 for interger data by default. To disable it, add thepredictor=Noneparameter.tiledset to True by default.driverisGTiffby default. BigTiff option is set according to the estimated output weight
Warning
With dask usage, this function is not lazy by default. Use
compute=Falsewith a delayed return.- Parameters:
xds (AnyXrDataStructure) – Path to the raster or a rasterio dataset or a xarray
output_path (AnyPathStrType) – Path where to save it (directories should be existing)
tags (dict) – Tags that will be written in your file
write_cogs_with_dask (bool) – If odc-geo and imagecodecs are installed, write your COGs with Dask. Otherwise, the array will be loaded into memory before writing it on disk (and can cause MemoryErrors). Only used with chunked data.
compute (bool) – If True (default) and data is a dask array, then compute and save the data immediately. If False, return a dask Delayed object. Call “.compute()” on the Delayed object to compute the result later. Call
dask.compute(delayed1, delayed2)to save multiple delayed files at once. Only useful with chunked data.**kwargs – Overloading metadata, ie
nodata=255ordtype=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)