-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_data.Rmd
112 lines (90 loc) · 3.24 KB
/
make_data.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
---
title: "Land cover data from ESA's GlobCover"
csl: the-american-naturalist.csl
output:
html_document:
theme: cerulean
toc: yes
pdf_document:
toc: yes
<!-- bibliography: references.bib -->
editor_options:
chunk_output_type: console
---
<!--
IMAGES:
Insert them with: ![alt text](image.png)
You can also resize them if needed: convert image.png -resize 50% image.png
If you want to center the image, go through HTML code:
<div style="text-align:center"><img src ="image.png"/></div>
REFERENCES:
For references: Put all the bibTeX references in the file "references.bib"
in the current folder and cite the references as @key or [@key] in the text.
Uncomment the bibliography field in the above header and put a "References"
title wherever you want to display the reference list.
-->
<style type="text/css">
.main-container {
max-width: 1370px;
margin-left: auto;
margin-right: auto;
}
</style>
```{r general options, include = FALSE}
knitr::knit_hooks$set(
margin = function(before, options, envir) {
if (before) par(mgp = c(1.5, .5, 0), bty = "n", plt = c(.105, .97, .13, .97))
else NULL
},
prompt = function(before, options, envir) {
options(prompt = if (options$engine %in% c("sh", "bash")) "$ " else "> ")
})
knitr::opts_chunk$set(margin = TRUE, prompt = TRUE, comment = "", eval = FALSE,
collapse = TRUE, cache = FALSE, autodep = TRUE,
dev.args = list(pointsize = 11), fig.height = 3.5,
fig.width = 4.24725, fig.retina = 2, fig.align = "center")
options(width = 137)
```
```{r}
library(sp)
library(raster)
library(ecomore)
```
Downloading the 2009 [GlobCover](http://due.esrin.esa.int/page_globcover.php)
data (** 300-m resolution**) from [ESA](https://www.esa.int/ESA):
```{r}
if (! dir.exists("data-raw")) dir.create("data-raw")
download.file("http://due.esrin.esa.int/files/Globcover2009_V2.3_Global_.zip", "data-raw/Globcover2009_V2.3.zip")
download.file("http://due.esrin.esa.int/files/Globcover_V2.2_Global.zip", "data-raw/Globcover2005_V2.2.zip")
```
Unzipping:
```{r}
unzip("data-raw/Globcover2009_V2.3.zip", exdir = "data-raw/Glocover2009_V2.3")
unzip("data-raw/Globcover2005_V2.2.zip", exdir = "data-raw/Glocover2005_V2.2")
```
Loading:
```{r}
Globcover2009_V2.3 <- raster("data-raw/Glocover2009_V2.3/GLOBCOVER_L4_200901_200912_V2.3.tif")
Globcover2005_V2.2 <- raster("data-raw/Glocover2005_V2.2/GLOBCOVER_200412_200606_V2.2_Global_CLA.tif")
```
Loading the Lao provinces polygons from [GADM](https://gadm.org):
```{r}
if (! file.exists("gadm36_LAO_1_sp.rds"))
download.file("https://biogeo.ucdavis.edu/data/gadm3.6/Rsp/gadm36_LAO_1_sp.rds", "data-raw/gadm36_LAO_1_sp.rds")
gadm36_LAO_1 <- readRDS("data-raw/gadm36_LAO_1_sp.rds")
```
Selecting the polygon of Vientiane:
```{r}
vientiane <- gadm36_LAO_1[gadm36_LAO_1$NAME_1 == "Vientiane [prefecture]", ]
```
Cropping:
```{r}
Globcover2009_V2.3 <- crop_raster(Globcover2009_V2.3, vientiane)
Globcover2005_V2.2 <- crop_raster(Globcover2005_V2.2, vientiane)
```
Saving to disk:
```{r}
if (! dir.exists("data")) dir.create("data")
writeRaster(Globcover2009_V2.3, "data/Globcover2009_V2.3.tif", "GTiff", overwrite = TRUE)
writeRaster(Globcover2005_V2.2, "data/Globcover2005_V2.2.tif", "GTiff", overwrite = TRUE)
```