Hi I have severous viewsheds (view1, view2, view3 etc) and I want to calculate the percent of visible areas per viewshed. I have the following code but I always get zero "0" at the second for loop and i have been trying that for hours, any help?
Thanks in advance
import arcpy import os from arcpy import env from arcpy.sa import * #workspace = arcpy.GetParameterAsText(0) arcpy.env.workspace = "C:Visibility/Calc_View/View" ras = arcpy.ListRasters("view*", "GRID") #cellsize = arcpy.GetParameterAsText(1) fields = ["VALUE", "COUNT"] for r in ras: with arcpy.da.UpdateCursor(r, fields) as cursor: total = 0 for row in cursor: total = total + row[1] print r, total C = arcpy.da.UpdateCursor(r, fields, """"VALUE" = 1""") for row in C: percent = row[1] / total print r, percent
Solved! Go to Solution.
percent = row[1] / float(total) maybe or row[1] is zero...print them before your percent calc
percent = row[1] / float(total) maybe or row[1] is zero...print them before your percent calc
aaa close, thank you a lot
A view comments.
thank you, I didn't want to update it I was just want to take the value, I will just pass it to a txt.