1

我正在研究 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: local variable 'row1' referenced before assignment

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

有人有问题吗?

4

1 回答 1

1

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

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

于 2013-08-13T16:58:41.913 回答