Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
python-visualization
GitHub Repository: python-visualization/folium
Path: blob/main/tests/snapshots/modules/issue_2109.py
1602 views
1
import geopandas as gpd
2
import pandas as pd
3
4
import folium
5
6
data = {
7
"warehouses": {
8
1: ("Allentown", "Allentown", "PA", "18101", 40.602812, -75.470433),
9
2: ("Atlanta", "Atlanta", "GA", "30301", 33.753693, -84.389544),
10
3: ("Baltimore", "Baltimore", "MD", "21201", 39.294398, -76.622747),
11
4: ("Boston", "Boston", "MA", "02101", 42.36097, -71.05344),
12
5: ("Chicago", "Chicago", "IL", "60602", 41.88331, -87.624713),
13
},
14
"customers": {
15
1: ("Akron", "Akron", "OH", " ", 41.08, -81.52),
16
2: ("Albuquerque", "Albuquerque", "NM", " ", 35.12, -106.62),
17
3: ("Alexandria", "Alexandria", "VA", " ", 38.82, -77.09),
18
4: ("Amarillo", "Amarillo", "TX", " ", 35.2, -101.82),
19
5: ("Anaheim", "Anaheim", "CA", " ", 33.84, -117.87),
20
6: ("Brownfield", "Brownfield", "TX", " ", 33.18101, -102.27066),
21
7: ("Arlington", "Arlington", "TX", " ", 32.69, -97.13),
22
8: ("Arlington", "Arlington", "VA", " ", 38.88, -77.1),
23
9: ("Atlanta", "Atlanta", "GA", " ", 33.76, -84.42),
24
10: ("Augusta-Richmond", "Augusta-Richmond", "GA", " ", 33.46, -81.99),
25
},
26
}
27
28
df_customer = pd.DataFrame(
29
list(data["customers"].values()),
30
columns=["Facility Name", "City", "State", "Zip", "Latitude", "Longitude"],
31
)
32
df_customer["Facility Name"] = (
33
"CUST_" + df_customer["Facility Name"] + "_" + df_customer["State"]
34
)
35
36
df_customer_geometry = gpd.points_from_xy(df_customer.Longitude, df_customer.Latitude)
37
gdf_customer = gpd.GeoDataFrame(
38
df_customer, crs="EPSG:4326", geometry=df_customer_geometry
39
)
40
gdf_customer["Facility Type"] = "Customer"
41
42
df_warehouse = pd.DataFrame(
43
list(data["warehouses"].values()),
44
columns=["Facility Name", "City", "State", "Zip", "Latitude", "Longitude"],
45
)
46
df_warehouse["Facility Name"] = (
47
"WH_" + df_warehouse["Facility Name"] + "_" + df_customer["State"]
48
)
49
50
df_warehouse_geometry = gpd.points_from_xy(
51
df_warehouse.Longitude, df_warehouse.Latitude
52
)
53
gdf_warehouse = gpd.GeoDataFrame(
54
df_warehouse, crs="EPSG:4326", geometry=df_warehouse_geometry
55
)
56
gdf_warehouse["Facility Type"] = "Warehouse"
57
58
m = folium.Map([40, -100.0], zoom_start=5, tiles=None)
59
60
gdf_warehouse.explore(
61
m=m,
62
marker_type="marker",
63
marker_kwds=dict(icon=folium.Icon(color="red", icon="warehouse", prefix="fa")),
64
name="Warehouse",
65
)
66
67
gdf_customer.explore(
68
m=m,
69
marker_type="marker",
70
marker_kwds=dict(icon=folium.Icon(color="green", icon="tent", prefix="fa")),
71
name="Customers",
72
)
73
74
folium.LayerControl().add_to(m)
75
76