使用arcpy更新游标以填充值

时间:2017-06-08 06:08:05

标签: python arcpy

我有一些来自我的教师的代码但是当我在建模器中将其作为脚本运行时会产生错误。 这是一段代码,其余的重复但DIST字段的值不同。 此代码旨在添加" DIST"字段到要素类并根据UpdateCursor中的条件填充它。

#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)

1 个答案:

答案 0 :(得分:0)

这是我自己的错,而不是代码,当我在建模器中使用addField工具时,我没有将它们称为LZONE和RZONE。所以这与导致问题的代码不匹配。