Python/Folium

I’m making a map using a single spreadsheet of data, as some facilities meet certain criteria that others don’t, that I’d like to filter out into a separate layer that can be selected on the map.

I’m fresh into python, but picking it up fairly easily.

Here’s my code so far:

import pandas as pd
import folium

df=pd.read_excel(open('data/VA Healthcare Facilities.xlsx', "rb"))

# Define Various Global Variables
location=[47.1164,-101.2996]
locationlist=df[["Latitude","Longitude"]].values.tolist()
labels=df["Name"].values.tolist()
surgical=df["Surgical"].values.tolist()

map=folium.Map(location=location,zoom_start=4,tiles="CartoDB positron")

from folium.plugins import MeasureControl
map.add_child(MeasureControl())

fg=folium.FeatureGroup(name="All VA Healthcare Facilities")

for point in range(len(locationlist)):
    popup=folium.Popup(labels[point],parse_html=True)
    fg.add_child(folium.RegularPolygonMarker(
        locationlist[point],
        popup=popup,
        fill_color='#EE1C25',
        number_of_sides=5,
        radius=7,
        )).add_to(map)

map.add_child(fg)

fg2=folium.FeatureGroup(name="VA Surgical Facilities")



map.add_child(fg2)

map.add_child(folium.LayerControl())
map.save(outfile="Healthcare_Facilities.html")

Within the excel spreadsheet, I’ve created a row for noting surgical capability, 1 meaning yes, and 0 meaning no. I’m certain an if/else statement could be what I need to parse this data and pull the coordinates from “locationlist” to plot only those with the value of “1” on the new layer. The idea is being able to toggle between all facilities, and only those with surgical capability. There will be additional layers likely created using the same method, but I just need to get it down first. Any suggestions?

I realize I could just use additional sheets of data, but I’d like to keep it all consolidated for ease of updating.

The words you are writing makes everything sound really cool, but this all went waaaay above my head (and it’s not just because I’m short!) :stuck_out_tongue:

1 Like

Trust me, I feel the same way!

I joined the Python discord to get a handle on things, and it’s all zooming right over me!

For the sake of ease, I just went with separate data sheets and that’s worked great so far. I’d prefer to consolidate and slice the data as needed, but I’m just not at that level yet.

I’ve hit another roadblock where I’ve found that pure leaflet.js has the event handlers I want (mouseover events!) that folium can’t seem to accommodate in a Python environment yet.

On the bright side, I’m having loads of fun, even if I don’t understand half of it! Never know if an avid Python fan is among us or not.