-
Notifications
You must be signed in to change notification settings - Fork 0
/
kapsi2rdata.R
77 lines (52 loc) · 3.14 KB
/
kapsi2rdata.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# If run from RStudio, set the WD correctly
if (Sys.getenv("RSTUDIO") == "1") {
setwd("rscripts/Kapsi/")
}
# Convert certain key data files from MML, obtained through Kapsi, into RData format.
# From http://kartat.kapsi.fi/
# List the data sets relevant to our present R tools
url.list <- c()
# Maastotietokanta tiestö osoitteilla 1; 14K;
url.list[["Maastotietokanta-tiesto1"]] <- "http://kartat.kapsi.fi/files/maastotietokanta/tiesto_osoitteilla/etrs89/shp/N61.shp.zip"
# Maastotietokanta tiestö osoitteilla 2; 1.3M;
url.list[["Maastotietokanta-tiesto2"]] <- "http://kartat.kapsi.fi/files/maastotietokanta/tiesto_osoitteilla/etrs89/shp/N62.shp.zip"
# Yleiskartta 1000; 45M;
# http://www.maanmittauslaitos.fi/digituotteet/yleiskartta-11-000-000
url.list[["Yleiskartta-1000"]] <- "http://kartat.kapsi.fi/files/yleiskartta_1000k/kaikki/etrs89/shape/1_milj_Shape_etrs_shape.zip"
# Yleiskartta 4500; 2.8M;
# http://www.maanmittauslaitos.fi/digituotteet/yleiskartta-14-500-000
url.list[["Yleiskartta-4500"]] <- "http://kartat.kapsi.fi/files/yleiskartta_4500k/kaikki/etrs89/shape/4_5_milj_shape_etrs-tm35fin.zip"
# Directory to store the data
destination.dir <- "../../rdata/"
library(sorvi)
source("funcs.R")
for (id in names(url.list)) {
# Get MML Shape files from Kapsi server
url <- url.list[[id]]
# Temporary directory
tmp.dir <- tempfile(fileext = ".zip")
# Get the data
dat <- GetKapsi(url, tmp.dir)
# Convert to RData and store to rdata/ subdir and save the original zip files
output.dir <- ConvertMMLToRData(dat$shape.list, output.dir = paste(destination.dir, id, "/", sep = ""))
# system(paste("cp ", dat$zipfile, output.dir))
fnam <- paste(output.dir, "README.Kapsi", sep = "")
write(paste("The RData files in this directory were converted from", url, "on", date(), "with https://github.com/avoindata/mml/blob/master/rscripts/Kapsi/kapsi2rdata.R"), file = fnam)
write(paste("Data (C) MML 2013. The original zip files were automatically downloaded from https://tiedostopalvelu.maanmittauslaitos.fi/tp/kartta"), file = fnam, append = TRUE)
write(paste("RData Conversion (C) Leo Lahti / Louhos louhos.github.com; FreeBSD license"), file = fnam, append = TRUE)
write(paste("For more information of the MML map files, see http://www.maanmittauslaitos.fi"), file = fnam, append = TRUE)
}
# Easier way to download the files but not get worḱing yet
#url <- url.list[[2]]
#y <- url_shp_to_spdf(url.list[[1]])
#z <- unlist(unlist(y))
# Save batch information
fnam <- paste(destination.dir, "README", sep = "")
write("Land Survey Finland (MML) data in RData format. ", file = fnam)
write("The data (C) MML 2013.", file = fnam, append = TRUE)
write("Obtained through Kapsi.", file = fnam, append = TRUE)
write("For full conversion details, references and contact information, see https://github.com/avoindata/mml/tree/master/rscripts/Kapsi", file = fnam, append = TRUE)
write(paste("Last conversion:", date()), file = fnam, append = TRUE)
# Send RData to datavaalit site (will require password)
# system(paste("scp -r", output.dir, "[email protected]:../datavaalit/storage/avoindata/mml/"))
# Also see spider.R for further shape file processing scripts.