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