Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use a cell count of an integer raster as a variable in Arcgis 10 ModelBuilder (and later in a python script), but can't seem to find how to access this information.

Is there a (python) function that will return a cell count for a particular value? eg. something like

count([raster], value)? 

Or how do I access the count column for a particular value in the raster table?

share|improve this question
up vote 2 down vote accepted

You could try to access it by reading the attribute table (assuming you have one; if you don't there is also a python function to create one).

# loop through attribute table    
Rows = ARCPY.SearchCursor( shapefile ) 

SomeValue = 'Count' # or some other column header name
for row in Rows:
    val = row.getValue( SomeValue ) 
    print val
share|improve this answer
To build the raster attribute table: arcpy.BuildRasterAttributeTable_management("c:/data/image.tif", "Overwrite") – scw Mar 3 '11 at 3:11
Thanks, to get counts for a particular value in the raster table I used this in the for loop: val = row.getValue('Value') count = row.getValue('Count') if val==1: return count getValue worked with single quotes, but row.Value also worked. – CCID Mar 3 '11 at 4:19
great - I'll clarify my answer to explain what I meant by SomeValue; I choose print just to illustrate the result; return is better of course but you need to create a function. – djq Mar 3 '11 at 10:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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