This repository provides a mechanism to generate TopoJSON and GeoJSON from publicly available (but difficult to access) swisstopo geodata.
To generate the TopoJSON and GeoJSON files you need to install Node.js, either with the official Node.js installer or via Homebrew:
brew install node
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 and GeoJSON files:
ch-country.json
ch-cantons.json
ch-districts.json
ch-municipalities.json
ch-lakes.json
- For each canton a file with its municipalities e.g.
zh-municipalities.json
ch.json
, containing all of the above (only TopoJSON)ch-contours.json
TopoJSON and GeoJSON files are placed in the topo/
and geo/
directories respectively.
You also can generate individual files, e.g.
make topo/ch-cantons.json
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.
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.
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.
Although the source files contain a slew of metadata such as population and area, data source, year of change etc., only the most basic properties are retained by default:
Country
- id ('CH')
- name ('Schweiz')
Canton
- id (the official canton number)
- name
- abbr (e.g. 'BE')
District
- id (the official district number)
- name
Municipality
- id (the official municipality or 'BFS' number)
- name
Lake
- id (the official lake or 'SEENR' number)
- name
Contours
- id (elevation)
This keeps files to a reasonable size and in most cases you will join other data to your map anyway. If you want to generate your files with more (or less) properties, you should modify the Makefile
.
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.
- TopoJSON Cantons and Municipalities (stored in a single file!)
- TopoJSON Cantons
Jeremy Stucki, Interactive Things
Data source is the Swiss Federal Office of Topography, swissBOUNDARIES3D 2013.
This agreement under public law in accordance with Article 12, paragraph 1b of the Swiss Federal Act of 5 October 2007 on Geoinformation (hereinafter referred to as Geoinformation Act) regulates access to, and use of, the federal geodata database.
By accepting this agreement, the licensee acknowledges all contractual provisions – in particular the scope of the licence and the contractual obligations – as well the applicability of Swiss federal legislation governing geoinformation.
By accepting this agreement, the licensee also acknowledges the sole right of the licensor to regulate access to, and use of, the federal geodata database. The attention of the licensee is herewith drawn to the fact that geodata may be protected under copyright law. The licensee thus acknowledges the exclusive right of the licensor to determine the use of the data.