Convert an sf object to EE object

sf_as_ee(x, check_ring_dir)

# S3 method for character
sf_as_ee(x, check_ring_dir = FALSE, ...)

# S3 method for sf
sf_as_ee(x, check_ring_dir = FALSE)

# S3 method for sfc
sf_as_ee(x, check_ring_dir = FALSE)

# S3 method for sfg
sf_as_ee(x, check_ring_dir = FALSE)

Arguments

x

sf object to be converted into a EE object.

check_ring_dir

logical. See st_read and details.

...

st_read arguments might be included.

Details

The conversion from sf to EE is a two-step process. Firstly, sf_as_ee transform sf objects into a GeoJSON format using geojson_json. Secondly, the GeoJSON generated will be encrusted in an HTTP request using the server-side objects (ee$Geometry$*). If the sf object is large spatial objects (>1Mb) it is expected that cause bottlenecks and plodding connections. See Client vs Server documentation for details. For leading with very large spatial objects, is recommended firstly importing it to the GEE assets. See ee_upload for creating uploading pipelines.

Earth Engine is strict with polygon ring directions (exterior ring counter-clockwise, holes clockwise). When check_ring_dir is TRUE, it check every ring and revert them to counter clockwise for outer, and clockwise for inner (hole) rings. By default this is FALSE because it is an expensive operation.

Examples

library(rgee) library(sf) ee_Initialize() # sf x <- st_read(system.file("shape/nc.shp", package = "sf")) %>% st_transform(4326)
#> Reading layer `nc' from data source `/home/aybarpc01/R/x86_64-pc-linux-gnu-library/3.6/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> epsg (SRID): 4267 #> proj4string: +proj=longlat +datum=NAD27 +no_defs
ee_x <- sf_as_ee(x, check_ring_dir = TRUE) ee_map(ee_x)
#> vizparams is missing, the following params are assigned. #> vizparams: {color:'000000', strokeWidth:3, pointRadius:3} #> center is missing, the centroid of this EE FeatureCollection is used: #> center: -79.4004113801615 35.5595134054197
# sfc x <- st_read(system.file("shape/nc.shp", package = "sf"))$geometry %>% st_transform(4326)
#> Reading layer `nc' from data source `/home/aybarpc01/R/x86_64-pc-linux-gnu-library/3.6/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> epsg (SRID): 4267 #> proj4string: +proj=longlat +datum=NAD27 +no_defs
ee_x <- sf_as_ee(x, check_ring_dir = TRUE) ee_map(ee_x)
#> vizparams is missing, the following params are assigned. #> vizparams: {color:'000000', strokeWidth:3, pointRadius:3} #> center is missing, the centroid of this EE Geometry is used: #> center: -79.4004113801615 35.5595134054197
# sfg x <- st_read(system.file("shape/nc.shp", package = "sf"))$geometry[[1]]
#> Reading layer `nc' from data source `/home/aybarpc01/R/x86_64-pc-linux-gnu-library/3.6/sf/shape/nc.shp' using driver `ESRI Shapefile' #> Simple feature collection with 100 features and 14 fields #> geometry type: MULTIPOLYGON #> dimension: XY #> bbox: xmin: -84.32385 ymin: 33.88199 xmax: -75.45698 ymax: 36.58965 #> epsg (SRID): 4267 #> proj4string: +proj=longlat +datum=NAD27 +no_defs
ee_x <- sf_as_ee(x, check_ring_dir = TRUE) ee_map(ee_x)
#> vizparams is missing, the following params are assigned. #> vizparams: {color:'000000', strokeWidth:3, pointRadius:3} #> center is missing, the centroid of this EE Geometry is used: #> center: -81.4982290170462 36.4313955999418