Shapefile to GeoJSON

A fellow attendee at the Open Data Day Toronto event hosted by Urban+Digital Toronto was wondering how to display Toronto neighbourhood data on a map that she was working on. I couldn’t find any GeoJSON of the neighbourhoods out in the open, so I grabbed a shapefile from the City of Toronto Open Data Portal – Toronto Neighborhood Planning Areas.

Toronto Neighbourhoods Shapefile

Toronto Neighbourhoods Shapefile In QGIS

To export it to GeoJSON I used the ogr2ogr tool from GDAL (Geospatial Data Abstraction Library).

$ ogr2ogr -t_srs EPSG:4269 -f geoJSON Neighbourhoods.json Neighbourhoods.shp

The resulting GeoJSON file was 1.4M in size. That’s a bit big to be sending down to the browser, so I used the Simplify geometries  tool in Quantum GIS (QGIS) and then re-exported to GeoJSON. The resulting file is a manageable 308K. It still looks good, so it could be shrunk down even further if needed.

The original shapefile, resulting simplified, GeoJSON and a Leaflet based example is up on GitHub: adamw523.github.com/toronto-geojson.

Leave a Reply