-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_overlaps.py
51 lines (38 loc) · 1.32 KB
/
main_overlaps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import folium
from shapely.geometry import Polygon
from shapely.ops import cascaded_union
import database
m = folium.Map(location=[48.721900, 21.257537], zoom_start=14)
def overlap_polygons(po1, po2):
diff = po2.difference(po1)
return po2.difference(diff)
# change these values to modify the visualization
data = [["Pošty", "fifteen"], ["supermarket", "five"], ["fast_food", "ten"], ["cafe", "ten"],
["Všeobecná ambulancia pre deti", "ten"], ["MS_štátna", "five"]]
polygons = []
for i in data:
polygons.append(cascaded_union([Polygon(x) for x in database.retrieve(i[0], i[1])]))
overlap = None
for polygon in polygons:
if overlap is None:
overlap = polygon
else:
overlap = overlap_polygons(overlap, polygon)
lst = list(overlap.geoms)
for i in lst:
geo_data = {"type": "FeatureCollection", "features": []}
geo_data["features"].append({
"type": "Feature",
"id": "0",
"properties": {
"name": "visual"
},
"geometry": {
"type": "Polygon",
"coordinates": [
list(i.exterior.coords)
]
}
})
m.add_child(folium.Choropleth(geo_data=geo_data, fill_opacity=0.4, line_opacity=0.1, fill_color="red"))
m.show_in_browser()