For your information, the source code for my tools can be found on GitHub. So you can grab the source code for the function from the OBJLib.mb. Here the procedure is called OBJDirection
.
Original Message:
Sent: 01-23-2025 05:38
From: Ryan Cook
Subject: Line Direction
Include "MAPBASIC.DEF"Dim Linktab, DirPath, SavePath, ImportPath, Cmd_String as StringLinkTab = Input("Link Table", "_Table:", "table", "TableInfo(ScriptContext(2)")If Not CommandInfo(CMD_INFO_DLG_OK) then Note "Exiting!" End Program Else End ifPrint "Add fields for processing..."Alter Table LinkTab (add Angle float, Bearing char(1), DirCode char(50), Dir_Of_Travel char(1))Print "Finding Dual Carriageways..."Select * from LinkTab where description = "Dual Carriageway" into _DUALSPrint "Upating Angle with direction drawn..."cmd_String = "Update _DUALS set Angle = DtLineDirection(obj)"Run Command cmd_StringPrint "Grouping Angles into 4 Bearings..."Select * from _DUALS where Angle >= 45 and Angle < 135 into _UPDATEUpdate _UPDATE set Bearing = "N"Select * from _DUALS where Angle >= 135 and Angle < 225 into _UPDATEUpdate _UPDATE set Bearing = "W"Select * from _DUALS where Angle >= 225 and Angle < 315 into _UPDATEUpdate _UPDATE set Bearing = "S"Select * from _DUALS where Angle >= 315 and Angle < 360 into _UPDATEUpdate _UPDATE set Bearing = "E"Select * from _DUALS where Angle >= 0 and Angle < 45 int _UPDATEUpdate _UPDATE set Bearing = "E"Commit Table LinkTabPrint "Concatenating Bearing with Directionality for DirCode..."Update _DUALS set DirCode = Bearing + "|" + DirectionalityPrint "Creating To and From values based on DirCode..."Select * from _DUALS whereDirCode = "N|In Direction" orDirCode = "S|In Opposite Direction" orDirCode = "E|In Direction" orDirCode = "W|In Opposite Direction"into _UPDATEUpdate _UPDATE set Dir_of_Travel = "T"Select * from _DUALS whereDirCode = "S|In Direction" orDirCode = "N|In Opposite Direction" orDirCode = "W|In Direction" orDirCode = "E|In Opposite Direction"into _UPDATEUpdate _UPDATE set Dir_of_Travel = "F"Commit Table LinksTabClose Table _UpdateClose Table _DUALSNote "Complete!"
------------------------------
Ryan Cook
ORH LTD
Original Message:
Sent: 01-23-2025 05:37
From: Ryan Cook
Subject: Line Direction
Update: Free beers confirmed.
It does exactly what I want with minimal fuss! Basically, I've been trying to split all dual carriageways pairs into separate batches. With HERE data, this is easy as they have a value called Dir_Of_Travel with either side of dual carriageways always carrying different values ("To" or "From"). But with Ordinance Survey data, they only have a "Directionality" field which rather stupidly relates traffic flow with the direction the technician randomly chose to draw the line (so its either "In Direction" - traffic flows in the same way they drew the line, or "In Opposite Direction", traffic flows against the direction the line was drawn). As both sides of a dual carriageway could be digitised in the direction of the traffic flow, they could both have the same value and therefore could not be separated. At least, not without knowing the direction the line was digitised!
Here is my code, which basically uses your DtLineDirection function to establish an angle, which I then group into 4 compass bearings, which I then concatenate with the results of DtLineDirection to yield a DirCode I can convert to a "To" and "From" distinction for all pairs.
Checked it and it has worked! Thanks again Peter, your tool was a huge help!
------------------------------
Ryan Cook
ORH LTD
Original Message:
Sent: 01-22-2025 07:43
From: Peter Møller
Subject: Line Direction
Now I hope it works as you hope, Ryan :-)
I like a good English beer. And a free English beer tastes even better ;-)
Let us know how it works out for you
Peter
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 01-22-2025 07:17
From: Ryan Cook
Subject: Line Direction
Oh my god, if this is true you may consider me a source of free beer anytime you are in the UK, Peter! This could save me a crazy amount of work! Can I run that function from inside a MapBasic program?
------------------------------
Ryan Cook
ORH LTD
Original Message:
Sent: 01-22-2025 04:46
From: Peter Møller
Subject: Line Direction
Hi Ryan
Download DrawTools from the MapInfo Marketplace.
When DrawTools has been loaded into MapInfo Pro, you will see a new function in the function list called DTLineDirection
.
You can use this to update a column with the direction of the line/polyline.
Update PIPES Set DIR = DTLineDirection(OBJ)
The direction is calculated as the direction between the first and last node of the first segment of a polyline.
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
Original Message:
Sent: 01-21-2025 12:26
From: Ryan Cook
Subject: Line Direction
Hi,
Can anyone explain to me how MapInfo is able to instantaneously show the line direction of a layer with a click of the button "Show Line Direction"? Seems to work for both lines and polylines. Yet I can't work out where this value is stored in the object geography. I basically want to populate a field with a value indicating the direction a polyline was digitised.
Alternatively, I'd be happy just knowing the angle of the polyline, or the angle the end point is from the start point. I guess I could query the segs and get the start/end x,y of the first seg and last seg, but it seems I'm working awfully hard to get something that MapInfo already seems to "know" via the "Show Line Direction".
Thanks in advance for any advice
Ryan
------------------------------
Ryan Cook
ORH LTD
------------------------------