Convert an EE table in a sf object
ee_as_sf(
x,
dsn,
overwrite = TRUE,
crs = NULL,
via = "getInfo",
maxFeatures = 5000,
container = "rgee_backup",
selectors = NULL,
quiet = FALSE
)
EE table (ee$FeatureCollection) to be converted into a sf object.
Character. Output filename; in case dsn
is missing
ee_as_sf
will create a temporary file.
Logical. Delete data source dsn
before attempting
to write?.
Integer or character. coordinate reference system
for the EE table. If is NULL, ee_as_sf
will take the CRS of
the first element.
Character. Method to fetch data about the object. Multiple options supported. See details.
Numeric. The maximum allowed number of features to
export (ignore if via
is not set as "getInfo"). The task will fail
if the exported region covers more features. Defaults to 5000.
Character. Name of the folder ('drive') or bucket ('gcs')
to be exported into (ignore if via
is not defined as "drive" or
"gcs").
The list of properties to include in the output, as a list of strings or a comma-separated string. By default, all properties are included.
logical. Suppress info message
An sf object.
ee_as_sf
supports the download of ee$FeatureCollection
,
ee$Feature
and ee$Geometry
by three different options:
"getInfo", "drive", and "gcs". When "getInfo" is set in the via
argument, ee_as_sf
will make an REST call to retrieve
all the known information about the object. The advantage of use
"getInfo" is a direct and faster download. However, there is a limitation of
5000 features by request which makes it not recommendable for large
collections. Instead of "getInfo", the options: "drive" and "gcs" are
suitable for large collections since they use an intermediate container,
which may be Google Drive and Google Cloud Storage respectively. For getting
more information about exporting data take a look at the
Google Earth
Engine Guide - Export data.
# NOT RUN {
library(rgee)
ee_reattach() # reattach ee as a reserved word
ee_Initialize(drive = TRUE, gcs = TRUE)
# Region of interest
roi <- ee$Geometry$Polygon(list(
c(-122.275, 37.891),
c(-122.275, 37.868),
c(-122.240, 37.868),
c(-122.240, 37.891)
))
# TIGER: US Census Blocks Dataset
blocks <- ee$FeatureCollection("TIGER/2010/Blocks")
subset <- blocks$filterBounds(roi)
sf_subset <- ee_as_sf(x = subset)
plot(sf_subset)
# Create Random points in Earth Engine
region <- ee$Geometry$Rectangle(-119.224, 34.669, -99.536, 50.064)
ee_help(ee$FeatureCollection$randomPoints)
ee_randomPoints <- ee$FeatureCollection$randomPoints(region, 100)
# Download via GetInfo
sf_randomPoints <- ee_as_sf(ee_randomPoints)
plot(sf_randomPoints)
# Download via drive
sf_randomPoints_drive <- ee_as_sf(
x = ee_randomPoints,
via = 'drive'
)
# Download via GCS
sf_randomPoints_gcs <- ee_as_sf(
x = subset,
via = 'gcs',
container = 'rgee_dev' #GCS bucket name
)
# }
Run the code above in your browser using DataLab