| sf_as_ee | R Documentation | 
Load an sf object to Earth Engine.
sf_as_ee(
  x,
  via = "getInfo",
  assetId = NULL,
  bucket = NULL,
  predefinedAcl = "bucketLevel",
  command_line_tool_path = NULL,
  overwrite = TRUE,
  monitoring = TRUE,
  proj = "EPSG:4326",
  evenOdd = TRUE,
  geodesic = NULL,
  quiet = FALSE,
  ...
)
x | 
 object of class sf, sfc or sfg.  | 
via | 
 Character. Upload method for sf objects. Three methods are implemented: 'getInfo', 'getInfo_to_asset' and 'gcs_to_asset'. See details.  | 
assetId | 
 Character. Destination asset ID for the uploaded file. Ignore
if   | 
bucket | 
 Character. Name of the bucket (GCS) to save intermediate files
(ignore if   | 
predefinedAcl | 
 Specify user access to object. Passed to
  | 
command_line_tool_path | 
 Character. Path to the Earth Engine command line
tool (CLT). If NULL, rgee assumes that CLT is set in the system PATH.
(ignore if   | 
overwrite | 
 A boolean argument that indicates indicating
whether "filename" should be overwritten. Ignore if   | 
monitoring | 
 Logical. Ignore if via is not set as
  | 
proj | 
 Integer or character. Coordinate Reference System (CRS) for the EE object, defaults to "EPSG:4326" (x=longitude, y=latitude).  | 
evenOdd | 
 Logical. Ignored if   | 
geodesic | 
 Logical. Ignored if   | 
quiet | 
 Logical. Suppress info message.  | 
... | 
 
  | 
sf_as_ee supports the upload of sf objects by three different
options: "getInfo" (default), "getInfo_to_asset", and "gcs_to_asset". getInfo
transforms sf objects (sfg, sfc, or sf) to GeoJSON (using geojsonio::geojson_json)
and then encrusted them in an HTTP request using the server-side objects that are
implemented in the Earth Engine API (i.e. ee$Geometry$...). If the sf object is too
large (~ >1Mb) is likely to cause bottlenecks since it is a temporary
file that is not saved in your EE Assets (server-side). The second option implemented
is 'getInfo_to_asset'. It is similar to the previous one, with the difference
that after create the server-side object will save it in your Earth Engine
Assets. For dealing with very large spatial objects is preferable to use the
third option 'gcs_to_asset'. This option firstly saves the sf object as a *.shp
file in the /temp directory. Secondly, using the function local_to_gcs
will move the shapefile from local to Google Cloud Storage. Finally, using
the function gcs_to_ee_table the ESRI shapefile will be loaded
to their EE Assets. See Importing
table data documentation for more details.
When via is "getInfo" and x is either an sf or sfc object
with multiple geometries will return an ee$FeatureCollection. For
single sfc and sfg objects will return an ee$Geometry$....
If via is either "getInfo_to_asset" or "gcs_to_asset" always will
return an ee$FeatureCollection.
## Not run: 
library(rgee)
library(sf)
ee_Initialize()
# 1. Handling geometry parameters
# Simple
ee_x <- st_read(system.file("shape/nc.shp", package = "sf")) %>%
  sf_as_ee()
Map$centerObject(eeObject = ee_x)
Map$addLayer(ee_x)
# Create a right-inside polygon.
toy_poly <- matrix(data = c(-35,-10,-35,10,35,10,35,-10,-35,-10),
                   ncol = 2,
                   byrow = TRUE) %>%
  list() %>%
  st_polygon()
holePoly <- sf_as_ee(x = toy_poly, evenOdd = FALSE)
# Create an even-odd version of the polygon.
evenOddPoly <- sf_as_ee(toy_poly, evenOdd = TRUE)
# Create a point to test the insideness of the polygon.
pt <- ee$Geometry$Point(c(1.5, 1.5))
# Check insideness with a contains operator.
print(holePoly$contains(pt)$getInfo() %>% ee_utils_py_to_r())
print(evenOddPoly$contains(pt)$getInfo() %>% ee_utils_py_to_r())
# 2. Upload small geometries to EE asset
assetId <- sprintf("%s/%s", ee_get_assethome(), 'toy_poly')
eex <- sf_as_ee(
 x = toy_poly,
 overwrite = TRUE,
 assetId = assetId,
 via = "getInfo_to_asset")
# 3. Upload large geometries to EE asset
ee_Initialize(gcs = TRUE)
assetId <- sprintf("%s/%s", ee_get_assethome(), 'toy_poly_gcs')
eex <- sf_as_ee(
  x = toy_poly,
  overwrite = TRUE,
  assetId = assetId,
  bucket = 'rgee_dev',
  monitoring = FALSE,
  via = 'gcs_to_asset'
)
ee_monitoring(max_attempts = Inf)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.