[GIS] Intersect shapefile with raster, then determine proportion of each raster value

arcpyrastershapefilestatisticszonal statistics

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.

Best Answer

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)