Creates a suitable input for the region argument to gd_download(<Image>) or gd_search() for Image Collections.
gd_region_to_vect() is the inverse function of gd_region/gd_bbox; convert GeoJSON-like list to Well-Known Text(WKT)/SpatVector. This may be useful, for example. when gd_region()-output was derived from an Earth Engine asset rather than local R object.
gd_region(x)
gd_region_to_vect(x, crs = "OGC:CRS84", as_wkt = FALSE, ...)list. A GeoJSON-like list object (e.g. from gd_region()).
character. Default for GeoJSON sources is "OGC:CRS84".
logical. Return Well-Known Text (WKT) string as character? Default: FALSE returns a 'terra' SpatVector.
Additional arguments to gd_region_to_vect() are passed to terra::vect() when as_wkt=FALSE (default).
list representing a GeoJSON extent
gd_region_to_vect(): a 'terra' SpatVector object, or character containing Well-Known Text.
If x is an R spatial object, each vertex (possibly after converting object extent to vector) is used to create the GeoJSON object. Otherwise, the extent is determined and passed to gd_bbox().
gd_region_to_vect() uses Python's json module (via reticulate) to parse the GeoJSON list and terra to create the spatial vector object. It supports all geometry types handled by terra::vect (e.g., Polygon, MultiPolygon).
# \donttest{
library(terra)
b <- terra::vect('POLYGON((-121.355 37.560,
-121.355 37.555,
-121.350 37.555,
-121.350 37.560,
-121.355 37.560))',
crs = "OGC:CRS84")
gd_region(b)
#> $type
#> [1] "Polygon"
#>
#> $coordinates
#> $coordinates[[1]]
#> $coordinates[[1]][[1]]
#> [1] -121.355 37.560
#>
#> $coordinates[[1]][[2]]
#> [1] -121.355 37.555
#>
#> $coordinates[[1]][[3]]
#> [1] -121.350 37.555
#>
#> $coordinates[[1]][[4]]
#> [1] -121.35 37.56
#>
#> $coordinates[[1]][[5]]
#> [1] -121.355 37.560
#>
#>
#>
# }