Xarray Interop

Importing odc.geo.xr enables .odc extension on xarray.DataArray and xarray.Dataset. You can access geospatial information recorded on those arrays. In the example below we make a sample array filled with zeros, but .odc.geobox will work on data loaded by other libraries like rioxarray or odc.stac. One can also use odc.geo.xr.assign_crs() to inject geospatial information into arrays without one present.

from odc.geo.geobox import GeoBox
from odc.geo.xr import ODCExtensionDa, xr_zeros

xx = xr_zeros(
    GeoBox.from_bbox(
        (-2_000_000, -5_000_000, 2_250_000, -1_000_000), "epsg:3577", resolution=1000
    ),
    chunks=(1000, 1000),
)
assert isinstance(xx.odc, ODCExtensionDa)
display(xx)
display(xx.odc.geobox)
<xarray.DataArray 'zeros_like-f1dd1509ded7759ee615cb07bd19fb87' (y: 4000,
                                                                 x: 4250)> Size: 136MB
dask.array<zeros_like, shape=(4000, 4250), dtype=float64, chunksize=(1000, 1000), chunktype=numpy.ndarray>
Coordinates:
  * y            (y) float64 32kB -1e+06 -1.002e+06 ... -4.998e+06 -5e+06
  * x            (x) float64 34kB -2e+06 -1.998e+06 ... 2.248e+06 2.25e+06
    spatial_ref  int32 4B 3577

GeoBox

Dimensions
4,250x4,000
EPSG
3577
Resolution
1000m
Cell
500px
WKT
PROJCRS["GDA94 / Australian Albers",
    BASEGEOGCRS["GDA94",
        DATUM["Geocentric Datum of Australia 1994",
            ELLIPSOID["GRS 1980",6378137,298.257222101,
                LENGTHUNIT["metre",1]]],
        PRIMEM["Greenwich",0,
            ANGLEUNIT["degree",0.0174532925199433]],
        ID["EPSG",4283]],
    CONVERSION["Australian Albers",
        METHOD["Albers Equal Area",
            ID["EPSG",9822]],
        PARAMETER["Latitude of false origin",0,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8821]],
        PARAMETER["Longitude of false origin",132,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8822]],
        PARAMETER["Latitude of 1st standard parallel",-18,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8823]],
        PARAMETER["Latitude of 2nd standard parallel",-36,
            ANGLEUNIT["degree",0.0174532925199433],
            ID["EPSG",8824]],
        PARAMETER["Easting at false origin",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8826]],
        PARAMETER["Northing at false origin",0,
            LENGTHUNIT["metre",1],
            ID["EPSG",8827]]],
    CS[Cartesian,2],
        AXIS["(E)",east,
            ORDER[1],
            LENGTHUNIT["metre",1]],
        AXIS["(N)",north,
            ORDER[2],
            LENGTHUNIT["metre",1]],
    USAGE[
        SCOPE["Statistical analysis."],
        AREA["Australia - Australian Capital Territory; New South Wales; Northern Territory; Queensland; South Australia; Tasmania; Western Australia; Victoria."],
        BBOX[-43.7,112.85,-9.86,153.69]],
    ID["EPSG",3577]]