Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to latest folium #1

Closed
wants to merge 1 commit into from

Conversation

ocefpaf
Copy link

@ocefpaf ocefpaf commented Sep 4, 2017

@emiliom GitHub is still bad at diffing notebooks so here are the important changes I made to the notebook.

cells [20] and [21]

import folium


def gdf_choropleth(gdf, keyon, data_column, **kw):
    """
    Thin wrapper to parse the options for choropleth in a GeoPandas friendly way.

    gdf: GeoPandas geodataframe
    choropleth: the id to "key_on"
    data_columns: data column for the choropleth
    kw: any other choropleth optional argument
    """
    kwargs = {
        'geo_data': gdf,
        'data': gdf,
        'columns': [keyon, data_column],
        'key_on': 'feature.properties.{}'.format(keyon),
    }
    kwargs.update(kw)
    return kwargs
m = folium.Map(location=[47.8, -122.5], zoom_start=7, 
               tiles="cartodbpositron")

kw = gdf_choropleth(
    hydrobas_ww_p7_wasp,
    keyon='pfaf_7',
    data_column='area_mi2',
    fill_color='YlGn',
    fill_opacity=0.4,
    legend_name='area'
)

m.choropleth(**kw)

m

You can see the full notebook here: http://nbviewer.jupyter.org/github/ocefpaf/geopandas-tutorial-maptime/blob/update_to_latest_folium/notebooks/geopandas_advanced.ipynb

@emiliom
Copy link
Owner

emiliom commented Sep 6, 2017

Thanks @ocefpaf ! @lsetiawan, let's not accept this PR yet, but use the information in updating the geohackweek/vector notebooks.

I'm not sure that in the context of the tutorial it makes sense to create and introduce this wrapper. Given that that folium usage only occurs once in the two notebooks, my first instinct is that it's not worth it. However, instead of keyon='pfaf_7', please see if you can pass the index name or something generic or "automated" like that which refereces the index, rather than requiring the user to think about a column name to pass.

ref: geohackweek/vector#12

@lsetiawan
Copy link

@emiliom I am not clear about this:

see if you can pass the index name or something generic or "automated" like that which refereces the index, rather than requiring the user to think about a column name to pass.

What sort of index are you looking for, an integer or the actual column name?

@ocefpaf
Copy link
Author

ocefpaf commented Sep 6, 2017

Indeed I do not recommend to merge that, specially if the goal is to teach the software API, even though it is a thin wrapper it can be confusing.

Closing this as the goal was only to send an example on how to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants