Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

Many thanks

share|improve this question
add comment

1 Answer

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
add comment

Your Answer

 
discard

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.