geohackweek/vector

Folium choropleth change/problem in 0.6.0 vs 0.5.0 and 0.4.0

Opened this issue · 3 comments

@ocefpaf hopefully you can help me with this. I'm updating my "vector" notebooks for the GeoHackWeek event next week.

I have a Folium choropleth statement that worked last time I ran it, a month ago, with Folium 0.5.0. But the same statement is now failing, with a brand new conda env created today that installed Folium 0.6.0. (the same statement worked as-is with 0.4.0, too). Nothing has changed with the GeoDataFrame I'm using as the data passed to geo_data and data.

The notebook that worked end-to-end, with the rendered Folium choropleth (0.4.0, ran a year ago), is here: https://github.com/emiliom/tutorial_contents/blob/master/vector/notebooks/geopandas_advanced.ipynb (and on nbviewer, to see the folium map). See cell 22.

And here's the notebook from today with the same choropleth statement (cell 23), but where Folium failed:
https://github.com/emiliom/tutorial_contents/blob/emilio_vector/vector/notebooks/geopandas_advanced.ipynb
I'm not able to interpret the error message. I tried looking at the current choropleth API documentation and the 0.6.0 release notes, but couldn't find anything new to explain this. I looked into this change but that didn't help me.

Thanks for your help!

I'm actually surprised that this used to work! It should not 😄

The fix is simple, just pass the column where the geometries are:

m = folium.Map(location=[47.8, -122.5], zoom_start=7, tiles='cartodbpositron')

m.choropleth(
    geo_data=hydrobas_ww_p7_wasp['polygongeom'],
    data=hydrobas_ww_p7_wasp,
    columns=['pfaf_7', 'area_mi2'],
    key_on='feature.properties.pfaf_7',
    legend_name='Area (sq mi)', 
    fill_color='YlGn',
    fill_opacity=0.4,
    highlight=True)

PS0: the choropleth is depreacted and I recommend using the GeoJson class to build choropleth in the future.

PS1: please open issues like this on the folium issue tracker where others can probably answer it quicker and better than me.

Thanks @ocefpaf! I'm now getting a folium map, but it's not actually rendering as a choropleth; all polygon fill colors are identical. I'll look into that and look into replacing with the GeoJson class.

PS1: please open issues like this on the folium issue tracker where others can probably answer it quicker and better than me.

Sorry for abusing your attention. I'll be a better Folium citizen next time.

Sorry for abusing your attention.

No problem.

I'll be a better Folium citizen next time.

The reason I said that is b/c we have some new devs and volunteers that are more "in" than me. I haven't touch folium's code in a while.