'module' object has no attribute 'GeometryIntersection'
时间: 2023-07-14 18:59:44 浏览: 163
您遇到的错误是因为ArcPy中没有名为`GeometryIntersection`的函数。我为您改写了代码,使用`Intersect`函数来检查起始点和终点是否与其他要素相交。请尝试使用以下代码:
```python
import arcpy
# 设置工作环境和输入要素类
arcpy.env.workspace = r"C:\path\to\your\geodatabase.gdb"
input_features = "your_line_features"
# 创建空的悬挂点图层
hang_points = arcpy.CreateFeatureclass_management(arcpy.env.workspace, "hang_points", "POINT")
# 添加字段
arcpy.AddField_management(hang_points, "line_oid", "LONG")
# 遍历线状要素,检查悬挂点并添加到悬挂点图层
with arcpy.da.SearchCursor(input_features, ["OID@", "SHAPE@"]) as cursor:
with arcpy.da.InsertCursor(hang_points, ["SHAPE@", "line_oid"]) as insert_cursor:
for row in cursor:
line_oid = row[0]
line_geometry = row[1]
# 检查起始点是否为悬挂点
start_point_on_line = line_geometry.firstPoint
start_point_on_line_geometry = arcpy.PointGeometry(start_point_on_line, line_geometry.spatialReference)
intersecting_features = arcpy.Intersect_analysis([start_point_on_line_geometry, input_features], arcpy.Geometry())
if len(intersecting_features) == 1: # 如果只有起始点自身相交,则添加到悬挂点图层
insert_cursor.insertRow((start_point_on_line, line_oid))
# 检查终点是否为悬挂点
end_point_on_line = line_geometry.lastPoint
end_point_on_line_geometry = arcpy.PointGeometry(end_point_on_line, line_geometry.spatialReference)
intersecting_features = arcpy.Intersect_analysis([end_point_on_line_geometry, input_features], arcpy.Geometry())
if len(intersecting_features) == 1: # 如果只有终点自身相交,则添加到悬挂点图层
insert_cursor.insertRow((end_point_on_line, line_oid))
# 输出悬挂点图层
output_path = r"C:\path\to\output.gdb"
arcpy.CopyFeatures_management(hang_points, output_path + "\\hang_points")
```
请确保将代码中的路径替换为您自己数据的实际路径。此代码将创建一个名为`hang_points`的新要素类,并将悬挂点添加到其中,然后将其复制到指定的输出路径。悬挂点被定义为线状要素的起始点或终点,不与其他要素相交。
希望这次能帮到您!如果您有任何其他问题,请随时提问。
阅读全文