Highlight one specific country in Folium

前端 未结 1 989
北恋
北恋 2021-01-25 02:35

I have a map drawn by folium as follow:

m = folium.Map(location = [51.1657,10.4515], zoom_start=6, min_zoom = 5, max_zoom = 7)

How can

相关标签:
1条回答
  • 2021-01-25 03:39

    As long as you have a json file containing the geometry (coordinates) for the country of interest, you can add a GeoJson layer:

    import folium
    import json
    
    with open('datasets/world-countries.json') as handle:
        country_geo = json.loads(handle.read())
    
    for i in country_geo['features']:
        if i['properties']['name'] == 'Germany':
            country = i
            break
    
    m = folium.Map(location = [51.1657,10.4515],
                   zoom_start=6,
                   min_zoom = 5,
                   max_zoom = 7)
    
    
    folium.GeoJson(country,
                   name='germany').add_to(m)
    
    folium.LayerControl().add_to(m)
    
    m
    

    and you get:

    0 讨论(0)
提交回复
热议问题