Skip to content

Instantly share code, notes, and snippets.

@jlehtoma
Created June 6, 2018 18:08
Show Gist options
  • Save jlehtoma/a91bc85ac415855664559aeeb9870098 to your computer and use it in GitHub Desktop.
Save jlehtoma/a91bc85ac415855664559aeeb9870098 to your computer and use it in GitHub Desktop.
Get aluejakokartat data for Helsinki
library(sf)
# Define source from where the data is downloaded
source_url <- "https://kartta.hel.fi/avoindata/aineistot/HKI-aluejako-1995-2016-gpkg.zip"
target_dir <- "data"
# Make target dir if it doesn't exist
if (!dir.exists(target_dir)) {
dir.create(target_dir)
}
# Download and unzip data
download.file(source_url, file.path(target_dir, basename(source_url)))
unzip(file.path(target_dir, basename(source_url)), exdir = target_dir)
# Find path to the target GeoPackage
dsn <- list.files(path = target_dir, pattern = ".\\.gpkg", recursive = TRUE,
full.names = TRUE)
# For all available layers, see sf::st_layers(dsn)
# Relevant for 2016 aluejako:
# suur_2016
# pien_2016
# perus_2016
# osa_alue_2016
sf_aluejako <- sf::read_sf(dsn, layer = "perus_2016")
# Plot for test
plot(sf_aluejako)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment