-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path03_norway.R
146 lines (125 loc) · 4.39 KB
/
03_norway.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# ----
# title : build census database - ssbno
# description : this script integrates data of 'Statistics Norway' (https://www.ssb.no/en/, https://www.ssb.no/en/statbank/list/stjord)
# license : https://creativecommons.org/licenses/by-sa/4.0/
# authors : Steffen Ehrmann
# date : 2025-01-22
# version : 0.0.2
# status : work in progress
# comment : file.edit(paste0(dir_docs, "/documentation/mdl_build_census_database.md"))
# ----
# geography : Norway
# spatial : ADM1, ADM2
# period : 1969 - 2023
# variables :
# - land : -
# - crops : -
# - livestock : number_heads
# - tech : -
# - social : -
# sampling : survey, census
# ----
thisNation <- "Norway"
# 1. dataseries ----
#
ds <- c("ssbno")
gs <- c("ssbno")
regDataseries(name = ds[1],
description = "Statistics Norway",
homepage = "https://www.ssb.no/en/",
version = "2024.09",
licence_link = licenses$by4)
# 2. geometries ----
#
regGeometry(ADM0 = !!thisNation,
gSeries = gs[1],
label = list(ADM1 = "fylkesnavn"),
archive = "45ce04cf-b10b-4277-a64f-2a2d14e886c1.zip|fylke.shp",
archiveLink = "https://kart.ssb.no/",
downloadDate = ymd("2024-07-22"),
updateFrequency = "unknown")
regGeometry(ADM0 = !!thisNation,
gSeries = gs[1],
label = list(ADM2 = "kommunenum"),
archive = "45ce04cf-b10b-4277-a64f-2a2d14e886c1.zip|kommune.shp",
archiveLink = "https://kart.ssb.no/",
downloadDate = ymd("2024-07-22"),
updateFrequency = "unknown")
regGeometry(ADM0 = !!thisNation,
gSeries = gs[1],
label = list(ADM2 = "kommunenum", ADM3 = "grunnkre_1"),
archive = "45ce04cf-b10b-4277-a64f-2a2d14e886c1.zip|grunnkrets.shp",
archiveLink = "https://kart.ssb.no/",
downloadDate = ymd("2024-07-22"),
updateFrequency = "unknown")
normGeometry(pattern = gs[1],
beep = 10)
# 3. tables ----
#
if(build_crops){
## crops ----
# work in progress
}
if(build_livestock){
## livestock ----
schema_livestock_ssbno <- setCluster() %>%
setFormat() %>%
setIDVar(name = "ADM1", ) %>%
setIDVar(name = "ADM2", ) %>%
setIDVar(name = "year", ) %>%
setIDVar(name = "method", value = "") %>%
setIDVar(name = "animal", ) %>%
setObsVar(name = "number_heads", )
### detailed species ----
regTable(ADM0 = !!thisNation,
label = "ADM1",
subset = "surveySpecies",
dSeries = ds[1],
gSeries = gs[1],
schema = schema_livestock_ssbno,
begin = 1969,
end = 2023,
archive = "11507_20240722-204729.xlsx",
archiveLink = "https://www.ssb.no/en/statbank/table/11507/tableViewLayout1/",
downloadDate = ymd("2025-01-16"),
updateFrequency = "annually",
metadataLink = "https://www.ssb.no/en/statbank/table/11507",
metadataPath = "unknown",
overwrite = TRUE)
### detailed admin units ----
regTable(ADM0 = !!thisNation,
label = "ADM2",
subset = "surveyAdmin",
dSeries = ds[1],
gSeries = gs[1],
schema = schema_livestock_ssbno,
begin = 1969,
end = 2023,
archive = "06447_20240722-204649.xlsx",
archiveLink = "https://www.ssb.no/en/statbank/table/06447/tableViewLayout1/",
downloadDate = ymd("2025-01-16"),
updateFrequency = "annually",
metadataLink = "https://www.ssb.no/en/statbank/table/06447",
metadataPath = "unkown",
overwrite = TRUE)
normTable(pattern = ds[1],
ontoMatch = "animal",
beep = 10)
}
if(build_landuse){
## landuse ----
# work in progress
}
#### test schemas
#
myRoot <- paste0(dir_census_wip, "tables/stage2/")
myFile <- ""
input <- read_csv(file = paste0(myRoot, myFile),
col_names = FALSE,
col_types = cols(.default = "c"))
schema <- schema_nbs_livestock
validateSchema(schema = schema, input = input)
output <- reorganise(input = input, schema = schema)
#
# https://github.com/luckinet/tabshiftr/issues
#### delete this section after finalising script