gisfin - tutorial

This R package provides tools to access open spatial data in Finland as part of the rOpenGov project.

For contact information and source code, see the github page

Available data sources

The following data sources are currently available: Helsinki region district maps (Helsingin seudun aluejakokartat) * Aluejakokartat, äänestysaluejako from Helsingin kaupungin Kiinteistövirasto (HKK) Helsinki spatial data (Helsingin seudun avoimia paikkatietoaineistoja) * Seutukartta, Helsingin piirijako, rakennusrekisterin ote from Helsingin kaupungin Kiinteistövirasto National Land Survey data (Maanmittauslaitoksen avointa dataa) * Yleiskartat from National Land Survey Finland Geocoding * Services: OKF.fi Geocoding API Test Console, OpenStreetMap Nominatim, Google

Installation

Release version for general users:

install.packages("gisfin")

Development version for developers:

install.packages("devtools")
library(devtools)
install_github("gisfin", "ropengov")

Load package.

library(gisfin)

Notes

The gisfin package uses the rgdal library, which depends on the GDAL spatial framework. Some rgdal installation tips for various platforms lister below. If you encounter problems, please contact us by email: louhos@googlegroups.com. Windows: Install binaries from CRAN OSX: Install binaries from CRAN. Check also KyngChaos Wiki * Linux: Try the installation scripts here (not necessarily up-to-date!)

Helsinki region district maps

Helsinki region district maps (Helsingin seudun aluejakokartat) from Helsingin kaupungin Kiinteistövirasto (HKK).

List available maps with get_Helsinki_aluejakokartat().

get_Helsinki_aluejakokartat()

Retrieve 'suuralue' spatial object with get_Helsinki_aluejakokartat(), and plot with plot_shape().

sp.suuralue <- get_Helsinki_aluejakokartat(map.specifier="suuralue")
plot_shape(sp=sp.suuralue, varname="Name", type="discrete", plot=FALSE)

Retrieve 'suuralue_piste' spatial object, containing the center points of the districts, and plot with spplot().

sp.suuralue.piste <- get_Helsinki_aluejakokartat(map.specifier="suuralue_piste")
sp::spplot(obj=sp.suuralue.piste, zcol="Name")

Use sp2df() function to tranform the spatial objects into data frames. Plot with ggplot2, using blank map theme with get_theme_map().

# Get data frames
df.suuralue <- sp2df(sp.suuralue, "Name")
df.suuralue.piste <- sp2df(sp.suuralue.piste, "Name")

# Set map theme
library(ggplot2)
theme_set(get_theme_map())
# Plot regions, add labels using the points data
ggplot(df.suuralue, aes(x=long, y=lat, fill=Name)) + geom_polygon() + geom_text(data=df.suuralue.piste, aes(label=Name)) + theme(legend.position="none")

Add background map from OpenStreetMap using get_map() from ggmap and plot again.

# Add background map from OpenStreetMap using ggmap
library(ggmap)
# Get bounding box from sp.suuralue
hel.bbox <- as.vector(sp.suuralue@bbox)
# Get map using openstreetmap
hel.map <- ggmap::get_map(location=hel.bbox, source="osm")
# Plot transparent districts on top the background map
ggmap(hel.map) + geom_polygon(data=df.suuralue, aes(x=long, y=lat, fill=Name), alpha=0.5) + geom_text(data=df.suuralue.piste, aes(x=long, y=lat, label=Name)) + theme(legend.position="none")

Retrieve and plot äänetysaluejako (election districts) with get_Helsinki_aluejakokartat() and plot_shape().

sp.aanestys <- get_Helsinki_aluejakokartat(map.specifier="aanestysalue")
plot_shape(sp.aanestys, "KUNTA", type="discrete", plot=FALSE)

Helsinki spatial data

Other Helsinki region spatial data from Helsingin Kaupungin Kiinteistövirasto (HKK).

List available spatial data with get_Helsinki_spatial().

get_Helsinki_spatial()

National Land Survey Finland

Spatial data from National Land Survey Finland (Maanmittauslaitos, MML). These data are preprocessed into RData format, see details here.

List available data sets with list_mml_datasets().

list_mml_datasets()

Retrieve regional borders for Finland with get_MML().

# Get a specific map
sp.mml <- get_MML(map.id="Yleiskartta-4500", data.id="HallintoAlue") 

# Investigate available variables in this map
head(as.data.frame(sp.mml))

Plot provinces (maakunnat) with plot_shape().

# Plot the shape file, colour provinces
plot_shape(sp=sp.mml, varname="Maakunta", type="discrete", plot = FALSE)

Plot municipalities (kunnat) with plot_shape().

# Plot the shape file, colour municipalities
plot_shape(sp=sp.mml, varname="Kunta", type="discrete", plot = FALSE)

Geocoding

Get geocodes for given location (address etc.) using one of the available services. Please read carefully the usage policies for the different services: OKF.fi Geocoding API Test Console OpenStreetMap Nominatim * Google

The function get_geocode() returns both latitude and longitude for the first hit, and the raw output (varies depending on the service used).

Warning! The geocode results may vary between sources, use with care!

gc1 <- get_geocode("Mannerheimintie 100, Helsinki", service="okf")
unlist(gc1[1:2])
gc2 <- get_geocode("Mannerheimintie 100, Helsinki", service="openstreetmap")
unlist(gc2[1:2])
gc3 <- get_geocode("Mannerheimintie 100, Helsinki", service="google")
unlist(gc3[1:2])

Citation

Citing the data: See help() to get citation information for each data source individually.

Citing the R package:

citation("gisfin")

Session info

This vignette was created with

sessionInfo()


rOpenGov/gisfin documentation built on May 26, 2019, 8:48 p.m.