-
-
Notifications
You must be signed in to change notification settings - Fork 593
/
Copy path_08-ex.Rmd
75 lines (56 loc) · 2.38 KB
/
_08-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
```{r 08-ex-e0}
library(sf)
library(terra)
```
E1. List and describe three types of vector, raster, and geodatabase formats.
```{asis}
Vector formats: Shapefile (old format supported by many programs), GeoPackage (more recent format with better support of attribute data) and GeoJSON (common format for web mapping).
Raster formats: GeoTiff, Arc ASCII, R-raster (see book for descriptions).
Database formats: PostGIS, SQLite, FileGDB (see book for details).
```
E2. Name at least two differences between `read_sf()` and the more well-known function `st_read()`.
```{asis}
`st_read()` prints outputs and keeps strings as text strings (`st_read()` creates factors). This can be seen from the source code of `read_sf()`, which show's it wraps `st_read()`:
```
```{r 08-ex-e2}
read_sf
```
E3. Read the `cycle_hire_xy.csv` file from the **spData** package as a spatial object (Hint: it is located in the `misc` folder).
What is a geometry type of the loaded object?
```{r 08-ex-e3}
c_h = read.csv(system.file("misc/cycle_hire_xy.csv", package = "spData")) %>%
st_as_sf(coords = c("X", "Y"))
c_h
```
E4. Download the borders of Germany using **rnaturalearth**, and create a new object called `germany_borders`.
Write this new object to a file of the GeoPackage format.
```{r 08-ex-e4}
library(rnaturalearth)
germany_borders = ne_countries(country = "Germany", returnclass = "sf")
plot(germany_borders)
st_write(germany_borders, "germany_borders.gpkg")
```
E5. Download the global monthly minimum temperature with a spatial resolution of five minutes using the **geodata** package.
Extract the June values, and save them to a file named `tmin_june.tif` file (hint: use `terra::subset()`).
```{r 08-ex-e5}
library(geodata)
gmmt = worldclim_global(var = "tmin", res = 5, path = tempdir())
names(gmmt)
plot(gmmt)
gmmt_june = terra::subset(gmmt, "wc2.1_5m_tmin_06")
plot(gmmt_june)
writeRaster(gmmt_june, "tmin_june.tif")
```
E6. Create a static map of Germany's borders, and save it to a PNG file.
```{r 08-ex-e6}
gmmt = getData("worldclim", var = "tmin", res = 5)
gmmt_june = raster::subset(gmmt, "tmin6")
writeRaster(gmmt_june, "tmin_june.tif")
```
E7. Create an interactive map using data from the `cycle_hire_xy.csv` file.
Export this map to a file called `cycle_hire.html`.
```{r 08-ex-e7}
library(mapview)
mapview_obj = mapview(c_h, zcol = "nbikes", legend = TRUE)
mapshot(mapview_obj, file = "cycle_hire.html")
```