MapInfo Pro Developers User Group

Expand all | Collapse all

How do I find the mid point of a line along the line

  • 1.  How do I find the mid point of a line along the line

    Posted 11-02-2018 01:02

    I need to find the midpoint (not centroid) of a line on the line and get the x and y coordinates.

     

    In SQL (Server) I see there are some options - https://ask.sqlservercentral.com/questions/87890/how-do-i-find-a-point-half-way-between-2-points.html

     

    Also in QGIS -https://gis.stackexchange.com/questions/258308/create-mid-point-from-line-layer/258317

     

    Is there a tool in Mapinfo (ideally Mapbasic) for this?



  • 2.  RE: How do I find the mid point of a line along the line

    Posted 11-07-2018 04:07

    Have a look at this function in the OBJLib that can be found on Github:

    Function OBJCartesianCreatePointAlong

    ( ByVal oPolyline As Object 'The polyline to create the point along

    , ByVal fDistance As Float 'Distance along polyline, can also be negative

    , ByVal fOffset As Float 'Offset from polyline, negative is left, positive is right

    ) As Object

    It doesn't give you the mid point directly but can be used to do it if you pass in the value of the distance parameter as half the object length:

    oMidPoint = OBJCartesianCreatePointAlong(oSel, CartesianObjectLen(oSel) / 2, 0)

    You can find it here on Github: https://github.com/PeterHorsbollMoller/mbLibrary.

    Look for the OBJLib.def and OBJLib.mb files.

    Note that it only supports lines and single segment polylines.