Using the arcpy module in Python, I want to find the proportion of each pixel value within the boundary of an overlaying polygon. (The polygon is in a shapefile.)

For example, there are 10 possible values in the raster, and intersecting the polygon 17% of the pixels are class1, 8% are class2, etc.

This may involve use of the Zonal Statistics tool, but apparently I'm having trouble working out the syntax programmatically.

1 Answer 1


I would use Tabulate Area (Spatial Analyst) rather than Zonal Statistics if you are after proportions.

enter image description here

import arcpy
from arcpy import env
from arcpy.sa import *
env.workspace = "C:/sapyexamples/data"
TabulateArea("zonedata.shp", "IDStr", "valueraster", "VALUE",
             "C:/sapyexamples/output/areatable.dbf", 2) 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.