Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GeoJSON data not displaying in Python folium map

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:

  1. I tried using the python code below but nothing shows up.

  2. I tried other geojson files in the github repository below using the same code and the data show up without any issue, so it looks like my python code is fine

  3. I opened the "census_tracts_2010.geojson" file in github and Mapshaper, the data showed up perfectly without any issue, so it doesn't look like the geojson file is corrupted

Could anyone please let me know how I can fix it?

Geojson file: https://github.com/dwillis/nyc-maps/blob/master/census_tracts_2010.geojson

Python code:

import folium
m = folium.Map(location=[40.66393072,-73.93827499], zoom_start=13)
m.choropleth(geo_path="census_tracts_2010.geojson")
m.save(outfile='datamap.html')

Thanks a lot!

like image 776
vkc Avatar asked Feb 08 '17 07:02

vkc


3 Answers

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
like image 128
ocefpaf Avatar answered Nov 04 '22 16:11

ocefpaf


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

like image 31
Eirik Aabøe Avatar answered Nov 04 '22 14:11

Eirik Aabøe


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

like image 40
Muhammad Haseeb Khan Avatar answered Nov 04 '22 16:11

Muhammad Haseeb Khan