我正在使用Python 2.7在64位计算机上处理ArcGIS 10.1中的以下挑战。
我有一个包含三个字段的表:ID#,“Revenue”和“Live” - 和2.1 百万条记录。
我试图通过匹配它来从fGDB中提取要素类 在此表中使用ID#的名称,向FC添加两个字段,以及 使用“收入”和“实时”数据值填充这些字段。
我的脚本包含for循环的层和层,if语句, 和搜索游标。虽然它在一个小的测试批次中工作,但它确实如此 永远使用真实数据,因为它正在搜索2.1 百万条记录。
我在下面添加了我的脚本,它有效 - 并且还显示了我的逻辑 流程,这是我需要指导的地方......
将一长串记录与一组要素类进行比较/匹配时,最佳策略是什么?
import arcpy
import sys
import os
#Read through DBF.
#For each record, locate it in fGDB and add fields REVENUE and LIVE
# Use searchCursor to find ID and REV value and LIVE value
#fc = #ID by the APR16ID
fields = ["APR16_ID","REVENUE", "LIVE"]
workspace = "C:\\FILE\\"
arcpy.env.workspace = workspace
#Table of values to append to each FC in the fGDB
table = "C:\\FILE\\FinalTest.gdb\\AUG_REV_BY_APRID"
#DIRECTORYPATH = the fGDB that has the FeatureClasses that are to have data appended to them.
directorypath = workspace + "DON_d2.gdb"
#Use searchcursor to determine APR16_ID...
cursor = arcpy.da.SearchCursor(table, fields)
for row in cursor:
fc = str("don_d2_"+"{0}".format(row[0]))
print fc
RevVAL = str(row[1])
print RevVAL
LiveVAL = str(row[2])
print LiveVAL
for dirpath, dirnames, fgdb in arcpy.da.Walk(directorypath,
datatype="FeatureClass",
type="Polygon"):
for donut in fgdb:
if str(donut)==str(fc):
print donut + " : this is the same as " + fc
##Append data to donuts_d2
d2_fc = workspace+"DON_d2.gdb\\"+fc
arcpy.AddField_management(d2_fc, "REVENUE", "FLOAT")
arcpy.AddField_management(d2_fc, "LIVE", "FLOAT")
arcpy.GetMessages()
#new SearchCursor for that feature
dons = arcpy.UpdateCursor(d2_fc, fields)
for don in dons:
don.setValue("REVENUE",RevVAL)
don.setValue("LIVE",LiveVAL)
dons.updateRow(don)
arcpy.GetMessages()
else:
pass