MapInfo Pro

Expand all | Collapse all

Chechin topology - self intersecting lines

  • 1.  Chechin topology - self intersecting lines

    Posted 11-21-2019 18:49
    Edited by Cintia Mateo Rodriguez 11-21-2019 19:48
    ​Hi everybody,

    I just joined to this forum.

    Here is my first question.

    I have vectorial layer with line work, representing roads.
    is there a tool in MapInfo that can identify lines that are self intersecting themselves?
    I am after identifying what roads are self intersecting themselves, which would mean that there is a error.
    I cant find a tool in MI to do this.

    can anybody help me please ?


    Cintia Mateo Rodriguez
    Knowledge Community Shared Account

  • 2.  RE: Chechin topology - self intersecting lines

    Posted 11-25-2019 17:19
    Ms. Rodriguez,
    To my knowledge, there is no "tool" built into MapInfo Pro to do this but there are functions and SQL you can use.
    At the heart of this is a function called IntersectNodes() which takes 2 geometries and some flags for the kind of intersection required.

    In your case you are looking for self intersections so the 2 geometries would be the same. And the ​flag would be

    "INCL_CROSSINGS" which has a value of 1.  This  returns points where segments cross.

    The returned geometry is a polyline as that was the simple way of returning a set of points in mapbasic. However, the returns are just a list of points.
    For example,  if a polyline had a clear intersection as in this picture:

    example of self-intersecting polygline

    then the expression IntersectNodes(obj, obj, 1) would return a polyline of 1 point at the place of intersection.
    Also note that any polyline can be queried for how many nodes it has with ObjectInfo(obj, 20)  .
    (OBJ_INFO_NPNTS in MapBasic). This will be useful for distinguishing returns that are empty (no self-interesections) from those that do have them.  

    How can you use this to find the problems?
    One way would be to create an integer column in your table and then use the Update Column feature to update this new column with this expression

    ObjectInfo(IntersectNodes(obj, obj, 1), 20) .

    This will populate the entire table that you pick with a integer value which should mostly be 0. That is, when there are no self-intersections, IntersectNodes returns an empty polyline that has no nodes.  If there is 1 or more those are objects with self-intsersections and you can sort and find and fix them. You can rerun the command as you fix things.

    You can also do a SQL command and not add a column to your table with a bit more work.
    select * from table where   int(objectinfo(Intersectnodes(obj, obj, 1), 20)) > 0
    Any returned records should have self-intersections.   Note you need the "Int" around the expression because ObjectInfo() return different types based on the parameters and this clarifies that the answer is an integer for the SQL engine.

    Either of these methods should help you identify the self-intersecting polylines.  My only word of caution would be for records where the segments merely touch but do not cross or in rare cases where the segment doubles back on itself. Those are a bit harder to detect.

    Eric Blasenheim
    Spectrum Spatial Technical Product Manager
    Troy, NY