之前有推送过关于GEE的文章,后台反馈的情况来看,很多人是想用,但是由于某些众所周知的原因无法使用GEE,还是那句话懂的人自然懂,想使用的人肯定想办法能用得上。就像中国第一封电子邮件富有深意的那句话:
“Across the Great Wall we can reach every corner in the world.(越过长城,走向世界)”,
今天推荐基于R语言的GEE”工具箱“!
Google Earth Engine for R
rgee
is a binding package for calling Google Earth Engine API from within R. Additionally, several functions have been implemented to make simple the connection with the R spatial ecosystem. The current version of rgee has been built considering theearthengine-api 0.1.227.
Note that access to Google Earth Engine is only available to registered users
.
GitHub:https://github.com/r-spatial/rgee
More than 250+ examples using GEE with R are available here
Quick Start User's Guide for rgee in Portuguese and Spanish.
Created by:
POR: Andres Luiz Lima Costa http://amazeone.com.br/index.php
Google Earth Engine is a cloud-based platform that allows users to have an easy access to a petabyte-scale archive of remote sensing data and run geospatial analysis on Google’s infrastructure. Currently, Google offers support only for Python and JavaScript.
rgee
will fill the gap
starting to provide support to R!
. Below you will find the comparison between the syntax of
rgee
and the two Google-supported client libraries.
JS (Code Editor)
Python
R
var db = 'CGIAR/SRTM90_V4'var image = ee.Image(db)print(image.bandNames())#> 'elevation'
Quite similar, isn’t it?
. However, there are additional smaller changes should consider when using Google Earth Engine with R. Please check the consideration section before you start coding!
Installation
Install the
rgee
package from GitHub is quite simple, you just have to run in your R console as follows:
remotes::install_github("r-spatial/rgee")
rgee
depends on sf
. Therefore, is necessary to install its external libraries, follow the installation steps specified here.
Prior to using
rgee
you will need to install a
Python version higher than 3.5
in their system.
rgee
counts with an installation function (ee_install) which helps to setup
rgee
correctly:
library(rgee)
## It is necessary just once
ee_install()
# Initialize Earth Engine!
ee_Initialize()
Additionally, you might use the functions below for checking the status of rgee dependencies and delete credentials.
ee_check() # Check non-R dependencies
ee_clean_credentials() # Remove credentials of a specific user
ee_clean_pyenv() # Remove reticulate system variables
Also, consider looking at the setup section for more information on customizing your Python installation.
Package Conventions
All
rgee
functions have the prefix ee_. Auto-completion is your friend :).
Full access to the Earth Engine API with the prefix
ee$…
.
Authenticate and Initialize the Earth Engine R API with
ee_Initialize
. It is necessary once by session!.
rgee
is “pipe-friendly”, we re-exports %>%, but
rgee
does not require its use.
Quick Demo
1. Compute the trend of night-time lights (JS version)
Authenticate and Initialize the Earth Engine R API.
library(rgee)
ee_Initialize()
#ee_reattach() # reattach ee as a reserve word
Adds a band containing image date as years since 1991.
createTimeBand <-function(img) {
year <- ee$Date(img$get('system:time_start'))$get('year')$subtract(1991L)
ee$Image(year)$byte()$addBands(img)
Map the time band creation helper over the night-time lights collection.
Extract monthly precipitation values from the Terraclimate ImageCollection through ee_extract. ee_extract works similar to raster::extract, you just need to define: the ImageCollection object (x), the geometry (y), and a function to summarize the values (fun).
ee_nc_rain <- ee_extract(x = terraclimate, y = nc, sf = FALSE)
colnames(ee_nc_rain) <- sprintf("%02d", 1:12)
ee_nc_rain$name <- nc$NAME
rgee is not a native Earth Engine API like the Javascript or Python client, to do this would be extremely hard, especially considering that the API is in active development. So, how is it possible to run Earth Engine using R? the answer is reticulate. reticulate is an R package designed to allow a seamless interoperability between R and Python. When an Earth Engine request is created in R, reticulate will transform this piece into Python. Once the Python code is obtained, the Earth Engine Python API transform the request to a JSON format. Finally, the request is received by the Google Earth Engine Platform thanks to a Web REST API. The response will follow the same path.
workflow
Code of Conduct
Please note that the rgee project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.
Contributing Guide
? Thanks for taking the time to contribute! ?? Please review our Contributing Guide.
Share the love ❤️
Think rgee is useful? Let others discover it, by telling them in person via Twitter or a blog post.
Using rgee for a paper you are writing? Consider citing it
citation("rgee")
To cite rgee in publications use:
C Aybar, Q Wu, L Bautista, R Yali and A Barja (2020) rgee: An R
package for interacting with Google Earth Engine Journal of Open
Source Software URL https://github.com/r-spatial/rgee/.
A BibTeX entry for LaTeX users is
@Article{,
title = {rgee: An R package for interacting with Google Earth Engine},
author = {Cesar Aybar and Quisheng Wu and Lesly Bautista and Roy Yali and Antony Barja},