raster.write_cog()
Write an array, a VRT or a raster file as a Cloud Optimized GeoTIFF.
Usage
raster.write_cog(data: np.ndarray | VRT | AnyPath, dst_file: AnyPath, profile: dict[str, Any] | None = ..., band_names: list[str] | None = ..., color_interp: list[ColorInterp] | None = ..., tags: Mapping[str, str] | None = ..., band_tags: Sequence[Mapping[str, str]] | None = ..., units: list[str] | None = ..., checksum: Literal[False] = ...) -> None
raster.write_cog(data: np.ndarray | VRT | AnyPath, dst_file: AnyPath, profile: dict[str, Any] | None = ..., band_names: list[str] | None = ..., color_interp: list[ColorInterp] | None = ..., tags: Mapping[str, str] | None = ..., band_tags: Sequence[Mapping[str, str]] | None = ..., units: list[str] | None = ..., checksum: Literal[True]) -> str
raster.write_cog(data: np.ndarray | VRT | AnyPath, dst_file: AnyPath, profile: dict[str, Any] | None = ..., band_names: list[str] | None = ..., color_interp: list[ColorInterp] | None = ..., tags: Mapping[str, str] | None = ..., band_tags: Sequence[Mapping[str, str]] | None = ..., units: list[str] | None = ..., checksum: bool) -> str | NoneA VRT or raster path is streamed through GDAL without loading it into memory. A path is read with freezebase.vrt.from_raster, which refuses colour tables and south-up rasters.
Parameters
data: numpy.ndarray | VRT | str | Path | UPath-
Single- or multi-band array (or array-like), a VRT, or a raster file.
dst_file: str | Path | UPath-
Destination COG (local or S3).
profile: dict[str, Any] or None = None-
Raster metadata and native GDAL
COGcreation options, the latter in any case; required for an array. For a VRT or path onlydtype,nodataand the creation options apply:dtypecasts every band, and anodatavalue that differs from a band’s moves the pixels holding the old one to it.nodata=Nonekeeps the VRT’s nodata, as leaving it out. A cast rounds and clamps out-of-range values, so a valid value can become the nodata value. Bands that differ in dtype or nodata needdtypeornodatahere. band_names: list[str] or None = None-
Band descriptions, one per band.
color_interp: list[ColorInterp] or None = None-
Per-band color interpretation.
tags: Mapping[str, str] or None = None-
Dataset-level tags.
band_tags: Sequence[Mapping[str, str]] or None = None-
Per-band tags, one mapping per band.
units: list[str] or None = None-
Band unit strings, one per band.
checksum: bool = False-
Hash the encoded COG file, the exact bytes that land at
dst_file, and return the digest.
Returns
str or None-
The SHA-256 digest as a multihash (
"1220"+ hex) whenchecksumisTrue, otherwiseNone.
Raises
ValueError-
If
profileis missing for an array, a per-band sequence has the wrong length, the dtype is unknown, a nodata value does not fit the dtype, a raster path is under a GDAL virtual file system such as/vsitar/or has a colour table or is south-up, or the bands differ in dtype or nodata withoutprofilesetting it, orprofileholds aCOGoption that reprojects, such astarget_srsortiling_scheme. RasterWriteError- If the write fails, also when GeoTIFF cannot store the CRS, such as a projected CRS with ellipsoidal heights.