MapInfo Pro

 View Only

MapInfo Monday: Count Overlapping Objects

  • 1.  MapInfo Monday: Count Overlapping Objects

    Employee
    Posted 11-27-2023 03:12

    Happy #MapInfoMonday!

    There are times when you don't only want to know where polygons overlap, but you want to know how many polygons overlap in which places.

    This could be that you are investigating biodiversity and want to understand the number of species in certain locations. The spread of the individual species is registered in polygons. Or maybe you are investigating the network coverage of your mobile network and want to understand how good your coverage is.

    In my example, I'm starting with several points for which I know the coverage in meters.

    If these were mobile cell towers, the coverage would of course be theoretical as the coverage is highly dependent on the area around the cell towers.
    I'll use the Buffer Table control from the Spatial tab to create buffers from these points in a new table.
    I'll use the values in my column Distance to determine the size of each buffer. I set this in the Buffer Objects dialog.
    My resulting buffers look like below.
    If your input is polygon-based, you should start here.
    With the Info Tool you can manually check the number of overlaps by clicking where you expect an overap. The Info Window will now tell you how many records are found in the layer.
    Make sure you are working with a copy of your table as we will modify the input polygons.
    With a table of polygons, make the layer editable select them all, and set them to the current target.
    Now select all the polygons from the table again, and use Split Target from the Spatial tab.
    Your data has now been split by itself making sure that any overlapping polygons how been split into separate polygons as you can see in the map below.
    The only thing left is to run a query that will calculate the number of polygons on top of each other.
    To do this, we will group the table using the centroid of the polygons.
    This is the query we will be using:
    Set Coordsys Table Known_Locations
    Select CentroidX(b.obj) "X"
      , CentroidY(b.obj) "Y"
      , Count(*) "NumOverlaps"
      , AggregateCombine(obj)
    From Known_Locations_Buffer As "b"
    Group By X, Y
    Into __Count_Overlaps

    A couple of things to note:

    1. We set the coordinate system to match the coordinate system of the table.
    2. We extract the coordinates of the centroids using the two functions CentroidX() and CentroidY().
    3. Also, note that we give these the column aliases "X" and "Y".
    4. We use the aggregate Count(*) to count the number of overlapping polygons with the same centroid coordinates.
    5. We use the spatial aggregate AggregateCombine() to include a spatial object in the query result.
    6. We group the results using the two columns X and Y.

    I'll add the resulting query to my map and add a theme where I colorize the polygons based on the number of overlaps.

    Have fun!


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