I have a raster of morphology data where each bin has a code. I want to count the number of each code that fall under a polygon from another file. Zonal stats as table only gives me the min/max occuring codes and not count of each code. Can anyone suggest how to get count of each code for each polygon?
You can use the Tabulate Area tool to get the metrics you need for binned data. I often join the resulting table to the polygon boundary shapefile for convenience, although this is optional. Here is the workflow:
- Tabulate Area (Spatial Analyst). There are two inputs here: 1) the morphology raster and 2) a polygon shapefile of boundaries you would like to calculate area by class.
- Join Field (Data Management). This is optional, although it is useful to have the tabulate area table attributes joined to the boundaries polygon shapefile.
- Optional. Add new fields for each of the cover classes and calculate meaningful units. For example, if the projection is in UTM at 1m spatial resolution, the units in the attributes will also in m. Therefore, it would useful to calculate acres or hectares per boundary feature rather than the default m^2/feature.
Here is an example using a classified canopy cover raster dataset and a polygon grid shapefile.
The screenshot shows the results of the described workflow. I used a raster dataset with the following classes for this example: VALUE_1 = 0-1%, VALUE_2 = 1-5%, VALUE_3 = 5-10%, VALUE_4 = 10-20%, VALUE_5 = 20-30%, AND VALUE_6 = 30-40%.
I might advise you to try the QGIS 2.2 plug-in.