我需要根据最近的多边形Name
字段填充点Name
字段。我尝试使用arcpy.analysis.GenerateNearTable
创建内存中的表,但它没有保存我需要的任何字段。如何才能做到这一点并避免创建新层和删除连接
near_result = arcpy.analysis.GenerateNearTable(
fc,
fc1,
r'in_memory\neartable',
'',
'LOCATION',
'NO_ANGLE',
'CLOSEST')
rows = arcpy.SearchCursor(near_result)
for row in rows:
arcpy.CalculateField_management(fc, "Name", "Name", "PYTHON_9.3", "")
我也尝试过这个更新光标,但它只在点位于多边形中时起作用
with arcpy.da.UpdateCursor(fc, ['SHAPE@','Name']) as ucursor:
for update_row in ucursor:
with arcpy.da.SearchCursor(fc1, ['SHAPE@', 'Name']) as scursor:
for search_row in scursor:
if update_row[0].within(search_row[0]):
update_row[1] = search_row[1]
ucursor.updateRow(update_row)
我不想这么说,但最好是进行空间连接,但可以在内存中创建要素类,然后立即将其删除。以下是我在类似情况下的做法:
如果您的数据集有多条记录,那么这将比使用嵌套游标快得多
相关问题 更多 >
编程相关推荐