GeoJSON data not displaying in Python folium map

前端 未结 3 1892
失恋的感觉
失恋的感觉 2020-12-21 03:00

I am trying to display the following geojson file in a folium map in Python but it just shows an empty map with none of the data.

Here are the steps I have tried:

相关标签:
3条回答
  • 2020-12-21 03:22

    Try this: m.add_child(folium.GeoJson(data = open("census_tracts_2010.geojson"))) and then call m.save() fun

    0 讨论(0)
  • 2020-12-21 03:37

    That file is not a GeoJson it is a TopoJson. You need to use folium.TopoJson instead.

    import folium
    
    m = folium.Map(location=[40.66393072,-73.93827499], zoom_start=13)
    
    folium.TopoJson(
        open('census_tracts_2010.geojson'),
        object_path='objects.nyct2010',
    ).add_to(m)
    
    m
    
    0 讨论(0)
  • 2020-12-21 03:37

    You need to open the geojson file.

        m.choropleth(open("census_tracts_2010.geojson"))
    

    Take a look at the examples https://folium.readthedocs.io/en/latest/quickstart.html

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