MapInfo Pro

 View Only

MapInfo Monday: Creating a Point along a Line

  • 1.  MapInfo Monday: Creating a Point along a Line

    Employee
    Posted 01-16-2023 04:57
    Edited by Peter Møller 02-03-2023 02:36
    Happy #MapInfoMonday!

    In today's post, I will address a question that came through the MapInfo-L: Capturing a point (XY coordinates) along a line. Ian Oldfield posted the question​ but I thought the solution might be helpful for others too.

    Ian used the DistanceCalculator to create lines between addresses and the nearest road. So that's also what I did.

    In the Distance Analysis dialog, I first calculated the nearest distance from my addresses to my roads via the Calculate button. After this, I used the Save Results button to save the result into a native tab file. The resulting table contains lines from my address points to the nearest location on the roads as you can see in the map below.

    It is essential to note the direction of the line as we want to create a point some meters from the last point - the point on the road.

    The next step requires an add-in for MapInfo Pro: WindowHelper. You can find this tool in the MapInfo Marketplace from where you can install and load it via a single click.

    WindowHelper publishes a number of useful custom MapBasic functions to the MapInfo Pro interface so that you can use these in label expressions, update statements, and more.

    The specific function we are after is called WHCartesianCreatePointAlong. It allows you to create a point along an existing polyline from the first point of the polyline. As we are looking to create a point from the last point, we can either reverse the direction of the polyline or calculate the length of the polyline and subtract the desired distance from this distance. In my example, I have chosen the first option.

    As these processes run in a MapBasic application it can be necessary to tell the application to use a specific coordinate system. This is the case in our example. To do so, WindowHelper also has a function that lets you set the coordinate system by referring to an open table. Also, note that the function WHCartesianCreatePointAlong only works with projected data. It doesn't work with data stored in Longitude/Latitude, hence the Cartesian prefix.

    I save a copy of the table as I'm about to update the objects stored in the table. The table I'll be updating is called RoadPoint.

    I open the SQL Window and open a new Update statement and modify this to look like this:
    Set CoordSys Table RoadPoint
    Print WHSetCoordsysUsingTable("RoadPoint")
    Update RoadPoint
      Set OBJ = WHCartesianCreatePointAlong(WHObjectReverse(OBJ), 3, 0)

    The first two statements set the coordsys in MapInfo Pro aan in the WindowHelper application to match the coordsys of the table RoadPoint.

    The Update statement converts the existing polyline to a point 3 meters from the last point. Notice how I use the function WHObjectReverse to reverse the line direction of the object I pass to the function WHCartesianCreatePointAlong. This makes the function calculate the distance from the last point instead of the first point.

    In the map below, you can see the new points created on the line 3 meters from the road.

    I hope this comes in handy.

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