AnsweredAssumed Answered

Python and calculating the X and Y coordinates of line start and line end.

Question asked by grparent on Oct 12, 2012
Latest reply on Oct 12, 2012 by grparent
Hello ArcGIS Forum Users,
I have been able to use Python to copy a polyline dataset and add four fields (FROM_X, TO_X, FROM_Y, TO_Y) but am having trouble with populating the fields with the appropriate information. I would like to use Python to populate them in the following manner:

FROM_X = X Coordinate of Line Start
TO_X = X Coordinate of Line End
FROM_Y = Y Coordinate of Line Start
TO_Y = Y Coordinate of Line End

I know it can be done manually by opening the datasets attribute table, right clicking on a field, selecting Calculate Geometry and then the appropriate Property but I would like to have a Python script be able to do this so it can be embedded in a SAS script. The COPY and ADD FIELD Python script works in SAS so I am hoping the CALCULATE FIELD will as well.

I tried using the Data Management - Fields - Calculate Field and its Python option for FROM_X using:

arcpy.CalculateField_management(dataset, fieldname, !FROM_X!.firstpoint.x,"PYTHON_9.3","") 


The script runs without errors but does nothing to my dataset. I suspect I am missing a step but do not know what to do next.

Any input you may provide is greatly appreciated.

Thank you.

Greg Parent

Outcomes