This page shows how use standard data sets (municipality borders etc.) from Land Survey Finland.
To list the latest MML data sets that are directly available in R through the sorvi package in avoindata/mml, type in R the following. Note that 2012 data sets in RData format are available but not shown in the above automated listing.
library(sorvi, quietly = TRUE) list_mml_datasets()
# Get a specific map (see list_mml_datasets() for options) map.id <- "Yleiskartta-4500" data.id <- "HallintoAlue" sp <- LoadMML(map.id, data.id) # Investigate available variables in this map varnames <- names(sp) print(varnames) head(as.data.frame(sp)) # Visualize the shape file p <- PlotShape(sp, "Maakunta", plot = FALSE) p # Print the plot to PDF file and open from command line # (done this ways as there seem to be some problem with spplot PNG file outputs currently) pdf("Maakunta.pdf") print(p) dev.off() system("evince Maakunta.pdf &")
Assuming you have downloaded a shape file f, adjust these commands to read in, modify, and visualize the data:
# Read and preprocess shape file sp <- maptools::readShapePoly(f) # read the shapefile sp <- sorvi::PreprocessShapeMML(sp) # handle special characters etc. # Add some data fields to plot sp$example <- rnorm(nrow(sp)) varname <- "example" int <- max(abs(sp[[varname]])) # Visualize the shape file varname <- names(sp)[[2]] # Which layer to show? p <- PlotShape(sp, varname, type = "twoway", main = "Title", at = seq(0 - int, 0 + int, length = 11), plot = FALSE) print(p)
To get data in R, get the URL for your desired data in Kapsi, and provide it as in this example. We have noticed problems with certain XML files. We welcome all bug reports and improvements to these tools and instructions, just contact us.
library(sorvi) # Define url from http://kartat.kapsi.fi url <- "http://kartat.kapsi.fi/files/kuntajako/kuntajako_4500k/etrs89/gml/TietoaKuntajaosta_2013_4500k.zip" # Define temporary data directory data.dir <- gsub(" ", "-", paste("tmp.data.", date(), sep = "")) system(paste("mkdir ", data.dir)) local.zip <- paste(data.dir, "/tmp.zip", sep = "") # Download the file: download.file(url, destfile = local.zip) # Unzip the downloaded zip file data.dir <- file.path(data.dir) # system(paste('unzip', local.zip)) unzip(local.zip, exdir = data.dir) # Remove TEMP file unlink("TEMP", recursive=T) # In the above we have this file: my.file <- "TietoaKuntajaosta_2013_4500k/SuomenKuntajako_2013_4500k.xml" # List available map layers library(rgdal) boundaries <- readOGR(my.file, layer = ogrListLayers(my.file)[[2]]) # Plotting p <- PlotShape(boundaries, names(boundaries)[[1]], plot = FALSE) print(p)
This is often asked for.
For the 2012 municipality boundaries, you can use this version:
sp <- LoadData("kuntarajat.maa.shp")
The 2013 version without sea regions is not yet readily available in R, but you can follow these instructions to cut off the sea regions from the overall map and carry out R conversion. Contributions welcome!
RData conversions are documented here
See TODO
Finnish geographic information (GIS) is available through Land Survey Finland (MML) in XML/GML format, but this requires a separate query. The same data is directly available through Kapsi, and we have further converted the key data sets into light-weight RData format that we distribute here.
sessionInfo()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.