xrspatial.geotiff.to_geotiff#

xrspatial.geotiff.to_geotiff(data: DataArray | ndarray, path: str, *, crs: int | str | None = None, nodata=None, compression: str = 'zstd', compression_level: int | None = None, tiled: bool = True, tile_size: int = 256, predictor: bool = False, cog: bool = False, overview_levels: list[int] | None = None, overview_resampling: str = 'mean', bigtiff: bool | None = None, gpu: bool | None = None) None[source]#

Write data as a GeoTIFF or Cloud Optimized GeoTIFF.

Dask-backed DataArrays are written in streaming mode: one tile-row at a time, without materialising the full array into RAM. Peak memory is roughly tile_size * width * bytes_per_sample. COG output (cog=True) still materialises because overviews need the full array.

Automatically dispatches to GPU compression when: - gpu=True is passed, or - The input data is CuPy-backed (auto-detected)

GPU write uses nvCOMP batch compression (deflate/ZSTD) and keeps the array on device. Falls back to CPU if nvCOMP is not available.

Parameters:
  • data (xr.DataArray or np.ndarray) – 2D raster data.

  • path (str) – Output file path.

  • crs (int, str, or None) – EPSG code (int), WKT string, or PROJ string. If None and data is a DataArray, tries to read from attrs (‘crs’ for EPSG, ‘crs_wkt’ for WKT).

  • nodata (float, int, or None) – NoData value.

  • compression (str) – ‘none’, ‘deflate’, ‘lzw’, ‘jpeg’, ‘packbits’, or ‘zstd’. JPEG is lossy and only supports uint8 data (1 or 3 bands). With gpu=True, JPEG uses nvJPEG for GPU-accelerated encode/decode when available, falling back to Pillow on CPU.

  • compression_level (int or None) – Compression effort level. None uses each codec’s default (6 for deflate/zstd). Valid ranges: deflate 1-9, zstd 1-22, lz4 0-16. Codecs without a level concept (lzw, packbits, jpeg) accept any value and ignore it.

  • tiled (bool) – Use tiled layout (default True).

  • tile_size (int) – Tile size in pixels (default 256).

  • predictor (bool) – Use horizontal differencing predictor.

  • cog (bool) – Write as Cloud Optimized GeoTIFF.

  • overview_levels (list[int] or None) – Overview decimation factors. Only used when cog=True.

  • overview_resampling (str) – Resampling method for overviews: ‘mean’ (default), ‘nearest’, ‘min’, ‘max’, ‘median’, ‘mode’, or ‘cubic’.

  • gpu (bool or None) – Force GPU compression. None (default) auto-detects CuPy data.