3

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?

1 Answer 1

2

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
3
  • To build the raster attribute table: arcpy.BuildRasterAttributeTable_management("c:/data/image.tif", "Overwrite")
    – scw
    Mar 3, 2011 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, 2011 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, 2011 at 10:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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