Hi there
I would like to include the output of a raster function into the Tabulate Area GP tool, but my raster function output does not have an attribute table. If it were a traditional raster, then I would have run the Build Raster Attribute Table gp tool to create one. Is there a raster function equivalent or is there a different approach to follow? I need to work with categorical data.
Thanks.
what kind of raster is it? normally a float raster has to be converted to an int raster in order to build a raster attribute table. The only thing that I can find to do zonal crosstab (aka counts) is xarray's zonal.crosstab, it is shipped with Pro 2.9
xrspatial.zonal.crosstab — xarray_spatial 0.3.0+g9a8909e-dirty documentation (xarray-spatial.org)
it produces a pandas df (pandas is also installed)
Of course you can do it in numpy using RasterToNumPyArray to get a raster out to an array
import numpy as np
a = np.random.randint(0, 4, size=100).reshape(10, 10)
b = np.random.randint(4, 8, size=100).reshape(10, 10)
ab = np.vstack((a.ravel(), b.ravel())).T
u, cnts = np.unique(ab, return_counts=True, axis=0)
a # -- zone raster
array([[0, 1, 0, 2, 2, 1, 2, 0, 1, 0],
[0, 3, 0, 2, 1, 3, 0, 0, 2, 0],
[0, 1, 2, 1, 2, 3, 1, 0, 0, 3],
[2, 1, 1, 2, 0, 0, 1, 3, 3, 2],
[0, 0, 2, 2, 0, 0, 0, 0, 1, 1],
[3, 1, 2, 0, 0, 1, 2, 1, 1, 0],
[0, 0, 3, 0, 3, 1, 2, 3, 0, 0],
[0, 3, 3, 1, 3, 1, 3, 1, 2, 3],
[3, 0, 0, 1, 3, 2, 2, 1, 0, 0],
[1, 1, 0, 2, 3, 3, 1, 1, 1, 1]])
b # -- values raster
array([[5, 6, 4, 6, 4, 7, 7, 6, 6, 4],
[6, 4, 6, 4, 7, 6, 4, 7, 4, 6],
[4, 4, 7, 5, 4, 7, 6, 7, 5, 4],
[7, 6, 5, 6, 7, 4, 7, 4, 5, 5],
[4, 7, 4, 6, 7, 5, 5, 4, 4, 7],
[4, 6, 7, 4, 7, 6, 6, 6, 6, 4],
[4, 6, 7, 6, 4, 7, 4, 5, 6, 4],
[4, 6, 6, 6, 4, 4, 4, 4, 6, 5],
[4, 7, 7, 7, 6, 5, 5, 6, 7, 5],
[4, 4, 5, 5, 4, 6, 5, 5, 6, 6]])
u # -- unique combinations
array([[0, 4],
[0, 5],
[0, 6],
[0, 7],
[1, 4],
[1, 5],
[1, 6],
[1, 7],
[2, 4],
[2, 5],
[2, 6],
[2, 7],
[3, 4],
[3, 5],
[3, 6],
[3, 7]])
cnts # -- counts per combination
array([12, 6, 7, 9, 6, 4, 12, 6, 6, 4, 5, 4, 9, 3, 5, 2],
dtype=int64)
My understanding is that raster functions are on the fly animals that process at a dynamic resolution and window, so seems to me the idea of a raster table wouldn't really apply, as you need a complete dataset to calculate cell counts and a list of unique values.