Map: R6 object (Map) to display Earth Engine (EE) spatial objects

Description Usage Format Details Value Examples

Description

Create interactive visualizations of spatial EE objects (ee$FeatureCollection, ee$ImageCollection, ee$Geometry, ee$Feature, and ee$Image.) using leaflet in the backend.

Usage

1

Format

An object of class environment with the following functions:

Details

Map use the Earth Engine method getMapId to fetch and return an ID dictionary being used to create layers in a leaflet object. Users can specify visualization parameters to Map$addLayer by using the visParams argument. Each Earth Engine spatial object has a specific format. For ee$Image, the parameters available are:

Parameter Description Type
bands Comma-delimited list of three band names to be mapped to RGB list
min Value(s) to map to 0 number or list of three numbers, one for each band
max Value(s) to map to 1 number or list of three numbers, one for each band
gain Value(s) by which to multiply each pixel value number or list of three numbers, one for each band
bias Value(s) to add to each Digital Number (DN) value number or list of three numbers, one for each band
gamma Gamma correction factor(s) number or list of three numbers, one for each band
palette List of CSS-style color strings (single-band images only) comma-separated list of hex strings
opacity The opacity of the layer (0.0 is fully transparent and 1.0 is fully opaque) number

If you add an ee$Image to Map$addLayer without any additional parameters, by default it assigns the first three bands to red, green, and blue bands, respectively. The default stretch is based on the min-max range. On the other hand, the available parameters for ee$Geometry, ee$Feature, and ee$FeatureCollection are:

Value

Object of class leaflet, with the following extra parameters: tokens, name, opacity, shown, min, max, palette, and legend. Use the $ method to retrieve the data (e.g. m$rgee$min).

Examples

 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
library(rgee)
library(sf)
ee_Initialize()

# Case 1: Geometry*
geom1 <- ee$Geometry$Point(list(-73.53, -15.75))
Map$centerObject(geom1, zoom = 8)
m1 <- Map$addLayer(
  eeObject = geom1,
  visParams = list(
    pointRadius = 10,
    color = "FF0000"
  ),
  name = "Geometry-Arequipa"
)

# Case 2: Feature
feature_arq <- ee$Feature(ee$Geometry$Point(list(-72.53, -15.75)))
m2 <- Map$addLayer(
  eeObject = feature_arq,
  name = "Feature-Arequipa"
)
m2 + m1

# Case 4: Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Map$centerObject(image)
m4 <- Map$addLayer(
  eeObject = image,
  visParams = list(
    bands = c("B4", "B3", "B2"),
    max = 10000
  ),
  name = "SF"
)

# Case 5: ImageCollection
nc <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
  st_transform(4326) %>%
  sf_as_ee()

ee_s2 <- ee$ImageCollection("COPERNICUS/S2")$
  filterDate("2016-01-01", "2016-01-31")$
  filterBounds(nc) %>%
  ee_get(0:4)
Map$centerObject(nc$geometry())
m5 <- Map$addLayers(ee_s2, legend = TRUE)
m5

# Case 6: Map comparison
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
Map$centerObject(image)
m_ndvi <- Map$addLayer(
  eeObject = image$normalizedDifference(list("B5", "B4")),
  visParams = list(max = 0.7),
  name = "SF_NDVI",
  legend = TRUE
)
m6 <- m4 | m_ndvi
m6

# Case 7: digging up the metadata
m6$rgee$tokens
m5$rgee$tokens

csaybar/rgee documentation built on March 11, 2021, 5:48 a.m.