Skip to content

Commit d099188

Browse files
committed
Progress on #766
1 parent 9b27b7f commit d099188

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

Diff for: _04-ex.Rmd

+22-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
```{r 04-ex-e0, include=TRUE, message=FALSE}
22
library(sf)
33
library(dplyr)
4-
data(nz, package = "spData")
5-
data(nz_height, package = "spData")
4+
library(spData)
65
```
76

87
E1. It was established in Section \@ref(spatial-vec) that Canterbury was the region of New Zealand containing most of the 100 highest points in the country.
@@ -67,6 +66,27 @@ nz_height_combined %>%
6766
na.omit()
6867
```
6968

69+
E4. To test your knowledge of spatial predicates:
70+
71+
- Create an object representing Colorado state in the USA, e.g. with the command
72+
`colorado = us_states[us_states$NAME == "Colorado",]` (base R) or
73+
`colorado = us_states %>% filter(NAME == "Colorado")` (tidyverse).
74+
- Create a new object representing all the objects that intersect, in some way, with Colorado and plot the result.
75+
- Create another object representing all the objects that touch Colorado and plot the result.
76+
77+
```{r 04-ex-4}
78+
plot(us_states$geometry)
79+
plot(Colorado$geometry, col = 2, add = TRUE)
80+
colorado = us_states[us_states$NAME == "Colorado", ]
81+
intersects_with_colorado = us_states[colorado, , op = st_intersects]
82+
touches_colorado = us_states[colorado, , op = st_touches]
83+
plot(us_states$geometry)
84+
plot(touches_colorado$geometry, col = "grey", add = TRUE)
85+
```
86+
87+
88+
# What are the neighbouring states of Colorado?
89+
7090
E4. Use `dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))`, and reclassify the elevation in three classes: low (<300), medium and high (>500).
7191
Secondly, read the NDVI raster (`ndvi = rast(system.file("raster/ndvi.tif", package = "spDataLarge"))`) and compute the mean NDVI and the mean elevation for each altitudinal class.
7292

0 commit comments

Comments
 (0)