如果表中的要素列是渡口,那么我需要在已经添加到表中的Ferry列中添加Yes。如果特征栏没有说渡口,我需要在渡轮列上添加否。以下是我遇到问题的代码块。有什么建议?是的我是python的新手,任何建议或提示将不胜感激,因为它将帮助我学习。欢呼声。
#need to update FERRY column with yes or no values if ferry crossing is available in feature field
delimfield = arcpy.AddFieldDelimiters(fc, "FERRY")
cursor = arcpy.da.UpdateCursor(fc, ["FERRY"])
for row in cursor:
if row[0] == "ferry crossing":
cursor.updateRow("FERRY")
print "YES"
if row[0] is not "ferry crossing":
cursor.updateRow("FERRY")
print "NO"
del row
del cursor
#if feature is ferry crossing == YES in FERRY field
#if feature is not ferry crossing == NO in FERRY field
答案 0 :(得分:1)
您需要获取光标中的两个字段:测试的feature
字段和要更新的FERRY
字段。然后,您的现有代码将正确测试,但您需要修改它以执行更新。使用字段的列表位置在行对象中访问它们。
with arcpy.da.UpdateCursor(fc, ["FEATURE", "FERRY"]) as cursor:
for row in cursor:
if row[0] == "ferry crossing": # test the FEATURE field
row[1] = "FERRY" # set the FERRY field
print "YES"
else:
print "NO"
cursor.updateRow(row) # commit the changes