AnsweredAssumed Answered

Multiple Field calculations

Question asked by kostas_ptr88 on Jan 12, 2016
Latest reply on Jan 12, 2016 by kostas_ptr88

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

Outcomes