1

I work for a utility company and we have a number of poles that did not have their GPS locations taken, rather where the line turns the GPS location was taken, and the span of each pole in between each "angle" pole was calculated.

I ran the point to line function to create the line that runs between the GPS'd points and am currently working on a single span where the poles all line up in a straight line (I plan to expand this script to populate multiple spans after their angles change). I have line name, pole number (the points), and the distance to the next pole (in feet, which I convert to meters) in a .csv file. I have calculated the angle of the line and used trig functions to calculate the position of the next point (I'm using UTM zone 14 so it's a grid). When I run the script, as I have it now, it places the first point exactly where it should be, based on the location of the start of the line it follows. The problem is, the way the script is written it places all the points the distance in the .csv file away from the START point of the line. What I'm stuck on is placing the point the distance in the .csv from the PREVIOUS point that I populate in the update cursor, instead of from the initial point.

Here is the script as I currently have it.

# Import system modules
import arcpy
import math
import csv
from arcpy import env
#Set Variables
input_line = r"P:\Scripts\missing_poles\missing_poles.gdb\missing_poles_script\angle_line"
angle_field ="Angle"
rotationMethod = "GEOGRAPHIC"
coordSystemField = "UTM"
pole_distance_file = r"P:\Scripts\missing_poles\missing_poles_demo_no_empty.csv"
new_points = r"P:\Scripts\missing_poles\missing_poles.gdb\missing_poles_script\updated_poles"
#Create Field to add line angle too
arcpy.AddField_management (input_line, angle_field, "FLOAT")
#Calculate the angle of the line
for row in arcpy.da.SearchCursor(input_line, ["OID@", "SHAPE@"]):
 # Print the current line ID
 print("Feature {0}:".format(row[0]))
 #Set start point
 startpt = row[1].firstPoint
 #Set Start coordinates
 startx = startpt.X
 starty = startpt.Y
 #Set end point
 endpt = row[1].lastPoint
 #Set End coordinates
 endx = endpt.X
 endy = endpt.Y
 #calculate xy of new points
 radian = math.atan((startx-endx)/(starty-endy))
 with open(pole_distance_file) as csvfile:
 readCSV = csv.reader(csvfile, delimiter=',')
 for row in readCSV:
 #convert span ahead to meters
 span_ahead = (float(row[2])*0.3048)
 pole_id = row[1]
 #calculate x and y coordinates
 x = (math.sin(radian)*span_ahead)+ startx
 y = (math.cos(radian)*span_ahead)+ starty
 #update Feature Class with new coordinates
 new_coordinates = (x,y)
 print new_coordinates
 cursor = arcpy.da.InsertCursor(new_points, ["SHAPE@XY"])
 cursor.insertRow ([new_coordinates]

And here is the .csv file I'm working off of.

555B,65,475
555B,66,455
555B,67,430
555B,68,355
555B,69,490
555B,70,450
555B,71,400
555B,72,460
555B,73,450
555B,74,495
555B,75,430
555B,76,455
555B,77,495
555B,78,465
555B,79,495
555B,80,470
555B,81,490
555B,82,478
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Nov 7, 2017 at 22:50

1 Answer 1

1

Reset your startx and starty in your csv loop:

#calculate x and y coordinates
x = (math.sin(radian)*span_ahead)+ startx
y = (math.cos(radian)*span_ahead)+ starty
# Reset startx and starty for next record in loop
startx = x
starty = y

Now the next record in the loop will use this record's x and y values as the start point.

answered Nov 8, 2017 at 3:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.