Hello,
I am about to begin developing a function that has a polygon featureclass and a raster as inputs. The purpose of the function is to calculate the average of the raster cell values that fall within each polygon.
For example
polygon feature class contains 3 polygons
Polygon 1 overlaps/contains 3 cells with values 1,2,3
Polygon 2 overlaps/contains 5 cells with values 1,3,5,7,9
Polygon 3 overlaps/contains 3 cells with values 7,8,9
The output would be
Polygon 1 average = 2
Polygon 2 average = 5
Polygon 3 average = 8
The only way that I know to do this is to loop through each cell of the raster, create a spatial query using the center point of the raster cell as the geometry, querying the polygon featureclass to get the polygon that contains the point, and finally having some data structure that holds the values for each polygon in order to compute the averages after the loop.
These seems like a very inefficient way of implementing this functionality. Does anyone have any suggestions on a better way to implement this?