I am using this code in "Calculate Field" to calculate the lat and long and re project the coordinates so I figure it has to be something similar.
arcpy.PointGeometry(!SHAPE!.firstPoint,!SHAPE.spatialReference!).projectAs(arcpy.SpatialReference(4326)).firstPoint.Y
Solved! Go to Solution.
Why both writing any code, simply call the Add Geometry Attributes (Data Management) tool?
Did you look at the polyline class?
projectAs (spatial_reference, {transformation_name}) | Projects a geometry and optionally applies a geotransformation. To project, the geometry needs to have a spatial reference, and not have an UnknownCoordinateSystem. The new spatial reference system passed to the method defines the output coordinate system. If either spatial reference is unknown the coordinates will not be changed. The Z- and measure values are not changed by the ProjectAs method. |
Why both writing any code, simply call the Add Geometry Attributes (Data Management) tool?
Hi there, before I had raised the question, we had attempted to use the Add geometry attributes tool. However, when we changed the projection, it would not honor it. You can set the output value and it would still calculate the length in the original feature class projection. Based on this, we ended up creating a variable of a spatial reference (SR) in model builder, and selected the desired output coordinate system. In the "calculate length" (data management) tool, we added the following expression: !SHAPE!.projectAs("%SR%").length and that seem to do the job.
Thanks!