Get folium data in right format for choropleth map

Created on Monday 2 November 2020, 13:30

Back to task list
  • ID
    331862
  • Project
    Metabolism of Cities
  • Status
    Completed
  • Priority
    Medium
  • Type
    Programming work
  • Assigned to
    Paul Hoekman
  • Subscribers
    Guus Hoekman
    Paul Hoekman

You are not logged in

Log In Register

Please join us and let's build things, together!

Description

In order to make a choropleth map with folium the data needs to be in a specific format.


https://python-visualization.github.io/folium/quickstart.html#Choropleth-maps


The example from there:


url = 'https://raw.githubusercontent.com/python-visualization/folium/master/examples/data'
state_geo = f'{url}/us-states.json'
state_unemployment = f'{url}/US_Unemployment_Oct2012.csv'
state_data = pd.read_csv(state_unemployment)


The state_geo part is fine, that's just a geojson like we already have.


They use pandas to read the csv of the data. That's a very simple CSV.


Later on the map is generated like this:


folium.Choropleth(
geo_data=state_geo,
name='choropleth',
data=state_data,
columns=['State', 'Unemployment'],
key_on='feature.id',
fill_color='YlGn',
fill_opacity=0.7,
line_opacity=0.2,
legend_name='Unemployment Rate (%)'
).add_to(m)


So the key parts for this work is columns (which defines which columns are taken into consideration) and key_on (which is the place where the geojson features match the first column of the dataset).


They started with CSV so used pandas, but I don't think that's necessary. We just need the same output.

Discussion and updates


New task was created


Task was assigned to Paul Hoekman


Status change: Open → In Progress


The Folium structure is not idea with our current data format and I am suggesting another format. I have set up a "zooming in" map system in which the geojsons for a certain level is created, and I am providing values (quantities, for the choropleth), as well as links that allow for zooming in. When the link is clicked, the system will load the next depth level (e.g. from postal codes to neighborhoods, or from neighborhood to building level), but only for that particular item selected. None of this is properly done in js; instead I am providing the values printed on the page so that you can pick this up Guus and format the js accordingly.


Here are two maps: Melbourne and Brussels. All of this is done in map.html


Status change: In Progress → Completed