rgee: An R package for interacting with Google Earth Engine

Google Earth Engine (Gorelick et al., 2017) is a cloud computing platform designed for planetary-scale environmental data analysis. Its multi-petabyte data catalog and computation services are accessed via an Internet-accessible API. The API is exposed through JavaScript and Python client libraries. Google provides a browser-based IDE for the JavaScript API, and while convenient and useful for rapid data exploration and script development, it does not allow third-party package integration, relying solely on Google Maps and Google Charts for data visualization, and proprietary systems for metadata viewing and asset management. In contrast, the Python and Node.js distributions offer much flexibility for developers to integrate with third-party libraries. However, without the structure of a dedicated IDE, casual users can be left directionless and daunted. A significant gap exists between these two offerings (Google-supported JavaScript IDE and base client libraries) where convenience and flexibility meet. We propose to fill this gap with an R package that wraps the Earth Engine Python API to provide R users with a familiar interface, rapid development features, and flexibility to analyze data using open-source, third-party packages.

rgee is an Earth Engine (EE) client library for R that allows users to leverage the strengths of the R spatial ecosystem and Google Earth Engine in the same workflow. All of the Earth Engine Python API classes, modules, and functions are made available through the reticulate package (Ushey, Allaire, & Tang, 2020), which embeds a Python session within an R session, enabling seamless interoperability. Additionally, rgee adds several new features such as (i) new I/O design, (ii) interactive map display, (iii) easy extraction of time series, (iv) asset management interface, and (v) metadata display. In addition, rgee also makes it possible to execute Earth Engine Python code from within R, making the translation of large Python projects unnecessary.

Interactive Map Display
rgee offers interactive map display through Map$addLayer, an R function mimicking the mapping module of the Earth Engine JavaScript Code Editor. Map$addLayer takes advantage of the getMapId EE method to fetch and return an ID dictionary being used to create layers in a mapview (Appelhans, Detsch, Reudenbach, & Woellauer, 2020) object. Users can specify visualization parameters to Map$addLayer by using the visParams argument, as demostrated below:

# Centers the map view
Map$centerObject(image)

Extraction of time series
rgee can extract values from ee$Image and ee$ImageCollection objects at a certain location based on ee$Geometry, ee$Feature, ee$FeatureCollection and sf objects. If the geometry is a polygon, users can summarize the values using built-in Earth Engine reducer functions. The code below explains how to extract the average areal rainfall from North Carolina counties using the TerraClimate dataset.

Metadata display
The ee_print function can save and display all metadata related to EE spatial objects. With ee_print, users can retrieve information about the number of images or features, number of bands or geometries, number of pixels, geotransform, datatype, properties and approximate object size. ee_print can be used inside debugging pipelines (e.g. linking with ee$Image$aside). library(rgee) ee_Initialize() l8 <-ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318") ee_print(l8) Figure 4: Metadata for a Landsat 8 Image.

Availability
rgee is an open-source software package made available under the Apache 2.0 license. It can be installed through GitHub repository using the remotes package: remotes::install_github("rspatial/rgee"). A series of examples for using rgee are available at https://r-spatial.github. io/rgee.