使用arcpy填充光标以填充值
问题描述:
我有一些来自我的教师的代码,但是当我在建模器中将其作为脚本运行时,它会产生错误。 这是一段代码,其余部分重复但DIST字段的值不同。 此代码旨在将“DIST”字段添加到要素类,并根据UpdateCursor中的条件进行填充。使用arcpy填充光标以填充值
#Import arcpy and standard library modules
import arcpy, sys, os
# Get feature class from argument
zoneArcSelect = sys.argv[1]
# Add DIST field to input feature class
arcpy.AddField_management(zoneArcSelect, "DIST", "SHORT")
#get rows using update cursor and conflict selection
rows = arcpy.UpdateCursor(zoneArcSelect,"(LZONE = 'O-L' AND RZONE = 'M-1') OR (RZONE = 'O-L' AND LZONE = 'M-1')")
# calculate value for DIST and update row
for row in rows:
row.DIST = 100
rows.updateRow(row)
#get rows using update cursor and conflict selection
rows = arcpy.UpdateCursor(zoneArcSelect,"(LZONE = 'M-1' AND RZONE = 'RPC') OR (RZONE = 'M-1' AND LZONE = 'RPC')")
# calculate value for DIST and update row
for row in rows:
row.DIST = 200
rows.updateRow(row)
#get rows using update cursor and conflict selection
rows = arcpy.UpdateCursor(zoneArcSelect,"(LZONE = 'M-1' AND RZONE = 'RM-1') OR (RZONE = 'M-1' AND LZONE = 'RM-1')")
# calculate value for DIST and update row
for row in rows:
row.DIST = 200
rows.updateRow(row)
答
这是我自己的错而不是代码,当我在建模用于激活addField工具,我没打电话给他们LZONE和RZone中。所以这不符合导致问题的代码。
请按照格式[指导方针](https://stackoverflow.com/help/mcve)了解如何提出问题。 – user3382203
它产生的错误是什么?您是否使用Arc 10.1或更高版本? – Erica
这是一个语法错误。我相信10.3版本 – deakin1416