0

I am trying to write a Python script to determine flow direction on a water pipe network. I have calculated the midpoint of each section of pipe and created a point feature class. I now need to determine the flow direction.

Originally used the Esri cartographic line feature to do this but need the flow direction to be separated from the polyline.

When I drew the pipe network it was digitized in flow direction, so all I really need to do is access the from/to field of the polyline and populate the angle field within the point feature class.

adding flow direction arrows

1 Answer 1

3

I found a similar question on a thread on the ArcGIS forums that can no longer be reached.

The solution that was used in that page requires that all lines be individual segments and not polylines. Also, the angle will be stored in an ANGLE field. That solution also populated the field in the field calculator with the following code:

Parser:

Python

Expression:

GetAzimuthPolyline( !Shape!)

Code Block:

import math
def GetAzimuthPolyline(shape):
 radian = math.atan((shape.lastpoint.x - shape.firstpoint.x)/(shape.lastpoint.y - shape.firstpoint.y))
 degrees = radian * 180 / math.pi
 return degrees

You could easily implement this in your script. I think the key is using the shape objects. That is, shape.lastpoint.x, shape.lastpoint.y, shape.firstpoint.x, and shape.firstpoint.y.

Your Answer

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

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