Description Usage Arguments Details Value Examples
Convert an sf object to an EE object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
x |
sf object to be converted into a EE object. |
via |
Method to download the image. 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 |
overwrite |
A boolean argument which indicates indicating whether "filename" should be overwritten. By default TRUE. |
monitoring |
Logical. Ignore if via is not set as
|
check_ring_dir |
Logical. See st_read for details. |
evenOdd |
Logical. Ignored if |
proj |
Integer or character. coordinate reference system for the EE object, defaults to "EPSG:4326" (x=longitude, y=latitude). |
geodesic |
Logical. Ignored if |
quiet |
Logical. Suppress info message. |
... |
st_read arguments might be included. |
sf_as_ee
supports the upload of sf
objects by three different
options: "getInfo", "getInfo_to_asset", and "gcs_to_asset".
When "getInfo" is set in the via
argument the sf object is
transformed to GeoJSON using geojson_json and then
encrusted in an HTTP request using the server-side objects that are
implemented in the Earth Engine API (ee$Geometry). If the sf object is too
large (~ >1Mb) it is likely to cause bottlenecks since it is a temporary
file that is not saved in your Earth Engine Asset. See
Client
vs Server documentation for more details. The second method implemented is
'getInfo_to_asset'. It is similar to the previous one, with the difference
that the result will be saved in your Earth Engine Asset. For dealing
with very large spatial objects, it is preferable to use the third option
'gcs_to_asset'. This option firstly save 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 the Earth Engine Asset.
See Importing
table data documentation for more details.
Earth Engine is strict on polygon ring directions (outer ring
counter-clockwise, and the inner one clockwise). If check_ring_dir
is TRUE,
it check every ring, and revert them if necessary, to counter clockwise for
outer, and clockwise for inner (hole) ones. By default this is FALSE because
it is an expensive operation.
A ee$FeatureCollection object
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 | ## Not run:
library(rgee)
library(sf)
ee_reattach() # reattach ee as a reserved word
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$geometry()$contains(pt)$getInfo() %>% ee_py_to_r()) # FALSE
print(evenOddPoly$geometry()$contains(pt)$getInfo() %>% ee_py_to_r())# TRUE
# 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'
)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.