Swiss geodata as TopoJSON
Makefile

README.md

Swiss Maps

This repository provides a mechanism to generate TopoJSON from publicly available (but difficult to access) swisstopo geodata.

Getting Started

To generate the TopoJSON files you need to install Node.js, either with the official Node.js installer or via Homebrew:

brew install node

You also need GDAL and the corresponding python-gdal library installed. Links to the binaries are in the GDAL Wiki. On OS X you can also use Homebrew:

brew install gdal

To get started, clone this repository and run make.

git clone https://github.com/interactivethings/swiss-maps.git
cd swiss-maps
make

make or make all generates the following TopoJSON files:

  • ch-country.json
  • ch-cantons.json
  • ch-districts.json
  • ch-municipalities.json
  • ch-country-lakes.json (country boundaries + lakes)
  • ch-cantons-lakes.json (canton boundaries + lakes)
  • ch-districts-lakes.json (district boundaries + lakes)
  • ch-municipalities-lakes.json (municipality boundaries + lakes)
  • ch-lakes.json
  • ch.json (all of the above combined)
  • For each canton a file with its municipalities and lakes, e.g. zh-municipalities.json and zh-municipalities-lakes.json

Additionally, PLZ (zip code) boundaries and elevation contours can be built:

  • ch-plz.json
  • ch-contours.json (the CONTOUR_INTERVAL variable can be set to the desired interval in meters (default: 500))

TopoJSON files are generated in the topo/ directory.

You can also generate individual files, e.g.

make topo/ch-cantons.json

SVG Output

To generate SVG files, the usage is similar, e.g.

make svg/ch-cantons.svg

If the generated SVG has a corresponding TopoJSON file with multiple objects (e.g. svg/ch.svg), the resulting SVG will have multiple layers too!

Note: Don't use REPROJECT=true when generating SVGs.

Projections and Dimensions

The coordinates of the source files is the official Swiss reference system CH1903 with already projected coordinates.

Per default, make will generate output files with the following characteristics:

  • Projected, cartesian coordinates
  • Scaled and simplified to a size of 960 × 500 pixels

If you're creating maps for screen use, these should be the optimal settings because you don't waste client performance with projecting spherical coordinates and have a good balance of geometry details and file size.

This means that if you use D3.js, you must disable the projection (see this example of New York Block Groups)

var path = d3.geo.path()
  .projection(null);

However, there are a few cases where you want something different.

Changing Dimensions

If you're targeting another output dimensions, you can easily change them by setting the WIDTH and HEIGHT variables:

make topo/ch-cantons.json WIDTH=2000 HEIGHT=1000

Per default, a 10px margin is included which can be changed by setting the MARGIN variable.

Make sure you run make clean if you've generated files before because make won't overwrite them if they already exist.

Reproject to Spherical Coordinates

If you want to combine your JSON files with other libraries like Leaflet or want to use another projection, you need to reproject the files to spherical coordinates first. You can do this by simply running

make topo/ch-cantons.json REPROJECT=true

It's double important that you run make clean or rm -rf shp first if you've generated files in cartesian coordinates (the default mode) before. Otherwise TopoJSON will throw an error. The WIDTH and HEIGHT variables will be ignored.

Metadata

Although the source files contain a slew of metadata such as population and area, data source, year of change etc., no properties are included by default, only the feature ID is set. This keeps files as small as possible and in most cases you will join other data to your map anyway.

You can easily include the following properties

  • id (the official ID of the feature, i.e. municipality (BFS), canton, district, or lake number)
  • name (the name of the feature in its main language)
  • abbr (only for cantons, e.g. 'BE')

To include some or all of these properties, define the PROPERTIES variable:

make topo/ch-cantons.json PROPERTIES=name,abbr

If you want to generate your files with more (or less) properties, you should modify the Makefile.

Historical Municipality Boundaries

Municipality boundaries from 2013 and 2014 are also available. If you want boundaries from another year than 2015, define the YEAR variable:

make topo/ch-municipalities.json YEAR=2013

Make sure you run make clean if you've generated files before for another year.

Custom Simplification

To use a custom simplification, define the SIMPLIFY variable. For example, to create a really blocky version of Switzerland:

make topo/ch-country.json SIMPLIFY=400

Note: The simplify parameter has different meanings depending on the coordinate system.

Other Modifications

For everything else you can modify the Makefile or run ogr2ogr and topojson directly. Mike Bostock's tutorial Let's Make a Map, the TopoJSON wiki, and ogr2ogr documentation should cover most of your needs.

Examples

Copyright and License

Author

Jeremy Stucki, Interactive Things

Data Source

Data source is the Swiss Federal Office of Topography, swissBOUNDARIES3D 2015.

License