2013-12-17 49 views
0

我正在嘗試編寫一個python腳本來確定水管網上的流向。我已經使用這個腳本來查找每條多段線的中點,現在我需要將這些數據轉換爲點要素類,這將成爲流向的箭頭。在Arcpy中將多段線轉換爲點要素

我試過將它保存爲一個列表,但無法將列表轉換爲點要素。任何人都可以建議將中點位置保存爲點要素類的方法嗎?

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

回答

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