These functions provide support to work with
doc_items
and doc_item
objects.
items_length()
: shows how many items there are in thedoc_items
object.items_matched()
: shows how many items matched the search criteria. It supportssearch:metadata
(v0.8.0),context
(v0.9.0), andnumberMatched
(OGC WFS3 core spec).items_fetch()
: request all STAC Items through pagination.items_next()
: fetches a new page from STAC service.items_datetime()
: retrieves thedatetime
field inproperties
fromdoc_items
anddoc_item
objects.items_bbox()
: retrieves thebbox
field of adoc_items
or adoc_item
object.item_assets()
: returns the assets name fromdoc_items
anddoc_item
objects.items_filter()
: selects only items that match some criteria (see details section).items_reap()
: traverses all items in adoc_items
object and extracts values based on the specified field path. It is useful for retrieving nested elements from STAC items.items_fields()
: lists field names inside an item.items_sign()
: allow access assets by preparing its url.items_intersects()
: indicates which items intersects a given geometry.items_properties()
: lists properties names inside an item.
Usage
items_length(items)
# S3 method for class 'doc_items'
items_length(items)
items_matched(items, matched_field = NULL)
# S3 method for class 'doc_items'
items_matched(items, matched_field = NULL)
items_fetch(items, ...)
# S3 method for class 'doc_items'
items_fetch(items, ..., progress = TRUE, matched_field = NULL)
items_next(items, ...)
# S3 method for class 'doc_items'
items_next(items, ...)
items_datetime(items)
# S3 method for class 'doc_item'
items_datetime(items)
# S3 method for class 'doc_items'
items_datetime(items)
items_bbox(items)
# S3 method for class 'doc_item'
items_bbox(items)
# S3 method for class 'doc_items'
items_bbox(items)
items_assets(items)
# S3 method for class 'doc_item'
items_assets(items)
# S3 method for class 'doc_items'
items_assets(items)
# Default S3 method
items_assets(items)
items_filter(items, ..., filter_fn = NULL)
# S3 method for class 'doc_items'
items_filter(items, ..., filter_fn = NULL)
items_compact(items)
# S3 method for class 'doc_items'
items_compact(items)
items_reap(items, field, pick_fn = identity)
# S3 method for class 'doc_item'
items_reap(items, field, pick_fn = identity)
# S3 method for class 'doc_items'
items_reap(items, field, pick_fn = identity)
# Default S3 method
items_reap(items, field, pick_fn = identity)
items_fields(items, field = NULL)
# S3 method for class 'doc_item'
items_fields(items, field = NULL)
# S3 method for class 'doc_items'
items_fields(items, field = NULL)
items_sign(items, sign_fn)
# S3 method for class 'doc_item'
items_sign(items, sign_fn)
# S3 method for class 'doc_items'
items_sign(items, sign_fn)
# Default S3 method
items_sign(items, sign_fn)
items_as_sf(items, ..., crs = 4326)
# S3 method for class 'doc_item'
items_as_sf(items, ..., crs = 4326)
# S3 method for class 'doc_items'
items_as_sf(items, ..., crs = 4326)
items_as_sfc(items, crs = 4326)
# S3 method for class 'doc_item'
items_as_sfc(items, crs = 4326)
# S3 method for class 'doc_items'
items_as_sfc(items, crs = 4326)
items_as_tibble(items)
# S3 method for class 'doc_item'
items_as_tibble(items)
# S3 method for class 'doc_items'
items_as_tibble(items)
items_intersects(items, geom, ..., crs = 4326)
# S3 method for class 'doc_item'
items_intersects(items, geom, ..., crs = 4326)
# S3 method for class 'doc_items'
items_intersects(items, geom, ..., crs = 4326)
items_properties(items)
# S3 method for class 'doc_item'
items_properties(items)
# S3 method for class 'doc_items'
items_properties(items)
items_select(items, selection)
# S3 method for class 'doc_items'
items_select(items, selection)
Arguments
- items
a
doc_items
object.- matched_field
a
character
vector with the path where the number of items returned in the named list is located starting from the initial node of the list. For example, if the information is in a positionitems$meta$found
of the object, it must be passed as the following parameterc("meta", "found")
.- ...
additional arguments. See details.
- progress
a
logical
indicating if a progress bar must be shown or not. Defaults toTRUE
.- filter_fn
a
function
that receives an item that should evaluate alogical
value.- field
A
character
vector specifying the path to the field from which to extract subfield values. For example,c("assets", "*")
will traverse all assets from each item.- pick_fn
a
function
used to pick elements from items addressed byfield
parameter.- sign_fn
a
function
that receives an item as a parameter and returns an item signed.- crs
a
character
representing the geometry projection.- geom
a
sf
orsfc
object.- selection
an
integer
vector containing the indices of the items to select.
Value
items_length()
: aninteger
value.items_matched()
: returns aninteger
value if the STAC web server does support this extension. Otherwise returnsNULL
.items_fetch()
: adoc_items
with all matched items.items_next()
: fetches a new page from STAC service.items_datetime()
: alist
of all items' datetime.items_bbox()
: returns alist
with all items' bounding boxes.item_assets()
: returns acharacter
value with all assets names of all items.items_filter()
: adoc_items
object.items_reap()
: avector
if the supplied field is atomic, otherwise or alist
.items_fields()
: acharacter
vector.items_sign()
: adoc_items
object with signed assets url.items_as_sf()
: asf
object.items_as_sfc()
: asfc
object.items_as_tibble()
: atibble
object.items_intersects()
: alogical
vector.items_properties()
: returns acharacter
value with all properties of all items.items_select()
: select features from an items object.
Details
Ellipsis argument (...
) appears in different items functions and
has distinct purposes:
items_matched()
anditems_assets()
: ellipsis is not used.items_fetch()
anditems_next()
: ellipsis is used to pass additionalhttr
options to GET or POST methods, such as add_headers or set_cookies.items_filter()
: ellipsis is used to pass logical expressions to be evaluated against adoc_item
field as filter criteria. Expressions must be evaluated as a logical value whereTRUE
selects the item andFALSE
discards it. Multiple expressions are combine withAND
operator.items_filter()
uses non-standard evaluation to evaluate its expressions. That means users must escape any variable or call to be able to use them in the expressions. The escape is done by usingdouble-curly-braces
, i.e.,{{variable}}
.WARNING: the evaluation of filter expressions changed in
rstac
0.9.2. Older versions ofrstac
usedproperties
field to evaluate filter expressions. Below, there is an example of how to write expressions in newrstac
version:# expression in older version items_filter(stac_obj, `eo:cloud_cover` < 10) # now expressions must refer to properties explicitly items_filter(stac_obj, properties$`eo:cloud_cover` < 10) items_filter(stac_obj, properties[["eo:cloud_cover"]] < 10)
items_sign()
: in the near future, ellipsis will be used to append key-value pairs to the url query string of an asset.
items_sign()
has sign_fn
parameter that must be a function that
receives as argument an item and returns a signed item. rstac
provides
sign_bdc()
and sign_planetary_computer()
functions to access Brazil
Data Cube products and Microsoft Planetary Computer catalogs, respectively.
Examples
if (FALSE) { # \dontrun{
x <- stac("https://brazildatacube.dpi.inpe.br/stac") %>%
stac_search(collections = "CB4-16D-2") %>%
stac_search(datetime = "2020-01-01/2021-01-01", limit = 500) %>%
get_request()
x %>% items_length()
x %>% items_matched()
x %>% items_datetime()
x %>% items_bbox()
x %>% items_fetch()
} # }
if (FALSE) { # \dontrun{
# Defining BDC token
Sys.setenv("BDC_ACCESS_KEY" = "token-123")
# doc_item object
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "CB4-16D-2", limit = 100,
datetime = "2017-08-01/2018-03-01",
bbox = c(-48.206, -14.195, -45.067, -12.272)) %>%
get_request() %>% items_sign(sign_fn = sign_bdc())
} # }
if (FALSE) { # \dontrun{
# doc_items object
stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "CB4-16D-2", limit = 100,
datetime = "2017-08-01/2018-03-01",
bbox = c(-48.206, -14.195, -45.067, -12.272)) %>%
get_request() %>%
items_filter(properties$`eo:cloud_cover` < 10)
# Example with AWS STAC
stac("https://earth-search.aws.element84.com/v0") %>%
stac_search(collections = "sentinel-s2-l2a-cogs",
bbox = c(-48.206, -14.195, -45.067, -12.272),
datetime = "2018-06-01/2018-06-30",
limit = 500) %>%
post_request() %>%
items_filter(filter_fn = function(x) {x$properties$`eo:cloud_cover` < 10})
} # }
if (FALSE) { # \dontrun{
# doc_items object
stac_item <- stac("https://brazildatacube.dpi.inpe.br/stac/") %>%
stac_search(collections = "CB4-16D-2", limit = 100,
datetime = "2017-08-01/2018-03-01",
bbox = c(-48.206, -14.195, -45.067, -12.272)) %>%
get_request() %>%
items_fetch(progress = FALSE)
stac_item %>% items_reap(c("properties", "datetime"))
# Extract all asset URLs from each item
stac_item %>% items_reap(c("assets", "*"), \(x) x$href)
stac_item %>% items_as_sf()
stac_item %>% items_as_tibble()
stac_item %>% items_select(c(1, 4, 10, 20))
} # }