2

Using code I found on Creating point at midpoint of polyline with ArcPy?, I've gotten my code to generate midpoints due to the 0.50 parameter in the position along line tool (below). BUT. I don't want to generate a specific percentage every time. I want to call the percentage in "duration_fraction" associated with each polyline (below), and put it in as the percentage in the points. So Polyline 1 would generate a point 86% of the way along the line. How should I go about this? Can I use a search cursor within a search cursor? enter image description here

in_data = "L:\\gathr\\indonesia\\Sara\\Lines_withinTimes\\Day_andmmsi\\s20160101fc_lines.gdb\\Detection1_lines_UTM"
detectpoint = "L:\\gathr\\indonesia\\Sara\\Lines_withinTimes\\Day_andmmsi\\s20160101fc_lines.gdb\\MEOWWW"
polyline = "L:\\gathr\\indonesia\\Sara\\Lines_withinTimes\\Day_andmmsi\\s20160101fc_lines.gdb\\Detection1_lines_UTM"

#housekeeping
arcpy.DeleteFeatures_management(detectpoint)
arcpy.env.overwriteOutput = True

#generating the mid point
with arcpy.da.SearchCursor(polyline, "SHAPE@") as in_cursor, \
arcpy.da.InsertCursor(detectpoint, "SHAPE@") as out_cursor:
    for row in in_cursor:
        fraction = row.getValue("duration_fraction")
        midpoint = row[0].positionAlongLine(0.50,True).firstPoint
        out_cursor.insertRow([midpoint])
  • 1
    You can but you shouldn't. Create a dictionary from one of the cursors and then use that inside the other instead. – PolyGeo Oct 13 '16 at 20:16

1 Answers1

2

Based on your code it seems you need 1 point per line. I suggest adding field X to your table and populate it using Python parser:

!Shape!.positionAlongLine ( !Shape!.length* !Percent! /100).firstPoint.X

Do similar thing for new field Y.

Export table and use Make XY event layer to plot your points. Export to feature class if necessary

FelixIP
  • 22,922
  • 3
  • 29
  • 61