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
git clone https://github.com/interactivethings/swiss-maps.git cd swiss-maps make
make all generates the following TopoJSON files:
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.json(all of the above combined)
- For each canton a file with its municipalities and lakes, e.g.
Additionally, PLZ (zip code) boundaries and elevation contours can be built:
CONTOUR_INTERVALvariable can be set to the desired interval in meters (default: 500))
TopoJSON files are generated in the
You can also generate individual files, e.g.
To generate SVG files, the usage is similar, e.g.
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
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.
If you're targeting another output dimensions, you can easily change them by setting the
make topo/ch-cantons.json WIDTH=2000 HEIGHT=1000
Per default, a 10px margin is included which can be changed by setting the
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
HEIGHT variables will be ignored.
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
make topo/ch-cantons.json PROPERTIES=name,abbr
If you want to generate your files with more (or less) properties, you should modify the
Historical Municipality Boundaries
Municipality boundaries from 2013 and 2014 are also available. If you want boundaries from another year than 2015, define the
make topo/ch-municipalities.json YEAR=2013
Make sure you run
make clean if you've generated files before for another year.
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.
For everything else you can modify the
Makefile or run
topojson directly. Mike Bostock's tutorial Let's Make a Map, the TopoJSON wiki, and ogr2ogr documentation should cover most of your needs.
Copyright and License
Jeremy Stucki, Interactive Things
Data source is the Swiss Federal Office of Topography, swissBOUNDARIES3D 2015.
- Geodata from swisstopo is licensed under the Licence for the free geodata of the Federal Office of Topography swisstopo
- Everything else: BSD