forked from Open-EO/openeo-hackathon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution-r-gee.rmd
122 lines (96 loc) · 3.6 KB
/
solution-r-gee.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
# openEO Hackathon - Solution R client / GEE back-end
## Task 1
Installing and loading the required packages:
```{r}
if (!require(devtools)) {
install.packages("devtools",dependencies=TRUE)
library(devtools)
}
# Sometimes the devtools fail to install some dependencies.
# You may need to install Rcpp and rlang manually by uncommenting thw following two lines:
# install.packages("Rcpp")
# install.packages("rlang")
install_github(repo="Open-EO/openeo-r-client",ref="v0.2.2",dependencies=TRUE)
library(openeo)
```
Connecting to the openEO Earth Engine back-end. You may need to change the credentials:
```{r}
gee.url = "http://giv-project8.uni-muenster.de"
gee.pwd = "test123"
gee.user = "groupX"
con = connect(gee.url,user=gee.user,password = gee.pwd)
```
Requesting the capabilities that are provided by the back-end:
```{r}
con %>% listCapabilities()
```
## Task 2
Requesting the processes offered by the back-end:
```{r}
con %>% listProcesses()
```
Requesting the arguments required for the ndvi process:
```{r}
con %>% describeProcess("NDVI")
```
Requesting the products offered by the back-end:
```{r}
con %>% listCollections()
```
Requesting information about the Sentinel-2 dataset, including the temporal and spatial extent:
```{r}
s2 = con %>% describeCollection("COPERNICUS/S2") # This may take some time to complete if GDAL is not installed
s2
s2$time
s2$extent
```
## Task 3
First of all, requesting the supported file formats to see whether PNG or GeoTiff (GTiff) is supported and color stretching is required for PNG files or not:
```{r}
con %>% listFormats()
```
Only PNG files are supported and therefore we need to apply color stretching.
We construct the process graph using a process graph builder. The following steps are required:
1. Construct the process graph builder
2. Specify the required dataset (`COPERNICUS/S2`)
3. Filtering by date range
4. Filtering by bounding box
5. Calculating the NDVI on the red band B4 and the near-infrared band B8
6. Computing a maximum time composite
7. Strecthing the colors
8. Executing the process graph on the back-end, requesting a PNG file with the name `task3.png`
```{r}
pgb = con %>% pgb()
task = collection("COPERNICUS/S2") %>%
pgb$filter_daterange(from = "2018-01-01", to= "2018-01-15") %>%
pgb$filter_bbox(left = 16.138916,top= 48.320647, right= 16.524124, bottom= 48.138600, srs="EPSG:4326") %>%
pgb$NDVI(red = "B4", nir = "B8") %>%
pgb$max_time() %>%
pgb$stretch_colors(min = -1, max = 1)
con %>% executeTask(task=task, format = "PNG", output_file = "task3.png")
```
## Task 4
Checking if the process `zonal_statistics` is provided by the back-end:
```{r}
con %>% describeProcess("zonal_statistics")
```
If you haven't done so yet, download the GeoJSON file containing the polygon:
```{r}
polygonURL = "https://raw.githubusercontent.com/Open-EO/openeo-hackathon/master/test-cases/polygon.json"
download.file(polygonURL, "polygon.json", quiet=TRUE)
```
Uploading the GeoJSON file containing the polygon:
```{r}
con %>% uploadUserData(content="polygon.json",target="polygon.json")
```
Construct and execute the process graph. Downloads the file in JSON format with the file name `task5.json`:
```{r}
task5 = collection("COPERNICUS/S2") %>%
pgb$filter_daterange(from="2018-01-01", to="2018-01-15") %>%
pgb$filter_bbox(left=16.138916, top=48.320647, right=16.524124, bottom=48.138600, srs="EPSG:4326") %>%
pgb$filter_bands(bands = "B8") %>%
pgb$zonal_statistics(regions = "polygon.json", func = "mean")
con %>% executeTask(task=task5, format="JSON", output_file = "task5.json")
```
## Task 5
Task 5 is currently not implemented in the openEO Earth Engine back-end.