forked from geocompx/geocompr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_02-ex.Rmd
77 lines (55 loc) · 2.25 KB
/
_02-ex.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
```{r}
library(sf)
library(spData)
library(terra)
```
<!--toDo: rl -->
<!--add solutions to E1-E3!-->
E1. Use `summary()` on the geometry column of the `world` data object. What does the output tell us about:
- Its geometry type?
- The number of countries?
- Its coordinate reference system (CRS)?
```{r}
summary(world)
```
E2. Run the code that 'generated' the map of the world in Section 2.2.4 Base plot arguments.
Find two similarities and two differences between the image on your computer and that in the book.
- What does the `cex` argument do (see `?plot`)?
- Why was `cex` set to the `sqrt(world$pop) / 10000`?
- Bonus: experiment with different ways to visualize the global population.
```{r}
```
E3. Use `plot()` to create maps of Nigeria in context (see Section 2.2.4 Base plot arguments).
- Adjust the `lwd`, `col` and `expandBB` arguments of `plot()`.
- Challenge: read the documentation of `text()` and annotate the map.
```{r}
```
E4. Create an empty `SpatRaster` object called `my_raster` with 10 columns and 10 rows.
Assign random values between 0 and 10 to the new raster and plot it.
```{r, message = FALSE}
my_raster = rast(ncol = 10, nrow = 10,
vals = sample(0:10, size = 10 * 10, replace = TRUE))
plot(my_raster)
```
E5. Read-in the `raster/nlcd.tif` file from the **spDataLarge** package.
What kind of information can you get about the properties of this file?
```{r, message = FALSE}
nlcd = rast(system.file("raster/nlcd.tif", package = "spDataLarge"))
dim(nlcd) # dimensions
res(nlcd) # resolution
ext(nlcd) # extent
nlyr(nlcd) # number of layers
cat(crs(nlcd)) # CRS
```
E6. Check the CRS of the `raster/nlcd.tif` file from the **spDataLarge** package.
What kind of information you can learn from it?
```{r, message = FALSE}
cat(crs(nlcd))
```
```{asis, message = FALSE}
The WKT above describes a two-dimensional projected coordinate reference system.
It is based on the GRS 1980 ellipsoid with North American Datum 1983 and the Greenwich prime meridian.
It used the Transverse Mercator projection to transform from geographic to projected CRS (UTM zone 12N).
Its first axis is related to eastness, while the second one is related to northness, and both axes have units in meters.
The SRID of the above CRS is "EPSG:26912".
```