1

I have a list of shapely polygons present in a list (around 12k). Many of the polygons in this list overlap with each other. The task I need to perform is to create a dictionary with the indexes of polygon which satisfy a certain overlapping threshold. For e.g. if polygon1 overlaps with polygon5 and polygon6 and polygon2 overlaps with polygon10 and polygon3, polygon4 does not overlap with any other polygon then the dictionary should be like

{1: [5, 6],
 2: [3, 10],
 3: [],
}

The overlapping criteria used to determine if the polygons should be merged is intersection of the polygons divided by the area of the smaller polygon. Also, getting a list of all the merged polygons will also help.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Ahmad Javed
  • 544
  • 6
  • 26
  • The task to find overlapping polygons in given collection is somewhat popular, so this looks like common algorithmic problem - and thus you should include your own attempt. Nobody's going to write the code for you. You may want `geopandas.overlay`, for example, and then filter result by intersection area - but again, please show what you've tried so far. – STerliakov Aug 24 '22 at 19:03

2 Answers2

0

This algorithm may be the solution for your problem, since it is an instance of a polygon-clipping-problem. This could be helpful A simple algorithm for polygon intersection too.

DrGregoryHouse
  • 510
  • 5
  • 12
0

I have got a similar problem. Find duplicate geometries and mark them out, solved by geopandas accessor duplicated_geometry_groups.

    >>> import dtoolkit.geoaccessor
    >>> import geopandas as gpd
    >>> from shapely.geometry import Polygon
    >>> df = gpd.GeoDataFrame(
    ...     geometry=[
    ...         Polygon([(0,0), (1,0), (1,1), (0,1)]),
    ...         Polygon([(1,1), (2,1), (2,2), (1,2)]),
    ...         Polygon([(2,2), (3,2), (3,3), (2,3)]),
    ...         Polygon([(2, 0), (3, 0), (3, 1)]),
    ...     ],
    ... )
    >>> df
                                                geometry
    0  POLYGON ((0.00000 0.00000, 1.00000 0.00000, 1....
    1  POLYGON ((1.00000 1.00000, 2.00000 1.00000, 2....
    2  POLYGON ((2.00000 2.00000, 3.00000 2.00000, 3....
    3  POLYGON ((2.00000 0.00000, 3.00000 0.00000, 3....

    - 0 and 1 are intersecting.
    - 1 and 2 are intersecting.
    - 3 is alone.

    So there are two groups: ``(0, 1, 2)`` and ``(3,)``.

    >>> df.duplicated_geometry_groups()
    0    0
    1    0
    2    0
    3    1
    dtype: int64

    ``index`` is the index of inputting, ``values`` is the labels of groups.
    And labels are natural numbers.
40Percent
  • 21
  • 7