MapInfo Pro

Expand all | Collapse all

Select shared borders of polygons

  • 1.  Select shared borders of polygons

    Posted 01-04-2021 14:29
    How can I select the portion of a polygon that shares a border with another polygon?  Specifically, how can I select the shared border of two counties?

    I'd like to have a different style for the portions that share a border with another county.  I don't want to include portions of the county that border water such as a river within the county or a lake on the edge of the county.

    I have a Counties table with one record for each county and each county is a single object.  My first idea was to convert the region/polyline object to lines, then use this SQL to select lines that intersect another line in a different county. 

    Select *
    From Counties, Counties2
    WHERE Counties.A2_Code <> Counties2.A2_Code
    and Counties.Obj Intersects Counties2.Obj
    Into Selection​

    I tried it on a sample of two counties, and it took 13 minutes.  The whole US or even a single state would take forever.

    Is there another/better way to do this?

    Daniel Ems
    Louisville KY

  • 2.  RE: Select shared borders of polygons

    Posted 01-05-2021 09:06
    Edited by Peter Horsbøll Møller 01-05-2021 09:10
    Hi Daniel

    13 minutes for two counties sounds like a long time. I must admit that it's not a fast process but I was able to perform a similar operation for the 99 municipalities in Denmark. This took around 23 minutes and resulted in 372 borders.

    The red lines are the internal borders between the municipalities, and where there is only a blue line visible, that's where the municipality border water and a neighboring country.

    I'm using MapInfo Pro v2019 and can take advantage of the new option to create a derived spatial object in my query. This means that I can use the polygons as they are and create the borders as a polyline.

    I create a small buffer of 5 cm around the boundary and only keep the part of the neighboring boundary that is within this slightly bigger boundary.

    One issue with the query above is that I'll create two border lines for all borders, one from each side of the borderline. I tried to change the last condition from t1.SomeIDColumn <> t2. SomeIDColumn to t1.SomeIDColumn < t2. SomeIDColumn. This should limit the query to only return the borderlines from one of the two sides, and it also speeds up the processing as there are fewer joins to consider.

    The query returned 186 records in 19 minutes.

    Here's the final query I used:
    Select t1.KOMKODE + "-" + t2.KomKode "BorderName"
    , Overlap(CartesianBuffer(t1.obj, 12, 5, "cm"), ConvertToPline(t2.obj)) object
    From Kommune_99_poster As "t1", Kommune2 As "t2"
    Where t1.KOMKODE < t2.KomKode
    And t1.Obj Intersects t2.obj
    Into Selection

    I don't want to estimate how long it will take to do this for all counties in the US...

    One way that might boost the performance would be to create a MapBasic application to run through each polygon at a time and delete this to avoid it being used again.

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

  • 3.  RE: Select shared borders of polygons

    Posted 01-06-2021 08:50
    just a thought- If your ultimate aim is to produce the set of all boundaries which do not intersect a body of water, perhaps it would be more efficient to check for intersects with a water dataset, and then what's left is your answer? Unless you were looking at really small watercourses I suspect there would be less length of border to check that way? Or at least less combinations to consider.

    Martin Burroughs
    Oldham Council