Skip to content

Conversion

Functions for converting metadata to/from GeoZarr

geozarr_toolkit.from_geotransform

from_geotransform(
    geotransform: tuple[float, ...] | list[float],
    crs_wkt: str,
    shape: tuple[int, int],
    dimensions: list[str] | None = None,
) -> dict[str, Any]

Convert GDAL-style GeoTransform to convention attributes.

GDAL GeoTransform format: [c, a, b, f, d, e] - c: x-coordinate of upper-left corner - a: pixel width (x resolution) - b: row rotation (typically 0) - f: y-coordinate of upper-left corner - d: column rotation (typically 0) - e: pixel height (y resolution, typically negative)

Rasterio/Affine format (used by spatial convention): [a, b, c, d, e, f]

Parameters:

  • geotransform (tuple or list of float) –

    GDAL-style geotransform [c, a, b, f, d, e].

  • crs_wkt (str) –

    WKT string of the CRS.

  • shape (tuple of int) –

    Array shape (height, width).

  • dimensions (list[str], default: None ) –

    Dimension names. Default: ["Y", "X"].

Returns:

  • dict[str, Any]

    Combined spatial: and proj: convention attributes.

geozarr_toolkit.from_rioxarray

from_rioxarray(da: DataArray) -> dict[str, Any]

Extract spatial and proj convention attributes from a rioxarray DataArray.

Parameters:

  • da (DataArray) –

    A DataArray with CRS and transform information set via rioxarray.

Returns:

  • dict[str, Any]

    Combined spatial: and proj: convention attributes.

Raises:

  • ValueError

    If the DataArray doesn't have CRS or transform information.