I have raster image overlap with shapefile (attached below). Is it possible to count the number of cells with specific value. for i.e., I have a 500 raster cells. 200 raster cells give 1st value and 200 raster cells gives 2nd values and remaining 100 raster cells gives 3rd values. So could I count like this separately values raster cells in a categories.
1 Answer
As commented by @BERA, Zonal histogramm creates a separate attribute for each pixel-value. However, if you have many different values (like in a DEM), you get hundreds if not thousands of attributes and it can get extremely slow to get the values you look for.
Another solution (for QGIS, but this should work in ArcGIS as well): let's say you want to find out the number of pixels between 900 and 1000 [meters] of a DEM that area covered by a polygon.
Clip to raster to your polygon using
Menu Raster / Extraction / Clip raster by mask layer
.Create contour polygons:
Menu Processing / Toolbox / contour Polygon
and setInterval between contour lines
to 100.In the output, select the relevant feature (with attributes
ELEV_MIN
=900 andELEV_MAX
=1000).Run zonal statistics and check the box next to
Selected features only
and forStatistics to calculate
selectcount
.
Screenshot: orgininal raster (pale, in the background), clipped raster (sturated), polygon (red outline) and contour polygon (blue). The attribute _count
shows the number of pixels inside the blue polygon (900 to 1000 meters):