I want to import a geojson file into python so I can map it with a visualization package vincent and merge with other data in a pandas data frame.

To be specific, the said geojson file is: https://gist.githubusercontent.com/justgrimes/a63e8ec28868d8ce337e/raw/13cd7d8867e579d8b4f6b44f002a99940fba0504/DCNeighborhoodBoundariesWaPo.geojson. It's a map of DC with neighborhoods, put together by Justin Grimes.

Right now, I'm just trying to visualize this map on notebook. Here's my code:

import vincent

geo_data = [{'name': 'countries',
             'url': map,
             'feature': "features"}] 
vis = vincent.Map(geo_data=geo_data, scale=5000) 

but I have nothing in the output. What am I doing wrong here?

I don't yet know much about GIS and Python.


You have to load Vincent JS parts with vincent.initialize_notebook()

You need to transform the GeoJSON to TopoJSON (use Mapshaper) as Vincent support only TopoJSON (or I missed something too). See the official doc to understand TopoJSON

The key DCNeighborhoodBoundariesWaPo in 'feature': "DCNeighborhoodBoundariesWaPo" was deduced from TopoJSON objects

You do not display you visualisation with vis.display()

See below working sample for a complete overview.

import vincent



geo_data = [{'name': 'whatever',
             'url': map,
             'feature': "DCNeighborhoodBoundariesWaPo"}] 
vis = vincent.Map(geo_data=geo_data, scale=150000, translate=[-40480], projection='albersUsa') 


A last remaining problem is the fact I was able to zoom to DC but without using really a recipe (more try/test...), with translate (IMO, Vega/Vincent sucks for this when zooming on a specific part of a country or region)

If you have a better way of doing for the last part, I will be happy to learn how!

  • Thanks for your response! this is a really basic question, but after I convert the file from GeoJson to TopoJson(or just Json, using Mapshaper), how would I establish a url path to put in map? the path to my hard drive where the Json file is saved seems to be not working, giving me the 'Loading failed' error message. – chungkim271 Jul 1 '15 at 17:58
  • the url issue aside, I also get an error at this line: vis = vincent.Map(geo_data=geo_data, scale=150000, translate=[-40480], projection='albersUsa'). The error is len(center) must = 2. did you not have this issue? – chungkim271 Jul 1 '15 at 17:59
  • For 1st comment, I usually do use default included Python web server e.g linuxjournal.com/content/… For 2nd comment, it was tested and worked but I didn't exactly checked my version of Vincent (maybe related to your issue). – ThomasG77 Jul 1 '15 at 22:41

Not knowing vincent very well, could I offer that your map variable is just a string and not the resulting geojson you expect? Or you could validate the geojson at http://geojsonlint.com/

  • this geojson file is validated – chungkim271 Jun 17 '15 at 19:47
  • Example from here has projection info, this isn't in your code. Does that help? vincent.readthedocs.org/en/latest/… – user965586 Jun 17 '15 at 21:20
  • The remote data is invalid if following JSON spec. I tested with jsonlint.com and it fails. You can't go further if you don't do local correction. – ThomasG77 Jun 18 '15 at 0:11
  • Sorry, I did have a wrong link there. please see edits. – chungkim271 Jun 18 '15 at 14:45
  • well, everything works for me from your code. I can get <class 'vincent.charts.Map'> using print type(vis)...is your code above everything you want to do? or am I missing something? – user965586 Jun 18 '15 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.