odc.geo.xr.ODCExtensionDa.write_cog

ODCExtensionDa.write_cog(fname: str | Path, *, overwrite: bool = False, blocksize: int | None = None, ovr_blocksize: int | None = None, overviews: Iterable[xr.DataArray] | None = None, overview_resampling: str | None = None, overview_levels: List[int] | None = None, use_windowed_writes: bool = False, intermediate_compression: bool | str | Dict[str, Any] = False, tags: Dict[str, Any] | None = None, **extra_rio_opts) Path | bytes

Save xarray.DataArray to a file in Cloud Optimized GeoTiff format.

Parameters:
  • geo_im (DataArray) – xarray.DataArray with crs

  • fname (Union[str, Path]) – Output path or ":mem:" in which case compress to RAM and return bytes

  • overwrite (bool) – True – replace existing file, False – abort with IOError exception

  • blocksize (Optional[int]) – Size of internal tiff tiles (512x512 pixels)

  • ovr_blocksize (Optional[int]) – Size of internal tiles in overview images (defaults to blocksize)

  • overviews (Optional[Iterable[DataArray]]) – Write pre-computed overviews if supplied

  • overview_resampling (Optional[str]) – Use this resampling when computing overviews

  • overview_levels (Optional[List[int]]) – List of shrink factors to compute overiews for: [2,4,8,16,32], to disable overviews supply empty list []

  • nodata – Set nodata flag to this value if supplied, by default nodata is read from the attributes of the input array (geo_im.attrs['nodata']).

  • use_windowed_writes (bool) – Write image block by block (might need this for large images)

  • intermediate_compression (Union[bool, str, Dict[str, Any]]) – Configure compression settings for first pass write , default is no compression

  • tags (Optional[Dict[str, Any]]) – Dictionary of tags to write into the output file. These are written as GDAL Metadata items in the GeoTIFF file.

  • extra_rio_opts – Any other option is passed to rasterio.open

Return type:

Union[Path, bytes]

Returns:

Path to which output was written

Returns:

Bytes if fname=":mem:"

Note

memory requirements

This function generates a temporary in memory tiff file without compression to speed things up. It then adds overviews to this file and only then copies it to the final destination with requested compression settings. This is necessary to produce a compliant COG, since the COG standard demands overviews to be placed before native resolution data and double pass is the only way to achieve this currently.

This means that this function will use about 1.5 to 2 times memory taken by geo_im.