gpt4 book ai didi

python - Arc Pro 中的更新光标功能不显示错误,但不会执行

转载 作者:太空宇宙 更新时间:2023-11-03 21:14:23 26 4
gpt4 key购买 nike

我编写此代码是为了在 ArcGIS Pro 中运行,以便在其他单元格之一为 true 时填充属性表中的某些单元格。当我运行脚本时,表中没有任何反应,也没有收到错误消息。我是否忘记了执行它的代码的某些部分?谢谢!

import arcpy
fc = 'C://file//path//folder.gdb//featureclass'

fields = ['OBJECT', 'PROJECT', 'LENGTH', 'ID', 'etc.', 'FIELD', 'FIELD2',
'FIELD3', 'FIELD4', 'DV......']


with arcpy.da.UpdateCursor(fc, fields) as rows:
for row in rows:
if(row[10] == "AERIAL"):
row[15] == "N" and row[18] == "AER::"
rows.updateRow(row)
else:
if(row[10] == "BURIED"):
row[15] == "Y" and row[18] == "BUR::"
cursor.updateRow(row)

最佳答案

在尝试更新行之前,您没有为行分配新值。

我认为这是一个语法问题。

这两行:

row[15] == "N" and row[18] == "AER::"
row[15] == "Y" and row[18] == "BUR::"

只是测试row[15]值是否等于"N""Y"row[18 ] 值等于 "AER::""BUR::"。这些行仅返回 TrueFalse,行值不会被修改。

如果您想要为row[15]row[18]分配新值,则必须按照以下代码进行操作:

import arcpy
fc = 'C://file//path//folder.gdb//featureclass'

fields = ['OBJECT', 'PROJECT', 'LENGTH', 'ID', 'etc.', 'FIELD', 'FIELD2',
'FIELD3', 'FIELD4', 'DV......']

with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in rows:
if row[10] == "AERIAL":
row[15] = "N" #assign value "N" to row[15]
row[18] = "AER::" #assign value "AER::" to row[18]
cursor.updateRow(row)
elif row[10] == "BURIED":
row[15] = "Y" #assign value "Y" to row[15]
row[18] = "BUR::" #assign value "BUR::" to row[18]
cursor.updateRow(row)

关于python - Arc Pro 中的更新光标功能不显示错误,但不会执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54830577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com