0

I have been trying to create a script to find the start and end UTM coordinates for a line feature class in ArcMap 10.8. The server we are using has Python 2 so my script is in Python 2. I have been trying to use the ConvertCoordinateNotation_management tool with limited success.

Steps:

  1. I first found the coordinates of the start and end of the line. I have used two different ways to do this. (see code below). adds x and y coordinates for the start and end points to my FC.
  2. I then use the ConvertCoordinateNotation tool to find the UTM coordinates for each feature in the feature class created in step 1. This is done twice to try and get the UTM for the end points and the start points

Unfortunately it is only giving me the coordinates for one of the features in my feature class in the PofC file created and nothing in the PofT feature class created and the UTM coordinate that is added is incorrect. How do I get it to return UTM coordinates for all the features and for both the start points and end points?

My geographic coordinate system is GCS_North_American_1983 and my projected coordinate system is NAD_1983_BC_Environment_Albers. I know that the location of the one point it is returning is likely because of this but am unsure how to correct it.

# imports
import arcpy

#gdb = raw_input("please input the path of the GDB you are working with. >> ")
gdb = r"W:\Projects\AMD5.gdb" #for testing purposes
arcpy.env.workspace = gdb
#in_fc = raw_input("Please input the fc that requires utm coordinates. >> ").upper().strip()
in_fc = "AMD5_FC" #for testing purposes
#out_fc = raw_input("Please enter the name of the new feature class. >> ").upper().strip()
out_fc = 'test_vertices' #for testing purposes

# set parameter values
# PofC = 'PofC' 
# PofT = 'PofT'
# PofC_Y = 'START_Y'
# PofC_X = 'START_X'
# PofT_X = 'END_X'
# PofT_Y = 'END_Y'
# input_format = 'DD_2'
# output_format = 'UTM'

# arcpy.ConvertCoordinateNotation_management(in_fc, PofC, PofC_X, PofC_Y, input_format, output_format)
# arcpy.ConvertCoordinateNotation_management(in_fc, PofT, PofT_X, PofT_Y, input_format, output_format)
# print("The conversion is done.")

#####################################################################################################

arcpy.FeatureVerticesToPoints_management(in_fc, out_fc, "BOTH_ENDS")
PofC = 'PofC' 
PofT = 'PofT'
PofC_Y = 'START_Y'
PofC_X = 'START_X'
PofT_X = 'END_X'
PofT_Y = 'END_Y'
input_format = 'DD_2'
output_format = 'UTM'

arcpy.ConvertCoordinateNotation_management(in_fc, PofC, PofC_X, PofC_Y, input_format, output_format)
arcpy.ConvertCoordinateNotation_management(in_fc, PofT, PofT_X, PofT_Y, input_format, output_format)
print ("script complete.")
0

I found an answer that worked. I was unaware of the format that the vertices tool used so was inputting the wrong input format, it is not dd*-2 but SHAPE.

For anyone new to these tools like me here is what I found: NOTE: make sure that you do not have any programs open that are using the geodatabase you are working in or you will get a schema lock error.

The first tool (FeatureVerticesToPoints_management) creates a new point feature class for the line vertices. Keep in mind that this tool will not overwrite a previous version of a feature class so if you have a file with the same name in the gdb it will give you an error. There are NO coordinates in the feature class yet.

The next tool (AddXY_management) adds an x and y field in the new feature class and populates the X and Y coordinates into it.

The third tool (ConvertCoordinateNotation_management) converts these xy coordinates to UTM coordinates and puts them along with the zone information in a new field. For example 10U 568062 5466526

Lastly I created a new field and populated it with coordinates less the zone value (as I do not need that)

imports

import arcpy

gdb = raw_input("please input the path of the GDB you are working with. >> ")

arcpy.env.workspace = gdb

in_fc = raw_input("Please input the fc that requires utm coordinates. >> ").upper().strip()

out_fc = raw_input("Please enter the name of the new start and end point feature class. eg) R18564_amd5_vertices >> ").upper().strip()

arcpy.FeatureVerticesToPoints_management(in_fc, out_fc, "BOTH_ENDS") #creating point fc from line fc

arcpy.AddXY_management(out_fc) #creating points for each vertex

verts = ("{}_VERTS".format(in_fc))

y_field = 'POINT_Y'

x_field = 'POINT_X'

input_format = 'SHAPE'

output_format = 'UTM'

arcpy.ConvertCoordinateNotation_management(out_fc, verts, x_field, y_field, input_format, output_format)#takes out_fc (from vertices tool) and writes out to verts

coord = arcpy.AddField_management (verts, "Coords","TEXT", "","",25)

expression = '!UTM!.split(" ")[1] + ", " + !UTM!.split(" ")[2]'

arcpy.CalculateField_management(verts, "Coords", expression, "PYTHON_9.3")

print ("script complete.")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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