折线中间成为Arcpy中的点要素

时间:2013-12-17 01:33:04

标签: python arcpy

我正在尝试编写一个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")

1 个答案:

答案 0 :(得分:2)

试试这个:

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"))