Abstract
The purpose of this chapter is to introduce rgee, a non-official API for Earth Engine. You will explore the main features available in rgee and how to set up an environment that integrates rgee with third-party R and Python packages. After this chapter, you will be able to combine R, Python, and JavaScript in the same workflow.
You have full access to this open access chapter, Download chapter PDF
Overview
The purpose of this chapter is to introduce rgee, a non-official API for Earth Engine. You will explore the main features available in rgee and how to set up an environment that integrates rgee with third-party R and Python packages. After this chapter, you will be able to combine R, Python, and JavaScript in the same workflow.
-
Becoming familiar with rgee, the Earth Engine R API interface.
-
Integrating rgee with other R packages.
-
Displaying interactive maps.
-
Integrating Python and R packages using reticulate.
-
Combining Earth Engine JavaScript and Python APIs with R.
Assumes you know how to
1 Introduction to Theory
R is a popular programming language established in statistical science with large support in reproducible research, geospatial analysis, data visualization, and much more. To get started with R, you will need to satisfy some extra software requirements. First, install an up-to-date R version (at least 4.0) in your work environment. The installation procedure will vary depending on your operating system (i.e., Windows, Mac, or Linux). Hands-On Programming with R (Garrett Grolemund 2014, Appendix A) explains step by step how to proceed. We strongly recommend that Windows users install Rtools to avoid compiling external static libraries.
If you are new to R, a good starting point is the book Geocomputation with R (Lovelace et al. 2019) or Spatial Data Science with Application in R (Pebesma and Bivand 2019). In addition, we recommend using an integrated development environment (e.g., Rstudio) or a Code Editor (e.g., Visual Studio Code) to create a suitable setting to display and interact with R objects.
The following R packages must be installed (find more information in the R manual) in order to go through the practicum section.
![A twelve-line algorithm to use install packages to install R packages from the C R A N respiratory. Some steps of the algorithm connect Python with R, install R packages from remote repositories, and read write, manipulate, analyze, and model spatial data.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figa_HTML.png)
Earth Engine officially supports client libraries only for the JavaScript and Python programming languages. While the Earth Engine Code Editor offers a convenient environment for rapid prototyping in JavaScript, the lack of a mechanism for integration with local environments makes the development of complex scripts tricky. On the other hand, the Python client library offers much versatility, enabling support for third-party packages. However, not all Earth and environmental scientists code in Python. Hence, a significant number of professionals are not members of the Earth Engine community. In the R ecosystem, rgee (Aybar et al. 2020) tries to fill this gap by wrapping the Earth Engine Python API via reticulate. The rgee package extends and supports all the Earth Engine classes, modules, and functions, working as fast as the other APIs.
Figure 31.1 illustrates how rgee bridges the Earth Engine platform with the R ecosystem. When an Earth Engine request is created in R, rgee transforms this piece of code into Python. Next, the Earth Engine Python API converts the Python code into JSON. Finally, the JSON file request is received by the server through a Web REST API. Users could get the response using the getInfo method by following the same path in reverse.
2 Practicum
2.1 Section 1. Installing rgee
To run, rgee needs a Python environment with two packages: NumPy and earthengine-api. Because instructions change frequently, installation is explained at the following checkpoint:
Code Checkpoint F64a. The book’s repository contains information about setting up the rgee environment.
After installing both the R and Python requirements, you can now initialize your Earth Engine account from within R. Consider that R, in contrast to JavaScript and Python, supports three distinct Google APIs: Earth Engine, Google Drive, and Google Cloud Storage (GCS).
The Google Drive and GCS APIs will allow you to transfer your Earth Engine completed task exports to a local environment automatically. In these practice sessions, we will use only the Earth Engine and Google Drive APIs. Users that are interested in GCS can look up and explore the GCS vignette. To initialize your Earth Engine account alongside Google Drive, use the following commands.
![A four-line algorithm for Initializing just Earth Engine and initializing Earth Engine and G D. The commands read, e e initialize left parenthesis right parenthesis and e e initialize left parenthesis drive = true right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figb_HTML.png)
If the Google account is verified and the permission is granted, you will be directed to an authentication token. Copy and paste this token into your R console. Consider that the GCS API requires setting up credentials manually; look up and explore the rgee vignette for more information. The verification step is only required once; after that, rgee saves the credentials in your system.
Code Checkpoint F64b. The book’s repository contains information about what your code should look like at this point.
2.2 Section 2. Creating a 3D Population Density Map with rgee and rayshader
First, import the rgee, rayshader, and raster packages.
![A three-line command reads, library left parenthesis ray shader right parenthesis, library left parenthesis raster right parenthesis, and library left parenthesis r g e e right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figc_HTML.png)
Initialize the Earth Engine and Google Drive APIs using ee_Initialize. Both credentials must come from the same Google account.
![A one-line command reads, e e underscore initialize left parenthesis drive = true right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figd_HTML.png)
Then, we will access the WorldPop Global Project Population Data dataset. In rgee, the Earth Engine spatial classes (ee$Image, ee$ImageCollection, and ee$FeatureCollection) have a special attribute called Dataset. Users can use it along with autocompletion to quickly find the desired dataset.
![A three-line command to access the classes for the following. Collections, population underscore data, and population underscore data underscore max.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Fige_HTML.png)
If you need more information about the Dataset, use ee_utils_dataset_display to go to the official documentation in the Earth Engine Data Catalog.
![A one-line command reads, population underscore data % greater than % e e underscore utils underscore dataset underscore display left parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figf_HTML.png)
The rgee package provides various built-in functions to retrieve data from Earth Engine (Aybar et al. 2020). In this example, we use ee_as_raster, which automatically converts an ee$Image (server object) into a RasterLayer (local object).
![An eleven-line algorithm to access the following built-in functions of the r g e e package. E e $ geometry $ rectangle and e e underscore a s underscore raster. The command home, p c-user 0 1 population dot t i f changes the user’s path.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figg_HTML.png)
Now, turn a RasterLayer into a matrix suitable for rayshader.
![A one-line command reads, pop underscore matrix less than hyphen raster underscore to underscore matrix left parenthesis population underscore data underscore l y underscore local right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figh_HTML.png)
Next, modify the matrix population density values, adding:
-
Texture, based on five colors (lightcolor, shadowcolor, leftcolor, rightcolor, and centercolor; see rayshader::create_texture documentation)
-
Color and shadows (rayshader::sphere_shade)
![A six-line pop matrix algorithm works with the sphere underscore shade and plot underscore 3 d classes. The values for zoom, theta, z scale, solid depth, solid color, shadow depth, shadow color, shadow width, and window size are given under the second class.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figi_HTML.png)
Lastly, define a title and subtitle for the plot. Use rayshader::render_snapshot to export the final results (Fig. 31.2).
![A fourteen-line algorithm to work with the text less than hyphen paste 0 and render underscore snapshot classes. The attributes for file name, title text, title size, title color, and title font are given under the second class.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figj_HTML.png)
Code Checkpoint F64c. The book’s repository contains information about what your code should look like at this point.
2.3 Section 3. Displaying Maps Interactively
Similar to the Code Editor, rgee supports the interactive visualization of spatial Earth Engine objects by Map$addLayer. First, let’s import the rgee and cptcity packages. The cptcity R package is a wrapper to the cpt-city color gradients web archive.
![A three-line command reads, library left parenthesis r g e e right parenthesis, library left parenthesis c p t city right parenthesis, e e underscore initialize left parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figk_HTML.png)
We will select an ee$Image; in this case, the Shuttle Radar Topography Mission 90m (SRTM-90) Version 4.
![A one-line command reads, d e m less than hyphen e e $ image $ dataset $ C G I A R underscore S R T M 90 underscore V 4.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figl_HTML.png)
Then, we will set the visualization parameters as a list with the following elements.
-
min: value(s) to map to 0
-
Max: value(s) to map to 1
-
palette: a list of CSS-style color strings.
![A five-line algorithm to access the viz less than hyphen list class and work with the attributes of the min value, max value, and palette.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figm_HTML.png)
Then, we will create a simple display using Map$addLayer.
![A one-line command reads, m 1 less than hyphen map $ add layer left parenthesis d e m, vis params = viz, name = double quotation starts S R T M double quotation ends, shown = true right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Fign_HTML.png)
Optionally, you could add a custom legend using Map$addLayer (Fig. 31.3).
![A two-line command reads, pal less than hyphen map $ add legend left parenthesis viz right parenthesis, m 1 + pal.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figo_HTML.png)
The procedure to display ee$Geometry, ee$Feature, and ee$FeatureCollections objects is similar to the previous example effected on an ee$Image. Users just need to change the arguments: eeObject and visParams.
First, Earth Engine geometries (Fig. 31.4).
![A four-line algorithm to display the following objects. E e $ geometry $ point, e e $ feature $ buffer, map $ center object, and map $ add layer. The e e object for map $ add layer is e e $ geometry $ polygon.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figp_HTML.png)
Next, Earth Engine feature collections (Fig. 31.5).
![A four-line algorithm to display the following objects. E e $ feature collection $ dataset $, map $ set center, and map $ add layer left parenthesis building right parenthesis. The e e object for map $ add layer left parenthesis building right parenthesis is a e e $ feature collection.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figq_HTML.png)
The rgee functionality also supports the display of ee$ImageCollection via Map$addLayers (note the extra “s” at the end). Map$addLayers will use the same visualization parameters for all the images (Fig. 31.6). If you need different visualization parameters per image, use a Map$addLayer within a for loop.
![A thirteen-line algorithm executes the following tasks. Defining an image collection. Setting viz params. Printing map results interactively.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figr_HTML.png)
Another useful rgee feature is the comparison operator (|), which creates a slider in the middle of the canvas, permitting quick comparison of two maps. For instance, load a Landsat 4 image:
![A one-line command reads, land sat less than sign hyphen e e $ image left parenthesis single quotation starts land sat slash L T 0 4 slash C 0 1 slash T 1 slash L T 0 4 underscore 0 0 8 0 6 7 underscore 1 9 8 9 0 9 1 7 single quotation ends right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figs_HTML.png)
Calculate the Normalized Difference Snow Index.
![A one-line command reads, n d s i less than symbol hyphen land sat $ normalized difference left parenthesis C left parenthesis single quotation starts B 3 single quotation ends, single quotation starts B 5 single quotation ends right parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figt_HTML.png)
Define a constant value and use ee$Image$gte to return a binary image where pixels greater than or equal to that value are set as 1 and the rest are set as 0. Next, filter 0 values using ee$Image$updateMask.
![A one-line command reads, n d s i masked less than symbol hyphen n d s i $ update mask left parenthesis n d s i $ g t e left parenthesis 0.4 right parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figu_HTML.png)
Define the visualization parameters.
![A seven-line algorithm works with the viz params less than hyphen list class and n d s i V i z less than hyphen list class. The attributes discussed under the first class are for the min value, max value, and gamma.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figv_HTML.png)
Center the map on the Huayhuash mountain range in Peru.
![A one-line command reads, map $ set center left parenthesis I o n = negative 77.20, l a t = negative 9.85, zoom = 10 right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figw_HTML.png)
Finally, visualize both maps using the | operator (Fig. 31.7).
![A three-line algorithm to visualize the maps using the modulus operator between m 2 and m 1 where m 2 deals with N D S I masked and m 1 deals with false color composite.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figx_HTML.png)
Code Checkpoint F64d. The book’s repository contains information about what your code should look like at this point.
2.4 Section 4. Integrating rgee with Other Python Packages
As noted in Sect. 31.2.1, rgee set up a Python environment with NumPy and earthengine-api in your system. However, there is no need to limit it to just two Python packages. In this section, you will learn how to use the Python package ndvi2gif to perform a Normalized Difference Vegetation Index (NDVI) multi-seasonal analysis in the Ocoña Valley without leaving R.
Whenever you want to install a Python package, you must run the following.
![A three-line command reads, library left parenthesis r g e e right parenthesis, library left parenthesis reticulate right parenthesis, e e underscore initialize left parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figy_HTML.png)
The ee_Initialize function not only authenticates your Earth Engine account but also helps reticulate to set up a Python environment compatible with rgee. After running ee_Initialize, use reticulate::install_python to install the desired Python package.
![A one-line command reads, p y underscore install left parenthesis double quotation starts n d v I 2 g i f double quotation ends right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figz_HTML.png)
The previous procedure is needed just once for each Python environment. Once installed, we simply load the package using reticulate::import.
![A one-line command reads, n g i f less than symbol hyphen import left parenthesis double quotation n d v i 2 g i f double quotation ends right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figaa_HTML.png)
Then, we define our study area using ee$Geometry$Rectangle (Fig. 31.8) and use the leaflet layers control to switch between basemaps.
![An algorithm of the following objects. E e $ geometry rectangle left parenthesis c o l c a right parenthesis, map $ center object left parenthesis r o i right parenthesis, and map $ add layer left parenthesis r o i right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figab_HTML.png)
In ndvi2gif, there is just one class: NdviSeasonality. It has the following four public methods.
-
get_export: Exports NDVI year composites in.GeoTIFF format to your local folder.
-
get_export_single: Exports single composite as.GeoTIFF to your local folder.
-
get_year_composite: Returns the NDVI composites for each year.
-
get_gif: Exports NDVI year composites as a.gif to your local folder.
To run, the NdviSeasonality constructor needs to define the following arguments.
-
roi: the region of interest
-
start_year: the initial year to start to create yearly composites
-
end_year: the end year to look for
-
sat: the satellite sensor
-
key: the aggregation rule that will be used to generate the yearly composite.
For each year, the get_year_composite method generates an NDVI ee$Image with four bands, one band per season. Color combination between images and bands will allow you to interpret the vegetation phenology over the seasons and years. In ndvi2gif, the seasons are defined as follows.
-
winter = c(‘-01-01’, ‘-03-31’)
-
spring = c(‘-04-01’, ‘-06-30’)
-
summer = c(‘-07-01’, ‘-09-30’)
-
autumn = c(‘-10-01’, ‘-12-31’).
![A 12-line my class algorithm executes the following tasks. Estimating the median of the yearly composites from 2016 to 2020 and the median of the winter season composites from 2016 to 2020.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figac_HTML.png)
We can display maps interactively using the Map$addLayer (Fig. 31.9) and use the leaflet layers control to switch between basemaps.
![A two-line code with the map $ add layer object deals with the winter max list of minimum and maximum values and the median list of minimum and maximum values.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figad_HTML.png)
And we can export the results to a GIF format.
![A one-line command reads, my class $ get underscore gift left parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figae_HTML.png)
To get more information about the ndvi2gif package, visit its GitHub repository.
Code Checkpoint F64e. The book’s repository contains information about what your code should look like at this point.
2.5 Section 5. Converting JavaScript Modules to R
In recent years, the Earth Engine community has developed a lot of valuable third-party modules. Some incredible ones are geeSharp, ee-palettes, spectral (Montero 2021), and LandsatLST (Ermida et al. 2020). While some of these modules have been implemented in Python and JavaScript (e.g., geeSharp and spectral), most are available only for JavaScript. This is a critical drawback, because it divides the Earth Engine community by programming languages. For example, if an R user wants to use tagee, the user will have to first translate the entire module to R.
In order to close this breach, the ee_extra Python package has been developed to unify the Earth Engine community. The philosophy behind ee_extra is that all of its extended functions, classes, and methods must be functional for the JavaScript, Julia, R, and Python client libraries. Currently, ee_extra is the base of the rgeeExtra (Aybar et al. 2020) and eemont (Montero 2021) packages.
To demonstrate the potential of ee_extra, let’s study an example from the Landsat Land Surface Temperature (LST) JavaScript module. The Landsat LST module computes the land surface temperature for Landsat products (Ermida et al. 2020). First, we will run it in the Earth Engine Code Editor; then, we will replicate those results in R.
First, JavaScript. In a new script in the Code Editor, we must require the Landsat LST module.
![A one-line v a r code with the land sat L S T module uses the require function. The code inside the function is single quote starts users slash Sofia e r m i d a slash land sat underscore s m w underscore l s t colon modules slash land sat underscore L S T dot j s single quote ends.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figaf_HTML.png)
The Landsat LST module contains a function named collection. This function receives the following parameters.
-
The Landsat archive ID
-
The starting date of the Landsat collection
-
The ending date of the Landsat collection
-
The region of interest as geometry
-
A Boolean parameter specifying if we want to use the NDVI for computing a dynamic emissivity instead of using the emissivity from ASTER.
In the following code block, we are going to define all required parameters.
![A five-line code block defines the following parameters. Geometry, satellite, data underscore start, data underscore end, and use underscore n d v i.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figag_HTML.png)
Now, with all our parameters defined, we can compute the land surface temperature by using the collection method from Landsat LST.
![A one-line algorithm to calculate the land surface temperature reads, v a r land sat coll = land sat L S T dot collection left parenthesis satellite, date underscore start, date underscore end, geometry, use underscore n d v i right parenthesis semicolon.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figah_HTML.png)
The result is stored as an ImageCollection in the LandsatColl variable. Now select the first element of the collection as an example by using the first method.
![A one-line code reads, v a r ex image = land sat coll dot first left parenthesis right parenthesis semicolon.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figai_HTML.png)
This example image is now stored in a variable named ‘exImage’. Let’s display the LST result on the Map. For visualization purposes, we will define a color palette.
![A 1-line code reads, v a r c map=left bracket single quote starts blue single quote ends, single quote starts cyan single quote ends, single quote starts green single quote ends, single quote starts yellow single quote ends, single quote starts red single quote ends right bracket semicolon.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figaj_HTML.png)
Then, we will center the map in the region of interest.
![A one-line code reads, map dot center object left parenthesis geometry right parenthesis semicolon.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figak_HTML.png)
Finally, let’s display the LST with the cmap color palette by using the Map.addLayer method (Fig. 31.10). This method receives the image to visualize, the visualization parameters, the color palette, and the name of the layer to show in the layer control. The visualization parameters will be
-
min: 290 (a minimum LST value of 290 K)
-
max: 320 (a maximum LST value of 320 K)
-
palette: cmap (the color palette that was created some steps before).
The name of the layer in the Map layer set will be LST.
![A four-line algorithm for the map dot add layer class deals with the attributes for ex image, min value, max value, and palette.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figal_HTML.png)
Code Checkpoint F64f. The book’s repository contains a script that shows what your code should look like at this point.
Now, let’s use R to implement the same logic. As in the previous sections, import the R packages: rgee and rgeeExtra. Then, initialize your Earth Engine session.
![A four-line code reads, library left parenthesis r g e e right parenthesis, library left parenthesis r g e e extra right parenthesis, library left parenthesis reticulate right parenthesis, e e underscore initialize left parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figam_HTML.png)
Install rgeeExtra Python dependencies.
![A one-line code reads p y underscore install left parenthesis packages = c left parenthesis double quote starts regex double quotes ends, double quote starts e e underscore extra double quotes, double quote starts j s beautifier double quotes ends right parenthesis right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figan_HTML.png)
Using the function rgeeExtra::module loads the JavaScript module.
![A one-line code written using the land sat L S T module function. The code inside the function reads, double quote starts users slash Sofia a e r m i d a slash land sat underscore s m w underscore l s t colon modules slash land sat underscore L S T dot j s double quote ends right parenthesis.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figao_HTML.png)
The rest of the code is exactly the same as in JavaScript (Fig. 31.11).
![An algorithm includes the attributes of the following parameters and the land sat collection function. Geometry, satellite, date underscore start, date underscore end, use underscore n d v i, ex image, c map, and I mod.](http://media.springernature.com/lw685/springer-static/image/chp%3A10.1007%2F978-3-031-26588-4_31/MediaObjects/508116_1_En_31_Figap_HTML.png)
Code Checkpoint F64g. The book’s repository contains information about what your code should look like at this point.
Question 1. When and why might users prefer to use R instead of Python to connect to Earth Engine?
Question 2. What are the advantages and disadvantages of using rgee instead of the Earth Engine JavaScript Code Editor?
3 Synthesis
Assignment 1. Estimate the Gaussian curvature map from a digital elevation model using rgee and rgeeExtra. Hint: Use the module 'users/joselucassafanelli/TAGEE:TAGEE-functions'.
4 Conclusion
In this chapter, you learned how to use Earth Engine and R in the same workflow. Since rgee uses reticulate, rgee also permits integration with third-party Earth Engine Python packages. You also learned how to use Map$addLayer, which works similarly to the Earth Engine User Interface API (Code Editor). Finally, we also introduced rgeeExtra, a new R package that extends the Earth Engine API and supports JavaScript module execution.
References
Aybar C, Wu Q, Bautista L, et al (2020) rgee: An R package for interacting with Google Earth Engine. J Open Source Softw 5:2272. https://doi.org/10.21105/joss.02272
Ermida SL, Soares P, Mantas V et al (2020) Google Earth Engine open-source code for land surface temperature estimation from the Landsat series. Remote Sens 12:1471. https://doi.org/10.3390/RS12091471
Grolemund G (2014) Hands-On Programming with R - Write Your Own Functions and Simulations. O’Reilly Media, Inc.
Lovelace R, Nowosad J, Muenchow J (2019) Geocomputation with R. Chapman and Hall/CRC
Montero D (2021) eemont: a Python package that extends Google Earth Engine. J Open Source Softw 6:3168. https://doi.org/10.21105/joss.03168
Pebesma E, Bivand R (2019) Spatial Data Science. https://r-spatial.org/book/
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Open Access This chapter is licensed under the terms of the Creative Commons Attribution 4.0 International License (http://creativecommons.org/licenses/by/4.0/), which permits use, sharing, adaptation, distribution and reproduction in any medium or format, as long as you give appropriate credit to the original author(s) and the source, provide a link to the Creative Commons license and indicate if changes were made.
The images or other third party material in this chapter are included in the chapter's Creative Commons license, unless indicated otherwise in a credit line to the material. If material is not included in the chapter's Creative Commons license and your intended use is not permitted by statutory regulation or exceeds the permitted use, you will need to obtain permission directly from the copyright holder.
Copyright information
© 2024 The Author(s)
About this chapter
Cite this chapter
Aybar, C., Montero, D., Barja, A., Herrera, F., Gonzales, A., Espinoza, W. (2024). Combining R and Earth Engine. In: Cardille, J.A., Crowley, M.A., Saah, D., Clinton, N.E. (eds) Cloud-Based Remote Sensing with Google Earth Engine. Springer, Cham. https://doi.org/10.1007/978-3-031-26588-4_31
Download citation
DOI: https://doi.org/10.1007/978-3-031-26588-4_31
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-031-26587-7
Online ISBN: 978-3-031-26588-4
eBook Packages: Chemistry and Materials ScienceChemistry and Material Science (R0)