该值不是 INVERT | NOT_INVERT 的成员。
时间: 2023-07-29 10:06:40 浏览: 91
抱歉,我之前给出的代码有一处错误。空间查询的参数中,使用了不正确的选择类型。请使用以下修正后的代码:
```python
import arcpy
# 设置工作空间
arcpy.env.workspace = r"D:\数据备份"
# 输入的线图层和点图层路径
line_shp = r"D:\数据备份\线.shp"
point_shp = r"D:\数据备份\点.shp"
# 创建一个内存中的副本用于编辑
line_copy = arcpy.CopyFeatures_management(line_shp, "in_memory\line_copy")
# 进行空间查询,找到线和点不重合的节点
arcpy.MakeFeatureLayer_management(line_copy, "line_lyr")
arcpy.MakeFeatureLayer_management(point_shp, "point_lyr")
arcpy.SelectLayerByLocation_management("line_lyr", "INTERSECT", "point_lyr", "", "NEW_SELECTION")
arcpy.SelectLayerByLocation_management("line_lyr", "WITHIN_A_DISTANCE", "point_lyr", "0.1 Meters", "SUBSET_SELECTION")
# 删除不重合的节点,但保留线的端点
with arcpy.da.UpdateCursor("line_lyr", ["SHAPE@"]) as cursor:
for row in cursor:
line_geom = row[0]
new_line = arcpy.Polyline(arcpy.Array([pnt for pnt in line_geom if pnt.touches(point_shp) or pnt.firstPoint or pnt.lastPoint]))
row[0] = new_line
cursor.updateRow(row)
# 保存修改并删除临时图层
arcpy.CopyFeatures_management("line_lyr", line_shp)
arcpy.Delete_management("in_memory")
print("处理完成!")
```
请注意,以上代码已经修正了错误,并使用了正确的选择类型。重新运行修正后的代码应该可以解决报错问题。
再次为之前的错误给您带来的困扰道歉。如果您还有其他问题,请随时提问。
阅读全文