Search code examples
d3.jsshapefilegeojson

How/Where do I get geoJSON data for states, provinces, and administrative regions of non-US countries?


I need geoJSON formatted paths for states, provinces, and regions within multiple countries. Most readily available geoJSON data is for US states and country level boundaries, not regions within the country. This geoJSON will be used to create a geographic visualization using D3.js.


Solution

  • There is a good writeup on how to generate geoJSON from shapefiles here
    http://vallandingham.me/shapefile_to_geojson.html

    The steps below should take you from start to finish:

    1. Install the Quantum GIS framework http://www.qgis.org/e/qgis.
      If you are on Mac OS X, you can use this version http://www.kyngchaos.com/software
      This will give you the ogr2ogr utility used for converting shapefiles to geoJSON

    2. Download the shapefiles for your country from here http://www.gadm.org/country and unzip

    3. For Canada, and possibly other countries, the shapefile with suffix 0 is for the country boundary and the suffix 1 is for the internal regions. Not sure if this naming is consistent across countries.

    4. Upload the region level shapefile to MapShaper http://mapshaper.com/test/MapShaper.swf
      You can skip this step if you don't care to optimize the size of your resulting geoJSON

    5. Set the 'simplification level' slider in MapShaper to the desired level and export the simplified shapefile as 'Shapefile - Polygons'

    6. Download .shp and .shx file to the local directory where you unzipped the original shapefiiles, replace the original files with the simplified ones.

    7. Navigate to the local directory and run the command below, replacing <shapefile> with the actual name of the shapefile you want to convert.

      ogr2ogr -f geoJSON regions.json <shapefile>.shp

    You should now have the regions for your country in geoJSON format. Check to make sure there are paths defined in regions.json and that property fields were maintained (ex. region name).