-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcruft.r
354 lines (321 loc) · 8.29 KB
/
cruft.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# Comparing size of industrial sites
inset maps
side-by-side
library(osmdata)
q <- opq(bbox = 'Turin, Italy') %>%
add_osm_feature(key = 'landuse', value = 'industrial') %>%
osmdata_sf()
qtm(q$osm_polygons %>% filter(osm_id == 2045972))
miafiore <- opq_osm_id(type = "relation", id = 2045972) %>%
osmdata_sf()
qtm(miafiore$osm_multipolygons)
# https://wiki.openstreetmap.org/wiki/NL:Tag:landuse=industrial?uselang=nl
# Officine ICO Ivrea
https://www.openstreetmap.org/way/162150668
# Relatie: Tenaris-Dalmine (2569949)
https://www.openstreetmap.org/relation/2569949#map=15/45.6396/9.6091
# M Relatie: Fiat Mirafiori (2045972)
https://www.openstreetmap.org/relation/2045972
qtm(brussel)
limburg <- prov %>% filter(label == 'Provincie Limburg')
qtm(limburg)
st_centroid(brussel)
st_geometry(brussel) + c(0, 10)
# Questions sessions 2019-02-11, 2019-02-14
#
# Spatial join to fix Brussels
#
# How do I format tmap legends with percentages?
#
# Possbility of using hex-based binning?
#
# Can I add points to a thematic map?
#
# Adding a logo to ggplot-based map?
#
#
# ```{r}
# library(haven)
#
# ```
#
#
# ```{r}
# library(haven)
# issp.2016 <- read_sav(file.path(Sys.getenv('DATADIR_HIVA_LOCAL'), 'ISSP/issp_w2016_rog/ZA6900_v2-0-0.sav'))
# ```
#
# ```{r}
# issp.2016
# ```
#
# BE: In order to deliver one integrated harmonized data file for Belgium post stratification weights were calculated based upon age (three age
# groups: 18-39; 40-59; 60+), sex, and geographical classification (NUTS1 Flemish Region, Walloon Region, Brussels Capital Region). These
# characteristics are known for all sampled units and the population distributions are published by the Belgian Institute for National Statistics
# (Statbel). The age-sex distribution in each region is reproduced by the weights as well as the distribution over the regions. The result of this
# weighting procedure in combination with the sampling design is that the weights for respondents of the Brussels Capital Region are much
# smaller than the weights for the respondents of the Flemish and Walloon regions. The use of adequate software is always necessary when
# analyzing data with weights, but with these data it is vitally important when comparing the regions or analyzing only one region
# separately.
# https://stackoverflow.com/questions/46704878/circle-around-a-geographic-point-with-st-buffer
#
#
# ```{r}
# luchthaven <- st_point(x = c(4.4833857, 50.9010024), dim = "XY")
# luchthaven <- luchthaven %>% st_sfc(crs = 4326)
# ```
#
# ```{r}
# library(mapview)
# mapview(luchthaven)
# ```
#
# ```{r}
# mapview(st_buffer(luchthaven, 0.2))
# ```
#
#
# https://skyvector.com/airport/EBBR/Brussels-Airport
# Coordinates: N50°54.08' / E4°29.07'
# Elevation is 184.0 feet MSL.
#
#
# ```{r}
# # https://stackoverflow.com/questions/46704878/circle-around-a-geographic-point-with-st-buffer
#
# #dub <- st_point(x = c(dub_lon, dub_lat, dub_elv), dim = "XYZ")
# #dub <- dub %>% st_sfc(crs = 4326)
# ```
#
# ```{r}
# qtm(world_tmap %>% filter(continent == 'Europe'))
# ```
#
# ```{r}
# qtm(world_tmap %>% filter(continent == 'Europe', name != 'Russia'))
# ```
#
#
#
# # http://bboxfinder.com/#50.388821,3.771057,50.455100,3.913536
#
# ```{r}
# borinage_coords <- matrix(c(
# 3.771057,50.388821,
# 3.771057,50.455100,
# 3.913536,50.455100,
# 3.913536,50.388821,
# 3.771057,50.388821),ncol=2, byrow=TRUE)
# borinage_bb <- st_geometry(st_polygon(list(borinage.coords)))
# borinage_bb <- st_set_crs(borinage_bb, 4326)
# mapview(borinage_bb)
# ```
#
#
# ```{r}
# borinage_crop <- st_crop(munip, borinage_bb)
# mapview(borinage_crop)
# ```
#
#
# ```{r}
# mapview(st_join(munip, borinage_crop, join = st_contains, left=FALSE))
# ```
#
#
# ```{r}
# mapview(st_join(munip, munip.crop, join = st_touches, left=FALSE))
# ```
#
# ```{r}
# mapview(st_join(munip, munip.crop, join = st_within, left=FALSE))
# ```
#
# ```{r, warning=FALSE}
# munip.crop <- st_crop(munip, c(xmin=5.5, xmax=6, ymin=51, ymax=55))
# qtm(munip.crop, text = 'TX_MUNTY_DESCR_NL')
# ```
#
# ```{r}
# mapview(munip.crop)
# ```
#
# ```{r}
# mapview(munip[st_within(munip, munip.crop) %>% lengths > 0,])
# ```
#
#
# ```{r}
# st_within(munip, munip.crop)
# ```
#
#
# ```{r}
# munip %>%
# filter(st_within(munip, munip.crop))
# ```
#
# ---
# title: "Tweak"
# output:
# html_document:
# toc: TRUE
# toc_float: TRUE
# ---
#
# Tip: export as SVG and post-process in [Inkscape](https://inkscape.org/).
#
# # Quick-save from mapview
#
# ```{r, eval=FALSE}
# data("BE_ADMIN_DISTRICT")
# district <- st_as_sf(BE_ADMIN_DISTRICT)
# districtmap <- mapview(district)
# mapshot(districtmap, 'mapview_districtmap.html')
# mapshot(districtmap, 'mapview_districtmap.png')
# ```
#
#
# # Save static maps with tmap
#
# ```{r}
#
# ```
#
#
# # Save static maps with ggplot
#
# ```{r}
#
# ```
#
#
# # Save interactive leaflet maps
#
# Standalone vs. dependencies
#
#
#
# ---
# title: "Tweak"
# output:
# html_document:
# toc: TRUE
# toc_float: TRUE
# ---
#
# ```{r, message=FALSE, warning=FALSE}
# library(readr)
# library(BelgiumMaps.StatBel)
# library(sf)
# library(dplyr)
# library(tmap)
# ```
#
#
#
# # Projection
#
#
#
#
#
# ```{r}
# be.income <- be.income +
# tm_layout(legend.show = FALSE)
# be.income.legend <- be.income +
# tm_layout(legend.show = TRUE)
# save_tmap(be.income, 'output/be_income_muni_2016.png', width=1920, height=1080)
# save_tmap(be.income.legend, 'output/be_income_muni_2016_legend.png', width=1920, height=1080)
# save_tmap(be.income.legend, 'output/be_income_muni_2016_legend.svg', width=1920, height=1080)
# ```
#
#
# ```{r}
# # tmap_mode('view')
# # qtm(heritage_leuven, fill = 'start_year')
# # tmap_mode('plot')
# ```
#
#
#
#
#
# # http://www.standaard.be/cnt/dmf20171025_03151950
#
#
#
#
# eu_nuts0 <- get_eurostat_geospatial(
# resolution = "60", # detail
# nuts_level = "0") # NUTS 0-3
#
# eu.mainland <- st_crop(eu_nuts0, c(xmin=-10, xmax=45, ymin=36, ymax=71))
# eu.mainland <- eu.mainland %>%
# left_join(worktime.2017, by = c('CNTR_CODE' = 'geo'))
#
# tm_shape(eu.mainland, projection="mercator") +
# tm_fill(col = 'values', title = 'Percentage\ntemporary work',
# legend.format=list(fun=function(x) paste0(formatC(x, digits=0, format="f"), " %"))) +
# tm_borders(col = 'white', lwd = .5) +
# tm_layout(frame = FALSE)
#
# # http://www.jla-data.net/2017/09/20/2017-09-19-tmap-legend/
# m.tempwork <- tm_shape(eu.mainland, projection="wintri") +
# tm_fill(col = 'values', title = 'Percentage\ntemporary work', showNA = FALSE,
# legend.format=list(fun=function(x) paste0(formatC(x, digits=0, format="f"), " %"))) +
# tm_borders(col = 'white', lwd = .7) +
# tm_layout(frame = FALSE) +
# tm_style_white(legend.format = list(text.separator= "-"))
#
# save_tmap(m.tempwork, 'map_eu_tempwork.png', width = 1920, height = 1080)
# save_tmap(m.tempwork, 'map_eu_tempwork.svg', width = 1920, height = 1080)
#
# internet <- get_eurostat('isoc_r_gov_i')
# internet.2018 <- internet %>%
# filter(time == '2018-01-01', unit == 'PC_IND', indic_is == 'I_IUGOV12')
#
# PC_IND pct individuals
# I_IUGOV12 Internet use: interaction with public authorities (last 12 months)
#
# eu_nuts2 <- get_eurostat_geospatial(
# resolution = "60", # detail
# nuts_level = "2") # NUTS 0-3
#
# internet.2018 <- internet.2018 %>%
# filter(geo %in% eu_nuts2$id)
#
# eu_nuts2 <- eu_nuts2 %>%
# left_join(internet.2018, by = c('id' = 'geo')) %>%
# st_crop(c(xmin=-10, xmax=45, ymin=36, ymax=71))
#
# tm_shape(eu_nuts2, projection="wintri") +
# tm_fill(col = 'values', title = 'Percentage\ntemporary work',
# legend.format=list(fun=function(x) paste0(formatC(x, digits=0, format="f"), " %"))) +
# tm_borders(col = 'white', lwd = .7) +
# tm_layout(frame = FALSE) +
# tm_style_white(legend.format = list(text.separator= "-"))
#st_crs(heritage) <- 31370
# ```{r}
# # Get a bounding box around Leuven
# # leuven_bb <- bb('Leuven', projection = '31370') # set projection to BE Lambert 72 https://epsg.io/31370
# # leuven_bb
# ```
#
# ```{r}
# #quick thematic map with a bounding box around Leuven
# #qtm(heritage) # compare full map
# #qtm(heritage, bbox = 'Leuven')
#
# #qtm(heritage, bbox = leuven_bb)
# ```
#
# ```{r}
# # heritage_leuven <- crop_shape(heritage, leuven_bb)
# # heritage_leuven
# ```
#
#
# ```{r}
# mapview(heritage)
# ```