How do you calculate the length of a line using a different output coordinate system using modelbuilder?

1211
3
Jump to solution
07-26-2019 04:03 PM
SH013
by
New Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
DuncanHornby
MVP Notable Contributor

Why both writing any code, simply call the Add Geometry Attributes (Data Management) tool?

View solution in original post

3 Replies
DanPatterson_Retired
MVP Emeritus

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.

0 Kudos
DuncanHornby
MVP Notable Contributor

Why both writing any code, simply call the Add Geometry Attributes (Data Management) tool?

SH013
by
New Contributor III

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!

0 Kudos