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!
Code:
import arcpy, os
from arcpy import env
from arcpy.sa import *
#To overwrite output
arcpy.env.overwriteOutput = True
#Set environment settings
env.workspace = "C:/Subhasis/Test/Neshanic_Python"
outws="C:/Subhasis/Test/Neshanic_Python/extract"
#checkout ArcGIS spatial analyst extension license
arcpy.CheckOutExtension("Spatial")
# 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())
percentage=(sumcnt/sumcnt1)
print percentage
Solved! Go to Solution.
Hi Subhasis,
I notice you have 5 separate threads on more or less the same topic:
Inception Woznicki (just look at the content)
I have a few recommendations:
Kind regards, Xander
Hi Subhasis,
I notice you have 5 separate threads on more or less the same topic:
Inception Woznicki (just look at the content)
I have a few recommendations:
Kind regards, Xander
Hi Xander,
This is a pretty good suggestion. I marked it as answer.
Regards,
Subhasis