import pandas as pd
import geopandas as gpd
import folium
print(f"Using folium version {folium.__version__}")
Using folium version 0.20.0
# Fetch the Minneapolis parks data
parks_url = "https://services.arcgis.com/afSMGVsC7QlRK1kZ/arcgis/rest/services/Parks/FeatureServer/0/query?outFields=*&where=1%3D1&f=geojson"
parks_data = pd.read_json(parks_url)
# Convert the GeoJSON data to a DataFrame
parks_df = gpd.GeoDataFrame.from_features(parks_data["features"], crs="EPSG:4326")
parks_df.head()
Loading...
parks_df["PARK_PARK3"].value_counts()
Loading...
# Create a map centered on Minneapolis
m = folium.Map(location=[44.9778, -93.2650], zoom_start=12)
folium.plugins.Fullscreen(
# position="topright",
# title="Expand me",
# title_cancel="Exit me",
# force_separate_button=True,
).add_to(m)
# Add the parks data to the map
popup = folium.GeoJsonPopup(
fields=["PARK_NAME1", "PARK_PARK3"], aliases=["Park Name", "Park Type"]
)
tooltip = folium.GeoJsonTooltip(
fields=["PARK_NAME1", "PARK_PARK3"], aliases=["Park Name", "Park Type"]
)
folium.GeoJson(
parks_df,
name="Minneapolis Parks",
popup=popup,
tooltip=tooltip,
style_function=lambda x: {
# Set the style for the parks based on PARK_PARK3 - PARK is green, TRIANGLE is orange, and other types are gray
"fillColor": "green"
if x["properties"]["PARK_PARK3"] == "PARK"
else "orange"
if x["properties"]["PARK_PARK3"] == "TRIANGLE"
else "gray",
"color": "darkgreen"
if x["properties"]["PARK_PARK3"] == "PARK"
else "darkorange"
if x["properties"]["PARK_PARK3"] == "TRIANGLE"
else "darkgray",
},
).add_to(m)
folium.LayerControl().add_to(m)
# Display the map
m
Loading...