AnsweredAssumed Answered

Raster' object is not iterable

Question asked by sean.woznicki on Jul 23, 2014
Latest reply on Jul 28, 2014 by sean.woznicki

Hi Guys,


I 'm trying to calculate the percentage of cell counts in new raster and the new raster is created from an old raster based on the Value > 14. In my code, 1st for loop is for original raster and keeping the value and count fields in a dictionary. Then, creating new raster using Value > 14. The 2nd for loop is for the new raster and keeping its value and counts of in a new dictionary and finally calculating the percentage.


However, I am getting an error on the 2nd for loop. The error says " 'Raster' object is not iterable". Anybody has any suggestion. Thank you for your help!




import arcpy, os

from arcpy import env

from import *


#To overwrite output

arcpy.env.overwriteOutput = True


#Set environment settings

env.workspace = "C:/Subhasis/Test/Neshanic_Python"




#checkout ArcGIS spatial analyst extension license



# set local variable

inraster = ["01367620-r-r"]

for i in inraster:

    flds = ("VALUE", "COUNT") 

    dct = {row[0]:row[1] for row in arcpy.da.SearchCursor(i, flds)} 

    sumcnt = sum(dct.values())

    newraster = ExtractByAttributes(str(i), "VALUE>=14")

    for j in newraster:

        flds1 = ("VALUE", "COUNT")

        dct1 = {row[0]:row[1] for row in arcpy.da.SearchCursor(j, flds)}

        sumcnt1 = sum(dct1.values())


        print percentage