MapInfo Pro

 View Only
  • 1.  Line Direction

    Posted 16 days ago

    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
    ------------------------------


  • 2.  RE: Line Direction

    Employee
    Posted 16 days ago

    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
    ------------------------------



  • 3.  RE: Line Direction

    Posted 15 days ago
    Edited by Ryan Cook 15 days ago

    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
    ------------------------------



  • 4.  RE: Line Direction

    Employee
    Posted 15 days ago

    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
    ------------------------------



  • 5.  RE: Line Direction

    Posted 14 days ago

    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
    ------------------------------



  • 6.  RE: Line Direction

    Posted 14 days ago
    Include "MAPBASIC.DEF"
    
    
    Dim Linktab, DirPath, SavePath, ImportPath, Cmd_String as String
    
    LinkTab = Input("Link Table", "_Table:", "table", "TableInfo(ScriptContext(2)")
    If Not CommandInfo(CMD_INFO_DLG_OK) then Note "Exiting!" End Program Else End if
    
    Print "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 _DUALS
    
    Print "Upating Angle with direction drawn..."
    cmd_String = "Update _DUALS set Angle = DtLineDirection(obj)"
    Run Command cmd_String
    
    Print "Grouping Angles into 4 Bearings..."
    Select * from _DUALS where Angle >= 45 and Angle < 135 into _UPDATE
    Update _UPDATE set Bearing = "N"
    
    Select * from _DUALS where Angle >= 135 and Angle < 225 into _UPDATE
    Update _UPDATE set Bearing = "W"
    
    Select * from _DUALS where Angle >= 225 and Angle < 315 into _UPDATE
    Update _UPDATE set Bearing = "S"
    
    Select * from _DUALS where Angle >= 315 and Angle < 360 into _UPDATE
    Update _UPDATE set Bearing = "E"
    
    Select * from _DUALS where Angle >= 0 and Angle < 45 int _UPDATE
    Update _UPDATE set Bearing = "E"
    
    Commit Table LinkTab
    
    
    Print "Concatenating Bearing with Directionality for DirCode..."
    Update _DUALS set DirCode = Bearing + "|" + Directionality
    
    Print "Creating To and From values based on DirCode..."
    Select * from _DUALS where
    DirCode = "N|In Direction" or
    DirCode = "S|In Opposite Direction" or
    DirCode = "E|In Direction" or
    DirCode = "W|In Opposite Direction"
    into _UPDATE
    
    Update _UPDATE set Dir_of_Travel = "T"
    
    Select * from _DUALS where
    DirCode = "S|In Direction" or
    DirCode = "N|In Opposite Direction" or
    DirCode = "W|In Direction" or
    DirCode = "E|In Opposite Direction"
    into _UPDATE
    
    Update _UPDATE set Dir_of_Travel = "F"
    
    Commit Table LinksTab
    Close Table _Update
    Close Table _DUALS
    
    Note "Complete!"


    ------------------------------
    Ryan Cook
    ORH LTD
    ------------------------------



  • 7.  RE: Line Direction

    Employee
    Posted 14 days ago

    Beautiful, Ryan,

    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.

    It uses another function MATHGetDirection from the MATHLib.mb to calculate the direction between two coordinate pairs.



    ------------------------------
    Peter Horsbøll Møller
    Principal Presales Consultant | Distinguished Engineer
    Precisely | Trust in Data
    ------------------------------