在Arcpy中多段线的中点到点要素

2024-09-29 23:19:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试编写一个python脚本来确定水管网上的流向。我已经用这个脚本找到了沿每条折线的中点,现在我需要将这些数据转换成一个点要素类,它将成为流向的箭头。在

我尝试过将其保存为列表,但无法将列表转换为点特征。有人能建议将中点位置保存为点要素类的方法吗?在

#FlowArrows.py
import arcpy
#setting the environment
arcpy.env.workspace = "J:/PYTHON/Flow_Direction.gdb"
#arcpy.env.overwriteOutput = True

#Setting the containers
Pipes = r"J:\PYTHON\Flow_Direction.gdb\Pipes"
Nodes = r"J:\PYTHON\Flow_Direction.gdb\Nodes"
MidList = []

#Getting the mid point
Cursor = arcpy.SearchCursor(Pipes)
    for i in Cursor:
    Midpoint = i.shape.positionAlongLine(0.50,True).firstPoint
    MidList.append(Midpoint)

print ("done")

Tags: theenv脚本true列表flowcursornodes
1条回答
网友
1楼 · 发布于 2024-09-29 23:19:16

试试这个:

import arcpy, os
Pipes = r"H:\My Documents\GDB.gdb\Pipes"
MidList = []

Cursor = arcpy.SearchCursor(Pipes)
for i in Cursor:
    Midpoint = i.shape.positionAlongLine(0.50,True).firstPoint
    point = arcpy.Point(Midpoint.X, Midpoint.Y)
    pointGeom = arcpy.PointGeometry(point)
    MidList.append(pointGeom)

arcpy.CopyFeatures_management(MidList, os.path.join(os.path.split(Pipes)[0], "Nodes"))

相关问题 更多 >

    热门问题