Skip to content

TeemuKoivisto/map-of-finland

Repository files navigation

Just an example using these:

How to install

Requires Node >=8 and yarn installed globally. Or you could use npm.

  1. yarn
  2. yarn start

Deploying

  1. Checkout to master if you're not already: git checkout master
  2. Tag the current commit to indicate deployed version: git tag v.0.1.0
  3. Checkout to gh-pages branch: git checkout gh-pages
  4. Pull the master: git pull origin master
  5. Run: npm run deploy
  6. Add files: git add -A
  7. Create commit: git commit -m "Version 0.1.0"
  8. Push it to Github: git push origin gh-pages --tags

Now it should be live at http://teemukoivisto.github.io/map-of-finland

Curious thing it always redirects to the root ((http://teemukoivisto.github.io) however it works as long as you don't refresh the page (then it goes to my github-homepage).

EDIT: It was fixed by adding basename-prop to BrowserRouter (facebook/create-react-app#1765).

Explanation how the map was generated

This map with current municipality borders (as of 2018) was created with a lot of pain with the following resources:

Instructions to create the map

Maanmittauslaitos offers free resources such as map of finnish municipalities (and also Aluehallintovirastojako, Maakuntajako, Valtakuntajako). To download the map you should go here: https://tiedostopalvelu.maanmittauslaitos.fi/tp/kartta and select the layers you want to download (here Kuntajako 1:10 000) and submit your request. Shortly you should get a download link to your email. NOTE: because life must be hard all the files were in latin-9 encoding.

But this is just the beginning! Oh boy yes well you don't have to go through the path of blood and tears as I did so consider yourself lucky. If you open the file with a map program such QGIS first remember to set the encoding to Latin-9 from properties and then convert the CRS with Save As and then selecting WGS84 EPSG:4326 as the projection and format as GeoJSON. Also you'll notice that the municipalities include the sea-areas which doesn't look that good. So in order to get rid of the excess area you need another layer with the desired topology.

Here's an old link explaining how it was done back in year 2013 https://github.com/kansanmuisti/datavaalit/wiki/kuntarajat-leikkatuna-suomen-rantaviivalla

Unfortunately the file containing the shape of finnish coast doesn't exist anymore. But thank God there is already a map of finnish municipalities with coastal borders http://datajournalismi.blogspot.com/2013/02/suomen-kuntarajat-2013-kml-formaatissa.html . We can use this map as a clip layer to cut the coastal borders to get the same result. This 2013 map has some municipalities that don't exist anymore due to unifications which is why we have to recreate the map.

It includes the map here in Google Drive as Fusiontable https://fusiontables.google.com/DataSource?docid=1V5-SxUZ9zMlvG1uRpJ0NUK7j53tubyC7ZMYpbt0 . You can download it by selecting the Map of geometry and then choosing File -> Download -> Format: KML (took me too long to figure it out). Now we have the cut layer, yey! No need to fumble around with QGIS and OpenStreet Maps trying to Clip the municipality polygons with a line. Just... don't try to do it...

Using QGIS (I had version 2.18.20) you can open both layers at the same time and then use Vector -> Geoprocessing Tools -> Clip and select kuntarajat as the input layer and Kuntarajat 2013 as the cut layer. Now what you get should be the current municipalities with coastline borders. Again save this layer as a GeoJSON file.

However as things would be too easy otherwise you might see that there's a lot of small islands in the map. Those islands are kinda annoying as they are ugly and make the map slower. So what we want to do is to remove all the smallest polygons from the map, right? Which is impossible in QGIS or well I never figured out how to do it.

But thank you Tomi for already figuring this out for me in the mapcolorizer repo. There's a nifty script there that loops through the geometries, computes polygon areas and reduces their count. But since at least my GeoJSON was in different shape than Tomi's I had to recreate the script. Wasn't too bad though so thanks again Tomi.

Running ./cut-small-polys.py should cut away all the smallest polygons from the clipped municipality GeoJSON kuntarajat-2018-raw.json and output it to kuntarajat-2018.json.

BUT as I noticed running this script for regions still generates a massive file of complicated polygons. Municipality-map was in tolerable limits (<1 MB) but region map too big (~12 MB). In order to reduce the size I used command line tool called ogr2ogr that comes with GDAL library. After installing that you should run ogr2ogr kuntarajat-2018-2.json kuntarajat-2018.json -simplify 0.005 to simplify the borders. Region-map's size was reduced to 188 kB so 99% reduction. Nice. From user's perspective the map is almost identical.

And that's it! I hope I saved a couple hours (or days) of your life trying to comprehend all this mess. So what was I even supposed to do with this map? Humm...