Learn R Programming

rgee (version 0.2.0)

ee_map: Adds a given Earth Engine (EE) spatial object to mapview as a layer.

Description

Create interactive visualizations of spatial EE objects (Geometry, Image, Feature, FeatureCollection or ImageCollection) through mapview.

Usage

ee_map(eeobject, ...)

# S3 method for default ee_map(eeobject, ...)

# S3 method for ee.geometry.Geometry ee_map(eeobject, vizparams, center, zoom_start = 8, objname = "map", quiet = FALSE, ...)

# S3 method for ee.feature.Feature ee_map(eeobject, vizparams, center, zoom_start = 8, objname = "map", quiet = FALSE, ...)

# S3 method for ee.featurecollection.FeatureCollection ee_map(eeobject, vizparams, center, zoom_start = 8, objname = "map", quiet = FALSE, ...)

# S3 method for ee.image.Image ee_map(eeobject, vizparams, center, zoom_start = 8, objname = "map", quiet = FALSE, ...)

# S3 method for ee.imagecollection.ImageCollection ee_map(eeobject, vizparams, center, zoom_start = 8, objname = "map", max_nimage = 10, quiet = FALSE, ...)

Arguments

eeobject

An EE spatial object.

...

Ignored.

vizparams

List of parameters for visualization. See details.

center

The longitude and latitude of the map center. If it is not defined, ee_map will try to determine the centroid of the spatial EE object.

zoom_start

zoom level.

objname

character vector. Name of the map, or maps in case that the EE object be an ImageCollection.

quiet

logical; suppress info messages.

max_nimage

Max number of Image to display.

Details

ee_map takes advantage of the ee$Image()$getMapId python function for fetch and return a mapid and token that is suitable for use in a mapview. To achieve desirable visualization effects, it will depend on the type of spatial EE object . For either Image or ImageCollection, you can provide visualization parameters to ee_map by using vizparams. 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 Image or ImageCollection to the map without any additional parameters, by default ee_map assigns the first three bands to red, green and blue bands, respectively. The default stretch is based on the min-max range. For Geometry, Feature or FeatureCollection. The available vizparams are:

  • color: A hex string in the format RRGGBB specifying the color to use for drawing the features. By default 000000.

  • pointRadius: The radius of the point markers. By default 3.

  • strokeWidth: The width of lines and polygon borders. By default 3.

Examples

Run this code
# NOT RUN {
library(rgee)
ee_reattach() # reattach ee as a reserved word
ee_Initialize()

# Case: Geometry*
geom <- ee$Geometry$Point(list(-73.53522, -15.75453))
m1 <- ee_map(
  eeobject = geom,
  vizparams = list(pointRadius = 10, color = "FF0000"),
  objname = "Geometry-Arequipa"
)
m1

# Case: Feature
eeobject_fc <- ee$FeatureCollection("users/csaybar/DLdemos/train_set")$
  first()
m2 <- ee_map(eeobject = ee$Feature(eeobject_fc),
             objname = "Feature-Arequipa")
m2 + m1

# Case: FeatureCollection
eeobject_fc <- ee$FeatureCollection("users/csaybar/DLdemos/train_set")
m3 <- ee_map(eeobject = eeobject_fc, objname = "FeatureCollection")
m3 + m2 + m1

# Case: Image
image <- ee$Image("LANDSAT/LC08/C01/T1/LC08_044034_20140318")
m4 <- ee_map(
  eeobject = image,
  vizparams = list(
    bands = c("B4", "B3", "B2"),
    max = 10000
  ),
  objname = "SF",
  zoom_start = "8"
)
m4

# Case: ImageCollection
collection <- ee$ImageCollection("LANDSAT/LC08/C01/T1_TOA")$
  filter(ee$Filter()$eq("WRS_PATH", 44))$
  filter(ee$Filter()$eq("WRS_ROW", 34))$
  filterDate("2014-01-01", "2015-01-01")$
  sort("CLOUD_COVER")

m5 <- ee_map(
  eeobject = collection,
  vizparams = list(bands = c("B4", "B3", "B2"), max = 1),
  objname = c("Scene_2019", "Scene_2016", "Scene_2011"),
  max_nimage = 3,
  zoom_start = 10
)
m5
# }

Run the code above in your browser using DataLab