如何在多个要素类中对值进行求和?

时间:2015-10-01 22:11:35

标签: windows python-2.7 oracle10g arcgis

我拼凑了下面的代码,循环遍历一些要素类,并输出fc的总和,以及要素类数量的总和。我难以理解的最后一块拼图是如何现在总结每个要素类的总和,所以我不需要在脑海中添加它们。我已经阅读了许多类似的帖子,但它们似乎都专注于返回要素类的总和,而不是多个要素类的总和。 (我在Win 7上,Oracle 10g,Python 2.7.5,ArcGIS 10.2.1) 到目前为止我的工作代码.....

-L$(shell pwd)

产生这个结果......

    FCS = arcpy.ListFeatureClasses()
    FCS.sort()
    for fc in FCS:
            if fc.startswith("Book"):
                    DM1 = arcpy.GetCount_management(fc)
                    print "\t" + fc +" Record Count = "+  str(DM1)
                    # total = sum(str(DM1)) ####  my effort to return sum
                    # print "Book_** Record Count = " +total
    # and the number of feature classes (In case there were hundreds)
    fcCount = len(FCS)
    print '\n' '\t' "FeatureClasses found = " + str(fcCount)

我在返回的行之后有"预订_ **记录计数= 91204"。

1 个答案:

答案 0 :(得分:1)

创建一个名为total的变量。每次循环时,将total增加该要素类的计数DM1。然后在循环后打印str(total)。看哪:

total = 0
FCS = arcpy.ListFeatureClasses()
FCS.sort()
for fc in FCS:
        if fc.startswith("Book"):                    
                getCountResult = arcpy.GetCount_management(fc)
                DM1 = int(getCountResult.getOutput(0))
                print "\t" + fc +" Record Count = "+  str(DM1)
                total += DM1
print "Book_** Record Count = " + str(total)
# and the number of feature classes (In case there were hundreds)
fcCount = len(FCS)
print '\n' '\t' "FeatureClasses found = " + str(fcCount)