gpt4 book ai didi

python - ArcGis 上的 Python 出现 UnboundLocalError

转载 作者:太空宇宙 更新时间:2023-11-03 18:51:42 25 4
gpt4 key购买 nike

我正在使用 ArcMap,我有这个 python 代码:

import arcpy, sys

feature = arcpy.GetParameterAsText(0)


def nearRoutine():
#calculate the distances using the current dataset
arcpy.Near_analysis(feature, feature)

#iterate through any features which are within the distance
cur = arcpy.UpdateCursor(feature, '"NEAR_DIST" < 500')
row1 = cur.next()
while row1:

#this point is within the distance of its neighbor, so delete it
cur.deleteRow(row1)

#now re-run this routine on the new dataset
del row1, cur
nearRoutine

#call the recursive routine. It will get progressively faster to run as it will loop through fewer points each time
nearRoutine()

我的错误消息:UnboundLocalError:赋值前引用了局部变量“row1”

我不明白,因为我的变量已经明确定义了......

有人有问题吗?

最佳答案

您删除row1,然后继续迭代要求(检查)它!

我不确定您是否真的需要在变量 row1cur 上使用 del 。您要删除这些变量,而不是它们在数据结构中的内容。

关于python - ArcGis 上的 Python 出现 UnboundLocalError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18214937/

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