[GIS] Sharing a Folium Interactive Map w/ Embedded Markers

featuresgeopandaspythonweb-mapping

I have been experimenting with a few Python packages that have great potential for my dissertation research. Since I use pandas for pretty much everything, geopandas was a natural choice for working with spatial data (within the range of capability of the package), and the interactive properties of folium are sweet.

In any case, I want to be able to share the maps that I have made with other folks who are not using or even familiar with IPython Notebook. My test case is plotting the location of traffic cameras in DC. (The shapefile is provided to the public by DCGIS via opendatadc.org, a new and growing source for District info.) The Notebook Viewer seemed like an obvious choice, but as can be seen from my rendered gist, the maps are 1) static, and 2) displayed only in their final form. (Markers were not added until the last map, even though they appear in the first one.)

I then thought I could leverage Mike Bostock's awesome viewer for interactive graphics, bl.ocks.org. I am missing something, however, because while my map is now interactive, the markers have disappeared.

Has anyone run into this problem?

Best Answer

I haven't gotten json files to load with nbviewer yet, but here's two things that work in similar situations:

If you only use map.simple_marker() and similar functions, it's possible to completely embed the map HTML into the notebook. I haven't gotten this to work with json yet, but it looks like the upcoming version of follium allows templates, so it possibly can be inlined in the future. I have an example of this here:

http://nbviewer.ipython.org/gist/bburky/7763555/folium-ipython.ipynb

Also, you're running a SimpleHTTPServer but you don't need to. You can use the magic IPython files/ url to refer to files in the directory that IPython was launched from. So you can use an iframe with a source files/index.html. However, I haven't been able to get that to work in the Notebook Viewer. Theoretically you should be able to include multiple files in the gist and make it work.

Related Question