-
Notifications
You must be signed in to change notification settings - Fork 8
/
geostat18-geocomputation.Rmd
691 lines (457 loc) · 17.4 KB
/
geostat18-geocomputation.Rmd
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
---
title: "Geocomputation with R"
subtitle: "🗺 <br/> An overview of the field and introduction to the book"
author: "Robin Lovelace"
date: "GeoStat 2018(-08-20)"
output:
xaringan::moon_reader:
css: xaringan_stuff/my-theme.css
seal: true
lib_dir: xaringan_stuff/libs
nature:
# highlightStyle: dracula
highlightLines: true
ratio: '4:3'
countIncrementalSlides: false
# for use with citr (allows auto-updates)
bibliography: refs-geostat.bib
---
<!-- 14:15 - 15:00 - 45 minute talk -->
<!-- Aims: show-off the book, provide overview, some useful things in it -->
```{r setup, include = FALSE}
options(htmltools.dir.version = FALSE)
library(RefManageR)
BibOptions(check.entries = FALSE,
bib.style = "authoryear",
cite.style = 'alphabetic',
style = "markdown",
first.inits = FALSE,
hyperlink = FALSE,
dashed = FALSE)
my_bib = ReadBib("refs-geostat.bib", check = FALSE)
```
layout: true
background-image: url(xaringan_stuff/img/r_geocomp_background.png)
background-size: cover
---
# 'Team geocompr'
<figure>
<img align="right" src="xaringan_stuff/img/geocompr_logo.png" width = "60%", height = "60%"/>
</figure>
- [Jakub Nowosad](https://nowosad.github.io/): developer of GeoPAT + more. Lecturing 09:00 on Wednesday.
- [Jannes Muenchow](http://www.geographie.uni-jena.de/en/Muenchow.html), creator of **RQGIS**. Lecturing Weds 13:30 on GIS Bridges and Weds 15:30 on Spatial CV.
--
- [Robin Lovelace](https://www.robinlovelace.net/), creator of **stplanr**, co-author of Efficent R Programming. Lecturing 11:00 Weds on spatial data and the **tidyverse**.
--
- Front cover image competition! Submissions (code / ideas welcome) by Thursday evening. Prize: ~~$100~~ $150 CRC Press book voucher.
---
# Find the slides and the code
<br> Slides: https://geocompr.github.io/presentations/
<br> Source code: https://github.com/geocompr/geostats_18
To install all packages used in the book:
```{r, eval=FALSE}
devtools::install_github("geocompr/geocompkg")
```
Data for the sea level rise code in this presentation: see the releases in [geostats_18](https://github.com/geocompr/geostats_18/releases):
```{r, eval=FALSE}
download.file("https://github.com/geocompr/geostats_18/releases/download/0.1/pres.2fgeocompr.2fdata.zip",
destfile = "data.zip")
unzip("data.zip")
```
---
# Origins of the book I
```{r, eval=FALSE}
webshot::webshot("https://bookdown.org/nowosad/Geostatystyka/")
```
```{r, echo=FALSE}
# webshot::webshot("https://bookdown.org/nowosad/Geostatystyka/", file = "images/geostatystyka.png")
# i = magick::image_read("images/geostatystyka.png")
# print(i)
knitr::include_graphics("images/geostatystyka.png")
```
---
# Origins of the book II
```{r, eval=FALSE}
webshot::webshot("https://github.com/Robinlovelace/Creating-maps-in-R")
```
```{r, echo=FALSE}
# i = magick::image_read("images/creating.png")
# i
# i = magick::image_resize(i, "992x")
# i
# magick::image_write(i, "images/creating.png")
knitr::include_graphics("images/creating.png")
```
---
# Origins of the book III
```{r, eval=FALSE}
webshot::webshot("https://rjournal.github.io/archive/2017/RJ-2017-067/")
```
```{r, echo=FALSE}
# webshot::webshot("https://rjournal.github.io/archive/2017/RJ-2017-067/", file = "images/rqgis-rjournal.png")
# magick::image_read("images/rqgis-rjournal.png")
knitr::include_graphics("images/rqgis-rjournal.png")
```
---
# Contributing 'upstream' - questions
- Comment on a random github issue -> new author!
```{r, eval=FALSE}
webshot::webshot("https://github.com/jannes-m/RQGIS/issues/66")
```
```{r, echo=FALSE}
# webshot::webshot("https://github.com/jannes-m/RQGIS/issues/66#issuecomment-304788979", file = "images/rqgis-question.png")
# i = magick::image_read("images/rqgis-question.png")
# i = magick::image_crop(image = i, "992x+0+1500")
# magick::image_write(i, "images/rqgis-question.png")
knitr::include_graphics("images/rqgis-question.png")
```
---
# First commits by Jannes
```{r, engine='bash'}
cd ~/repos/geocompr
git log --author=jannes | tail -n 20
```
<!-- point: Anyone can get involved -->
---
# Contributions to other pkgs
```{r, message=FALSE}
library(tidyverse)
d = read_csv("~/repos/geocompr/our-impact.csv"); nrow(d)
d %>% slice(1:2) %>% select(date, description, creator) %>% knitr::kable(format = "html")
d %>% group_by(type) %>%
summarise(n = n(), comms = sum(comments, na.rm = T)) %>%
arrange(desc(n)) %>% top_n(4, n) %>% knitr::kable(format = "html")
```
<!-- d = read_csv("https://raw.githubusercontent.com/Robinlovelace/geocompr/master/our-impact.csv") -->
---
# Why Geocomputation with R?
.pull-left[
Why geocomputation?
- 'Does what it says on the tin'
- Emphasis on 'tools' + flexibility
- Link to Leeds (Jakub and Robin joined forces at the [GeoComputation 2017](http://www.geocomputation.org/2017/conference/) conference)
Why R?
- We all speak R!
- It's good for academic research (statistical rigour, reproducibility)
- It's a good bridge/interface language (see Chapter [9 on bridges](http://geocompr.robinlovelace.net/gis.html))
- It's got an awesome community!
]
.pull-right[
```{r, echo=FALSE, message=FALSE}
knitr::include_graphics("https://pbs.twimg.com/media/CkgvW4ZXEAAxumw.jpg:large")
```
]
---
# What is Geocomputation?
.pull-left[
> GeoComputation is about using the various different types of geodata and about developing relevant geo-tools within the overall context of a 'scientific' approach `r Citep(my_bib, "openshaw_geocomputation_2000", .opts = list(cite.style = "authoryear"))`.
]
.pull-right[
```{r, echo=FALSE, message=FALSE}
knitr::include_graphics("http://www.ccg.leeds.ac.uk/people/s.openshaw/s.openshaw.png")
```
]
--
- But we do differ from early definitions in one important way:
> At the turn of the 21st Century it was unrealistic to expect readers to be able to reproduce code examples, due to barriers preventing access to the necessary hardware, software and data
---
# Other aspects of the definition
--
> What distinguishes geocomputation from the older quantitative geography, is its emphasis on "creative and experimental" GIS applications `r Citep(my_bib, "longley_geocomputation_1998", .opts = list(cite.style = "authoryear"))`.
--
It's about doing "practical work that is beneficial or useful" `r Citep(my_bib, "openshaw_geocomputation_2000", .opts = list(cite.style = "authoryear"))`.
--
> about harnessing the power of modern computers to *do things* with geographic data.
---
# What's in the geocompr box?
.pull-left[
- Chapter 1: History + 'philosophy' = important
Foundations
- Starting from nothing
- Class definitions
- Spatial/attribute operations
- Projections
- Data IO
Extensions
- Advanced methods
- How to build your own functions
Applications
- A taster of what you can do
]
.pull-right[
```{r, echo=FALSE, message=FALSE, out.height="500"}
knitr::include_graphics("images/geocompr-index.png")
```
]
---
# Just do it!
--
"A little less conversation a little more action"
--
- "The sky is the limit with R" (Tom Hengl, 2018)
--
![](https://media.giphy.com/media/OMeGDxdAsMPzW/giphy.gif)
---
# A brief history of geographic data in R
R's predecesor was S, which was itself inspired by lisp `r Citep(my_bib, "chambers_extending_2016", .opts = list(cite.style = "authoryear"))`.
This is geographic analysis in S `r Citep(my_bib, "rowlingson_splancs_1993", .opts = list(cite.style = "authoryear"))`:
```
pts <- spoints(scan('cavities'))
uk()
pointmap(pts,add=T)
zoom()
uk(add=T)
pointmap(pts,add=T)
poly<-getpoly()
```
Still works today, 25 years later:
```{r}
library(splancs)
#> Spatial Point Pattern Analysis Code in S-Plus
#> Version 2 - Spatial and Space-Time analysis
```
---
# Live demo (try this)!
```{r, fig.height=4}
# install.packages("splancs"); library(splancs)
# example, interactive! (commented bits)
data(bodmin)
plot(bodmin$poly, asp=1, type="n")
pointmap(as.points(bodmin), add=TRUE)
# zoom()
# pointmap(as.points(bodmin), add=TRUE)
```
---
# Observations
- R' is robust and future-proof
- See a [video](https://www.youtube.com/watch?v=Luxllb_WAqY) of Roger Bivand's talk on the subject (live demo of R 0.49) + GitHub [repo](https://github.com/rsbivand/eRum18/blob/master/eRum_keynote_18.Rmd)
- Rs capabilities have evolved substantially since then!
---
# Case study: Geographic data visualization
- An area that illustrates the pace of development
- Rapid growth in number and diversity of packages
- Consolidation, but still many packages to choose from
- `plot()` still best for many tasks
--
- Vital for understanding geographic data.
--
- Empower youselves with maps!
---
# A brief history of geographic vizualisation I
- Neo Babylonian (626 BC - 539 BC) temple plan
Source:
`r Citep(my_bib, "talbert_ancient_2014", .opts = list(cite.style = "authoryear"))`
```{r, echo=FALSE, out.width="50%"}
knitr::include_graphics("https://raw.githubusercontent.com/jannes-m/erum18_geocompr/master/pres/rmd/img/neo-babylon-temple-map-circa-600-bc.png")
```
---
# A brief history of geographic vizualisation II
- Neo Babylonian (626 BC - 539 BC) map of the world
Source:
`r Citep(my_bib, "talbert_ancient_2014", .opts = list(cite.style = "authoryear"))`
```{r, echo=FALSE, out.width="50%"}
knitr::include_graphics("https://raw.githubusercontent.com/jannes-m/erum18_geocompr/master/pres/rmd/img/babylon-map.png")
```
---
# A brief history of geographic vizualisation III
- Humboldt's Naturgemälde (1807, *Geography of Plants*)
```{r, echo=FALSE}
knitr::include_graphics("https://upload.wikimedia.org/wikipedia/commons/thumb/7/7e/Zentralbibliothek_Z%C3%BCrich_-_Ideen_zu_einer_Geographie_der_Pflanzen_nebst_einem_Naturgem%C3%A4lde_der_Tropenl%C3%A4nder_-_000012142.jpg/2560px-Zentralbibliothek_Z%C3%BCrich_-_Ideen_zu_einer_Geographie_der_Pflanzen_nebst_einem_Naturgem%C3%A4lde_der_Tropenl%C3%A4nder_-_000012142.jpg")
```
<!-- - The mappa mundi - largest Mediaval map surviving (~1300 **AD**) -->
<!-- knitr::include_graphics("https://upload.wikimedia.org/wikipedia/commons/4/48/Hereford-Karte.jpg?download") -->
---
# A brief history of geographic data viz in R
"The core R engine was not designed specifically for the display and analysis
of maps, and the limited interactive facilities it offers have drawbacks in this
area" `r Citep(my_bib, "bivand_applied_2013", .opts = list(cite.style = "authoryear"))`.
--
Five years later...
--
"An example showing R's flexibility and evolving geographic capabilities is **leaflet**
`r Citep(my_bib, "R-leaflet", .opts = list(cite.style = "authoryear"))`,
a package for making interactive maps that has been extended by the R community, as we'll see in Chapter 9"
`r Citep(my_bib, "lovelace_geocomputation_2018", .opts = list(cite.style = "authoryear"))`.
---
# R's 'base' graphics: sp
```{r, echo=FALSE, eval=FALSE}
# from asdar:
library(sp)
data(meuse)
coordinates(meuse) = c("x", "y")
#layout(matrix(1:4, 2, 2, byrow = TRUE))
layout(matrix(1:4, 1, 4, byrow = TRUE))
par(mar = c(0,0,1,0))
plot(meuse, cex = 0.6)
title("points")
cc = coordinates(meuse)
m.sl = SpatialLines(list(Lines(list(Line(cc)), "mess")))
plot(m.sl)
title("lines")
data(meuse.riv)
meuse.lst = list(Polygons(list(Polygon(meuse.riv)), "meuse.riv"))
meuse.pol = SpatialPolygons(meuse.lst)
plot(meuse.pol, col = "grey")
title("polygons")
data(meuse.grid)
coordinates(meuse.grid) = c("x", "y")
meuse.grid <- as(meuse.grid, "SpatialPixels")
image(meuse.grid, col = "grey")
title("grid")
```
```{r, echo=FALSE, message=FALSE}
library(sp)
library(sf)
library(spData)
layout(matrix(1:3, 1, 3, byrow = TRUE))
nz_sp = as(nz, "Spatial")
nz_height_sp = as(nz_height, "Spatial")
plot(nz_height_sp, cex = 2)
title("points")
plot(nz_sp, col = "grey")
plot(nz_sp)
plot(nz_height_sp, add = TRUE, col = "red")
```
---
# Base R graphics: sp code
Credit: [asdar-book.org/](http://asdar-book.org/), reproducible code accompanying the book Applied Spatial Data Analysis with R (Pebesma et al. 2013).
```{r, eval=FALSE}
library(sp)
library(spData)
nz_sp = as(nz, "Spatial")
plot(nz_height_sp, cex = 2)
title("points")
plot(nz_sp, col = "grey")
plot(nz_height, add = TRUE, col = "red")
```
--
## Observations
- Passes arguments (e.g `cex` for symbol size) to `graphics::plot()`
- New command for each additional 'layer' (e.g. `title()`, `plot(..., add = TRUE)`)
- Black and white default output style
- Fast
---
# Base R graphics: sf
```{r}
plot(nz)
```
--
# tmap
- A diverse dedicated mapping R package
```{r}
library(tmap)
tm_shape(nz) +
tm_polygons("Median_income", palette = "RdYlBu")
```
---
# Why tmap?
- It is powerful and flexible.
- Concise syntax, attractive maps with minimal code, familiar to **ggplot2** users.
- Unique capability: same code -> static + interactive maps with switch `tmap_mode()`.
- Wide range of spatial classes (including `raster` objects) supported.
- Well documented + developed --- see [`tmap-nutshell`](https://cran.r-project.org/web/packages/tmap/vignettes/tmap-nutshell.html) and JSS paper
`r Citep(my_bib, "tennekes_tmap_2018", .opts = list(cite.style = "authoryear"))`.
```{r, fig.cap="tmap basics", out.width="32%", fig.show='hold', echo=FALSE, eval=FALSE}
# tmap basics
# Add fill layer to nz shape
tm_shape(nz) + tm_fill()
# Add border layer to nz shape
tm_shape(nz) + tm_borders()
# Add fill and border layers to nz shape
tm_shape(nz) + tm_fill() + tm_borders()
```
---
# Animations
- Are easy with **tmap** (section [9.3](http://geocompr.robinlovelace.net/adv-map.html#animated-maps) of geocompr)
```{r, echo=FALSE, out.width="80%"}
knitr::include_graphics("https://user-images.githubusercontent.com/1825120/38543030-5794b6f0-3c9b-11e8-9da9-10ec1f3ea726.gif")
```
---
# Interactive maps with mapview
- Lives at https://github.com/r-spatial/mapview
```{r, eval=FALSE}
m = mapview::mapview(nz)
m@map
```
--
- See Tim Applehans's talk Tomorrow
---
# Just do it! II
--
> Geographic data can save the world ([Robin Lovelace 2018, Jena](https://twitter.com/robinlovelace/status/983978278569553920))
--
> One of the most intriguing things about spatial data problems is that things which appear to be trivially easy to a human being can be surprisingly difficult on a computer (Wise 2001, from [geocompr.robinlovelace.net/algorithms.html](http://geocompr.robinlovelace.net/algorithms.html)).
--
![](https://media.giphy.com/media/OMeGDxdAsMPzW/giphy.gif)
---
# Finding a problem that is "beneficial or useful"
- With so much data emerging, more options than ever, including:
--
- Earth: how to replenish topsoil?
- Water: how to deal with aquifer depletion?
- Fire: how to encourage fire-resistent ecosystems?
---
## (Retrospective) justification
--
- It's supported by evidence! (see previous figure):
```{r, echo=FALSE}
# knitr::include_graphics("images/slr-long-clark-caption.png")
```
--
- Why study it? (are there 'bigger fish to fry'?)
<!-- what you're studying? Scientific justifications abound. -->
--
> We are headed for "much higher global average temperature than any interglacial in the past 1.2 million years and to sea levels significantly higher than at any time in the Holocene"
`r Citep(my_bib, "steffen_trajectories_2018", .opts = list(cite.style = "authoryear"))`
> Melting at the base of floating ice shelves [of the West Antarctic Ice Sheet (WAIS)] can lead to runaway retreat ... WAIS + Greenland have contributed at most ∼3 to 10 m
`r Citep(my_bib, "pollard_potential_2015", .opts = list(cite.style = "authoryear"))`
--
- Retrospective justifications like "I like bikes"
`r Citep(my_bib, "lovelace_propensity_2017", .opts = list(cite.style = "authoryear"))`
`r emojifont::emoji("negative_squared_cross_mark")`
--
- Pre-emptive justification like "it's the number one area I can make a difference" (you can always change direction) `r emojifont::emoji("heavy_check_mark")`
---
# A case study of doing something useful I
- Motivation: I like bikes!
- Tech: **shiny** + `leaflet::leafletOutput()` -> [pct.bike](http://www.pct.bike/)
`r Citep(my_bib, "lovelace_propensity_2017", .opts = list(cite.style = "authoryear"))`.
```{r, echo=FALSE}
knitr::include_graphics("https://raw.githubusercontent.com/npct/pct-team/master/figures/pct-frontpage.png")
```
---
# Sea level rise: a global geo* issue
- How to prepare for future sea level rise
`r Citep(my_bib, "clark_consequences_2016", .opts = list(cite.style = "authoryear"))`?
```{r, echo=FALSE}
knitr::include_graphics("images/slr-long-clark-et-al-2016.png")
```
---
# A case study of 'doing' something useful II
- Sea level rise could change the course of humanity
- See code: https://github.com/geocompr/geostats_18/blob/master/code/geocompr/slr.R
- Live demo, leading to this (to be continued Weds, see geostats_18):
```{r}
knitr::include_graphics("https://camo.githubusercontent.com/9ba73ec5a33f2e5a008d04517ea8ba12a7b0c01d/68747470733a2f2f692e696d6775722e636f6d2f634a62304977312e706e67")
```
---
# What's next for geocomputation with R?
- Geocomputation can be applied to many area and it's not a finished story
--
- Consolidation (Geocomputation workshops on Wednesday)
--
- Growth of cloud services + containerisation
- Big raster (Edzer and Markus's workshops on Thursday)
- Integration with other languages like Python
- More bridges
---
class: small
# References + contact
- To contact us about the book - go to [github.com/Robinlovelace/geocompr](https://github.com/Robinlovelace/geocompr)
- Social media: [#geocompr](https://twitter.com/hashtag/geocompr)
<!-- - Good old fashioned email: r.lovelace at leeds dot ac dot uk -->
--
```{r, 'refs', results="asis", echo=FALSE}
PrintBibliography(my_bib)
# RefManageR::WriteBib(my_bib, "refs-geostat.bib")
```