My very first exercise with TopoJSON and D3 - just a municipal map showing some basic information when you hover over the individual municipalities. Nothing really fancy, but, hey, you have got to start somewhere...
###Steps followed to create the file nlgemeenten2009.json:
Step 1. download input file gem_2009_gn3.shp from the Dutch Statistical Office: Wijk- en Buurtkaart 2009
Step 2. convert shapefile to GeoJSON with ogr2ogr:
ogr2ogr \
-f GeoJSON \
-t_srs EPSG:4326 \
gemeenten.json \
gem_2009_gn3.shp
In this step we convert the projection from the Netherlands National System (EPSG:28992) to WGS84 (EPSG:4326)
The output file is 2.6 MB in size.
Step 3. change the encoding of the GeoJSON file to UTF-8:
I did do this in a manual step by opening the file gemeenten.json in Notepad++ and modify the encoding via Encoding > Convert to UTF-8 and save the file.
Step 4. convert (and compress) the GeoJSON file with topojson:
topojson \
-o nlgemeenten2009.json \
--id-property GM_CODE \
--properties gemeente=GM_NAAM \
--properties inwoners=AANT_INW \
gemeenten.json
The resulting file nlgemeenten2009.json is much smaller, at only 237 KB.
Why do I use a relatively outdated dataset for this exercise, 2009 is almost a decade ago? The main reason for this is: file size! Until 2009 the Dutch Statistical Office (CBS) provided the data with generalized geometry (i.e. simplified municipal borders). This reults in relatively small GeoJSON (2.6 MB) en TopoJSON (237 KB) files. The resulting TopoJSON file is managable in a web map application. And the level of detail is perfect for the display of statistical data at national level.
Nowadays the Statistical Office offers datasets with the full boundary geometry. And they even added - as an additional service - highly detailed boundaries between water bodies and land areas within municipalites.
The same exercise with the official 2014 dataset resulted in a whopping 54 MB (!!!) GeoJSON file. And after compression the TopoJSON file was also relatively large, at 2 MB. That's why I decided to rewrite the exercise with an older, more compact dataset.