Alteryx designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer.
SOLVED

Get polyline direction/orientation as a numeric field

Meteor

Hi Alteryx Commuity,

I am working with road network data and am trying to determine the travel direction of a vehicle based on the coordinates (lat, long) of a track (polyline). I have a python code I used to use in ArcGIS and I am trying to translate it into the Alteryx environment.

Python code is as follows:

360 + math.degrees(math.atan2((!Shape.lastpoint.X! - !Shape.firstpoint.X!),(!Shape.lastpoint.Y! - !Shape.firstpoint.Y!))) if math.degrees(math.atan2((!Shape.lastpoint.X! - !Shape.firstpoint.X!),(!Shape.lastpoint.Y! - !Shape.firstpoint.Y!))) < 0 else math.degrees(math.atan2((!Shape.lastpoint.X! - !Shape.firstpoint.X!),(!Shape.lastpoint.Y! - !Shape.firstpoint.Y!)))

My Alteryx translations is as follows and gives me an error (Malformed Function Call):

IF ATAN2((ST_EndPoint([SpatialObj]) - ST_StartPoint([SpatialObj]))<0 THEN 360 + ATAN2((ST_EndPoint([SpatialObj]) - ST_StartPoint([SpatialObj])) ELSE ATAN2((ST_EndPoint([SpatialObj]) - ST_StartPoint([SpatialObj])) ENDIF

I know that ATAN2 needs an x, y, but how do I do this with a spatial object? Or is there an easier way around this?

Thanks

Highlighted
Alteryx Alumni (Retired)

If you have a spatial object, but don't have the x/y coordinates, but need them, you can get those with the Spatial Info tool.

Then it seems like you would just substitute those for the x/y as you have in the original expression.

Highlighted
Meteor

Thanks that might be a workaround. Do you know how the Alteryx Spatial Info tool decides where the start and the end is in a polyline that has been created outside of Alteryx?

Highlighted
Alteryx Alumni (Retired)

Sorry, that one I don't know.

I'll see if I can find out from within our Product team.

Highlighted
Alteryx Alumni (Retired)

This is from the Product Development team...

The polyline in Alteryx will be defined in the same order as it was in the file we read it from.  So the start is the first point listed in the file, and the end is the last.

Highlighted
Alteryx

You may also want to take a look at the Poly Split tool, which can split a line into a set of ordered points. You could then use the Distance tool to find the degrees and the cardinal direction between any two points you wish.

Labels