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"}
}
]
}