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.

enter image description here

  • @BERA Thank you so much.
    – user_3264
    Jun 30, 2021 at 8:08

1 Answer 1


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.

  1. Clip to raster to your polygon using Menu Raster / Extraction / Clip raster by mask layer.

  2. Create contour polygons: Menu Processing / Toolbox / contour Polygon and set Interval between contour lines to 100.

  3. In the output, select the relevant feature (with attributes ELEV_MIN=900 and ELEV_MAX=1000).

  4. Run zonal statistics and check the box next to Selected features only and for Statistics to calculate select count.

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):

enter image description here

Your Answer

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

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