-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
182 lines (113 loc) · 4.07 KB
/
README.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
title: 'targets-rgee-extract'
output:
github_document:
toc: true
---
```{r include=FALSE}
knitr::opts_chunk$set(
fig.path = "man/figures/"
)
library(targets)
library(sf)
```
## Goal
Learning Earth Engine (though I highly recommend it), can be a bit of overhead
if you just need to, for example, sample a land cover product for a
collection of points. Great packages like `sf` and `terra` exist in the
R ecosystem for sampling from rasters, but Earth Engine (and its user community)
offers an incredible resource of data sets (see below) that can be accessed
without downloading any large files to your local machine.
With that in mind, this project combines `targets` and
`rgee` with a couple simple helper functions, to make simple operations
with Earth Engine easier. We won't cover anywhere near the full potential
of Earth Engine, just things like sampling images or image collections with
different types of features (for now).
Working with Earth Engine through the Python package (or through `rgee` which
also goes through the Python package via `reticulate`) has one main challenge
compared to the JavaScript API for Earth Engine: setup. See below for steps that
worked for me. You'll first need to install system dependencies,
then install some R packages and authenticate with Earth Engine.
`renv` is used to track required R and Python packages.
Open an issue, submit a PR, or otherwise get in touch if you have any
thoughts or would like to contribute. Thanks!
## Usage
This repository is a [template repository](https://docs.github.com/en/repositories/creating-and-managing-repositories/creating-a-repository-from-a-template), so you can select "Use this template"
to start a new project quickly with the setup and example targets workflow.

Then see the [Setup](#setup) section below for installing system and R
dependencies.
## Neat data sets
TODO
- https://developers.google.com/earth-engine/datasets/
- https://samapriya.github.io/awesome-gee-community-datasets/
## Outputs
### Sample image with polygons
For example, extract the maximum elevation in each polygon ("elevation"):
```{r}
tar_load(sample_image_with_polys)
head(sample_image_with_polys)
plot(sample_image_with_polys)
```
### Sample image with points
For example, extract the leading tree species at each point ("b1"):
```{r}
tar_load(sample_image_with_points)
head(sample_image_with_points)
plot(sample_image_with_points['b1'])
```
### Sample image collections with polygons
For example, extract the monthly water detection within polygons (2 = water, 1 = land)
```{r}
tar_load(sample_image_collection_with_polygons)
head(sample_image_collection_with_polygons)
plot(sample_image_collection_with_polygons)
```
### Sample image collections with points
For example, Landsat 8 bands at each point:
```{r}
tar_load(sample_image_collection_with_points)
head(sample_image_collection_with_points)
plot(sample_image_collection_with_points)
```
Note - these are spread wide, where each measure is a new column. That
means they will likely need to be restructured for further processing.
## Setup
System dependencies:
- gcloud (https://cloud.google.com/sdk/docs/install)
- python >= 3.5
- earthengine python package
First time using this project:
```{r, eval = FALSE}
Sys.setenv(DOWNLOAD_STATIC_LIBV8 = 1)
install.packages('renv')
renv::restore()
rgee::ee_Authenticate()
rgee::ee_Initialize(drive = TRUE)
```
### Dependencies
System dependencies above.
Details for `rgee` here: https://r-spatial.github.io/rgee/articles/rgee01.html#installation
#### `rgee`
The "first time" section above should get you set up, but if you are starting from scratch:
Install:
```{r, eval = FALSE}
library(rgee)
ee_install(py_env = 'rgee')
```
Authenticate:
```{r, eval = FALSE}
ee_Initialize()
```
Check:
```{r, eval = FALSE}
ee_check()
```
Renv + python:
```{r, eval = FALSE}
renv::use_python(reticulate::py_discover_config()$python)
renv::snapshot()
```
## Resources
- `rgee`
- https://csaybar.github.io/rgee-examples/