raster_tools.Raster.save#

Raster.save(path, null_value=None, *, color_table=None, driver=None, tiled=True, blocksize=None, compress=None, compress_level=None, predictor=None, bigtiff='if_safer', overviews=None, overview_resampling='average', overview_num_threads='all_cpus', no_data_value=None, **gdal_kwargs)[source]#

Compute the final raster and save it to the provided location.

Parameters
  • path (str) – The target location to save the raster to.

  • null_value (scalar, optional) – A new null value to use when saving. Defaults to the raster’s current null value.

  • color_table (dict, array-like, str, pathlib.Path, optional) –

    A discrete color palette to attach to the saved raster, mapping cell values to colors. This can be a dict mapping raster values to (r, g, b) or (r, g, b, a) components in the range 0-255, an array-like of shape (N, 3) or (N, 4) where row i is the color for value i, or the path to an existing raster to copy the color table from. Only single band uint8 and uint16 rasters can carry one. The default is to write no color table.

    Note

    This is a lookup table indexed by cell value, not a continuous ramp; a matplotlib-style colormap name such as "viridis" is not accepted.

    Note

    Alpha components are dropped when writing a GeoTIFF, whose color table has no room for them.

  • driver (str, optional) – The GDAL driver to use. If not given, the driver is inferred from the file extension.

  • tiled (bool, optional) – Whether to write tiled output. Default is True. Applies to drivers with a tiling concept (e.g. GTiff); silently ignored for others.

  • blocksize (int or (int, int), optional) – Tile dimensions. An int means a square tile of that size; a tuple is (height, width). Default lets the driver choose.

  • compress (str or None, optional) – Compression. One of "lzw", "deflate", "zstd", "packbits", "jpeg", or None (default) to disable compression.

  • compress_level (int, optional) – Compression level. Meaning depends on the compressor (e.g. ZLEVEL for deflate, ZSTD_LEVEL for zstd, JPEG_QUALITY for jpeg). Has no effect with "lzw" or "packbits".

  • predictor (str, optional) – Differencing predictor. "horizontal" for integer data, "float" for floating-point. Lossless compressors only.

  • bigtiff (bool or str, optional) – Force BigTIFF. True/False or one of "if_safer" (default), "if_needed", "yes", "no". GTiff only.

  • overviews (bool or list of int, optional) – Build internal overviews after writing. True selects an automatic chain based on raster size; pass a list of decimation factors (e.g. [2, 4, 8]) for explicit control. Default does not build overviews.

  • overview_resampling (str, optional) – Resampling method used to build overviews. Default "average".

  • overview_num_threads (str or int, optional) – Value passed as GDAL_NUM_THREADS while building overviews. Default "all_cpus". Set to None to leave the env unset.

  • no_data_value (scalar, optional) –

    Deprecated since version Use: null_value instead. no_data_value will be removed in a future release.

  • **gdal_kwargs (kwargs, optional) – Additional GDAL creation options forwarded to rasterio. Wins over the translated logical kwargs on collisions.

Returns

A raster pointing to the saved location.

Return type

Raster