Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to write a python script to determine flow direction on a water pipe network. I've used this script to find the mid point along each polyline, now i need to convert this data into a point feature class, which will become an arrow of flow direction.

I've tried saving it as a list but cannot convet the list to a point feature. Can anyone suggest ways to save the mid point locations as a point feature class?

  #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")       
share|improve this question

3 Answers 3

You need to open an InsertCursor on the other feature class:

import arcpy

pipes = r"J:\PYTHON\Flow_Direction.gdb\Pipes"
nodes = r"J:\PYTHON\Flow_Direction.gdb\Nodes"

#Getting the mid point
with arcpy.da.SearchCursor(pipes, "SHAPE@") as in_cursor, \
     arcpy.da.InsertCursor(nodes, "SHAPE@") as out_cursor:
    for row in in_cursor:
        midpoint = row[0].positionAlongLine(0.50,True).firstPoint
        out_cursor.insertRow([midpoint])

print ("done")       
share|improve this answer

If using ArcPy for this is not a mandatory requirement, and if you have an Advanced (formerly called ArcInfo) level license, then there is an out-of-the-box tool called Feature Vertices To Points (Data Management) that has a MID option:

MID —A point will be created at the midpoint, not necessarily a vertex, 
of each input line or polygon boundary. 
share|improve this answer

You can do it using FeatureVerticies to Points (as mentioned above) - using your code and 1 line addition.

#FlowArrows.py
import arcpy

#setting the environment
arcpy.env.workspace = "J:/PYTHON/Flow_Direction.gdb"

#Setting the containers
Pipes = r"J:\PYTHON\Flow_Direction.gdb\Pipes"

# This will give you the mid point - which is not necessarily a vertex on the line.
arcpy.FeatureVerticesToPoints_management(Pipes, "ARROW_PNTS", "MID")

You can also use the answer in this post using SHAPELY module to find a point at a given distance along a line:

Get a point on a polyline from end points given distance along poly line

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.