10 21105 Joss 02272
10 21105 Joss 02272
10 21105 Joss 02272
net/publication/342986910
CITATIONS READS
0 518
5 authors, including:
Qiusheng Wu
University of Tennessee
57 PUBLICATIONS 794 CITATIONS
SEE PROFILE
Some of the authors of this publication are also working on these related projects:
Special Issue in the journal Remote Sensing "Remote Sensing for 3D Urban Morphology" View project
All content following this page was uploaded by Qiusheng Wu on 16 July 2020.
Features
Enhanced I/O
rgee implements several functions to support download/upload of spatial objects (Table 1 and
Table 2). For instance, to download vector (image) files one can use ee_as_sf (ee_as_ras
ter or ee_as_stars). In rgee, all the functions from server to local side have the option to
fetch data using an intermediate container (Google Drive or Google Cloud Storage) or through
a REST call (“$getInfo”). Although the latter option performs a quick download, there is a
request limit of 262144 pixels for ee$Image and 5000 elements for ee$FeatureCollection
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 1
//doi.org/10.21105/joss.02272
which makes it unsuitable for large objects. Other download functions, from server-side to
others (see Table 1), are implemented to enable more customized download workflows. For
example, using ee_image_to_drive and ee_drive_to_local users could create scripts
which save results in the .TFRecord rather than the .GeoTIFF format. The upload process
follows the same logic (Table 2). rgee includes raster_as_ee and stars_as_ee for uploading
images and sf_as_ee for uploading vector data. Large uploads are only possible with an active
Google Cloud Storage account.
FROM TO RETURN
Image ee_image_to_drive EE server Drive Unstarted task
ee_image_to_gcs EE server Cloud Storage Unstarted task
ee_image_to_asset EE server EE asset Unstarted task
ee_as_raster EE server Local RasterStack object
ee_as_stars EE server Local Proxy-stars object
Table ee_table_to_drive EE server Drive Unstarted task
ee_table_to_gcs EE server Cloud Storage Unstarted task
ee_table_to_asset EE server EE asset Unstarted task
ee_as_sf EE server Local sf object
Generic ee_drive_to_local Drive Local object filename
ee_gcs_to_local Cloud Storage Local GCS filename
FROM TO RETURN
Image gcs_to_ee_image Cloud Storage EE asset EE Asset ID
raster_as_ee Local EE asset EE Asset ID
stars_as_ee Local EE asset EE Asset ID
Table gcs_to_ee_table Cloud Storage EE asset EE Asset ID
sf_as_ee Local EE asset EE Asset ID
Generic local_to_gcs Local Cloud Storage GCS filename
The following example illustrates how to integrate the rgee I/O module and ggplot2 (Wickham,
2011) to download and visualize metadata for the BLM AIM TerrestrialAIM dataset.
library(tidyverse)
library(rgee)
library(sf)
ee_Initialize()
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 2
//doi.org/10.21105/joss.02272
# Create a boxplot with ggplot2
gapPct <- c("_25_50" = "GapPct_25_50","_51_100"="GapPct_51_100",
"101_200" = "GapPct_101_200","200_>" = "GapPct_200_plus")
sf_subset[gapPct] %>%
st_set_geometry(NULL) %>%
as_tibble() %>%
rename(!!gapPct) %>%
pivot_longer(seq_along(gapPct), names_to = "Range") %>%
ggplot(aes(x = Range, y = value, fill = Range)) +
geom_boxplot() +
xlab("") + ylab("% of the plot's soil surface") +
theme_minimal()
Figure 1: Gaps percentage between plant canopies of different sizes in a place near to Carson City,
Nevada, USA.
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:
library(rgee)
ee_Initialize()
# Load an ee$Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 3
//doi.org/10.21105/joss.02272
eeObject = image,
visParams = list(bands = c("B4", "B3", "B2"), max = 10000),
name = "SF"
)
Figure 2: Landsat 8 false color composite of San Francisco bay area, California, USA.
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.
library(ggplot2)
library(tidyr)
library(dplyr)
library(rgee)
library(sf)
ee_Initialize()
# Define a geometry
nc <- st_read(system.file("shape/nc.shp", package = "sf"))
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 4
//doi.org/10.21105/joss.02272
colnames(ee_nc_rain) <- sprintf("%02d", 1:12)
ee_nc_rain$name <- nc$NAME
Figure 3: Average areal rainfall in counties of North Carolina for the year 2001 according to the
TerraClimate dataset.
library(rgee)
ee_Initialize()
ee_manage_copy(
path_asset = paste0(server_path,"/LC08_044034_20140318"),
final_path = paste0(user_asset_path,"/LC08_044034_20140318")
)
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,
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 5
//doi.org/10.21105/joss.02272
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)
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(“r-
spatial/rgee”). A series of examples for using rgee are available at https://r-spatial.github.
io/rgee.
Acknowledgments
The authors would like to thank Justin Braaten for his reviewing and helpful comments during
the preparation of this manuscript and development of rgee.
References
Appelhans, T., Detsch, F., Reudenbach, C., & Woellauer, S. (2020). mapview: Interactive
viewing of spatial data in r. Retrieved from https://github.com/r-spatial/mapview
Gorelick, N., Hancher, M., Dixon, M., Ilyushchenko, S., Thau, D., & Moore, R. (2017).
Google earth engine: Planetary-scale geospatial analysis for everyone. Remote sensing of
Environment, 202, 18–27. doi:10.1016/j.rse.2017.06.031
Ushey, K., Allaire, J., & Tang, Y. (2020). reticulate: Interface to ’python’. Retrieved from
https://CRAN.R-project.org/package=reticulate
Wickham, H. (2011). ggplot2. Wiley Interdisciplinary Reviews: Computational Statistics,
3(2), 180–185. doi:10.1002/wics.147
Aybar et al., (2020). rgee: An R package for interacting with Google Earth Engine. Journal of Open Source Software, 5(51), 2272. https: 6
//doi.org/10.21105/joss.02272