0

enter image description here

I have multipolygons as it can see in image and I would split all polygons (poly_in_1, ..., poly_in_2) that are into Polygon and there are some of polygons outside so the result should be like see in right part of image.

the data (data_pol.json) that I am showing of polygons is from (polygon, poly_in_1 and poly_out_1) but code should considere for n polygons ...

data_01 = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [[2, 2], [2, 22], [22, 22], [22, 2], [2, 2]]
                ]
            },
            "properties": {"z": 1412.5, "la": "ba"}
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [[12, 16], [7, 10], [17, 10], [12, 16]]
                ]
            },
            "properties": {"z": 1412.5, "la": "ba"}
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [[27, 15], [24, 12], [29, 12], [27, 15]]
                ]
            },
            "properties": {"z": 1412.5, "la": "ba"}
        }
    ]
}
data_01 = gpd.read_file(data_pol.json)


df.loc[0, "geometry"] = (df.loc[0, "geometry"] - df.loc[1, "geometry"])
df = df.drop(1)




the data after split polygons should be like shows final_data in JSON where coordinates of overlapping polygons was joined into one list.

final_data = {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [[27, 15], [24, 12], [29, 12], [27, 15]]
                ]
            },
            "properties": {"z": 1412.5, "la": "ba"}
        },
        {
            "type": "Feature",
            "geometry": {
                "type": "Polygon",
                "coordinates": [
                    [[2, 2], [2, 22], [22, 22], [22, 2], [2, 2]],
                    [[12, 16], [7, 10], [17, 10], [12, 16]]
                ]
            },
            "properties": {"z": 1412.5, "la": "ba"}
        }
    ]
}
  • Can you show us what you’ve tried? In your [last question](https://stackoverflow.com/questions/74526297/split-polygons-by-overlap-in-python) I showed you exactly how to do this for a pair of polygons. Have you tried to figure out how to extend this to multiple? Where are you actually stuck? – Michael Delgado Nov 23 '22 at 03:24
  • I try to do with Geopandas using data_01.overlay('geometry', how='symmetric_difference') as you can see here https://geopandas.org/en/stable/docs/user_guide/set_operations.html, but I couldnt figure out . Do you have any suggestions? –  Nov 23 '22 at 14:16
  • 1
    Please edit the question to show the full example of what you’ve tried. Thanks! – Michael Delgado Nov 23 '22 at 16:46

0 Answers0