AnsweredAssumed Answered

Calculate Field with arcpy

Question asked by JuttaSchiller on Sep 26, 2014
Latest reply on Oct 1, 2014 by JuttaSchiller

At first I made a statistic analyst to get the sum of the field area for equal Ids.Now I need the sum of all area fields from the output-table therefore I did another statistic analyst to get the sum. With a searchcursor I tried to get the sumvalue to put it in the calculate field tool. But in the end it is not calculating the percent, so the field I add before and I don’t know what I did wrong. I need to do it with arcpy because it is a small part of a big tool I’m trying to build and the sumvalue will change from input to input.

It would be wonderful if you can tell me my mistake.

The following code is working, but there is just a 0 in the percent field.

 

import arcpy

import os

from arcpy import env

 

env.overwriteOutput = True

env.workspace = r"D:\Users\jul\ers\cities_UA\resultfolder"

 

inputshp = r"D:\Users\jul\ers\cities_UA\resultfolder\at005l_innsbruck_result.shp"

 

outtable= r"D:\Users\jul\ers\cities_UA\resultfolder\outtable.dbf"

arcpy.Statistics_analysis(inputshp, outtable, [["area", "SUM"]], "Id")

 

 

outtableSUM= r"D:\Users\jul\ers\cities_UA\resultfolder\outtableSUM.dbf"

arcpy.Statistics_analysis(outtable, outtableSUM, [["SUM_area", "SUM"]])

 

with arcpy.da.SearchCursor(outtableSUM, "SUM_SUM_ar") as cursor:

    for row in cursor:

          print (int(row[0]))

         

fieldsum = (int(row[0]))

print fieldsum

arcpy.AddField_management(outtable, "prozent", "DOUBLE")#working

 

arcpy.CalculateField_management(outtable, "prozent", "([SUM_area]*100)/fieldsum", "VB")

Outcomes