xrspatial.zonal.crosstab(zones: xarray.core.dataarray.DataArray, values: xarray.core.dataarray.DataArray, layer: Optional[str] = None)pandas.core.frame.DataFrame[source]

Calculate cross-tabulated (categorical stats) areas between two datasets: a zone dataset, a value dataset (a value raster). Outputs a pandas DataFrame.

Requires a DataArray with a single data dimension, here called the “values”, indexed using 3D coordinates.

DataArrays with 3D coordinates are expected to contain values distributed over different categories that are indexed by the additional coordinate. Such an array would reduce to the 2D-coordinate case if collapsed across the categories (e.g. if one did aggc.sum(dim='cat') for a categorical dimension cat).

zones: xarray.DataArray,

zones.values is a 2d array of integers. A zone is all the cells in a raster that have the same value, whether or not they are contiguous. The input zone layer defines the shape, values, and locations of the zones. An integer field in the zone input is specified to define the zones.

values: xarray.DataArray,

values.values is a 3d array of integers or floats. The input value raster contains the input values used in calculating the categorical statistic for each zone.

layer: str, optional (default = None)

name of the layer inside the values DataArray for getting the values.

crosstab_df: pandas.DataFrame

A pandas DataFrame where each column is a categorical value and each row is a zone with zone id. Each entry presents the percentage of the category over the zone.