Skip to content

Commit

Permalink
Add items_select() (closes #146)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rolf Simoes committed Feb 14, 2024
1 parent defbdb2 commit deb978b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,3 @@ Collate:
'rstac.R'
'rstac-funs.R'
Roxygen: list(markdown = TRUE)
VignetteBuilder: knitr
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ S3method(items_properties,doc_items)
S3method(items_reap,default)
S3method(items_reap,doc_item)
S3method(items_reap,doc_items)
S3method(items_select,doc_items)
S3method(items_sign,default)
S3method(items_sign,doc_item)
S3method(items_sign,doc_items)
Expand Down Expand Up @@ -201,6 +202,7 @@ export(items_matched)
export(items_next)
export(items_properties)
export(items_reap)
export(items_select)
export(items_sign)
export(items_sign_bdc)
export(items_sign_planetary_computer)
Expand Down
30 changes: 30 additions & 0 deletions R/items-funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@
#'
#' @param geom a `sf` or `sfc` object.
#'
#' @param selection an `integer` vector containing the indices of the items
#' to select.
#'
#' @param ... additional arguments. See details.
#'
#' @details
Expand Down Expand Up @@ -153,6 +156,8 @@
#' \item `items_properties()`: returns a `character` value with all properties
#' of all items.
#'
#' \item `items_select()`: select features from an items object.
#'
#' }
#'
#' @examples
Expand Down Expand Up @@ -215,6 +220,8 @@
#'
#' stac_item %>% items_as_tibble()
#'
#' stac_item %>% items_select(c(1, 4, 10, 20))
#'
#' }
#'
#' @name items_functions
Expand Down Expand Up @@ -751,3 +758,26 @@ items_properties.doc_items <- function(items) {
names(item$properties)
}))))
}

#' @rdname items_functions
#'
#' @export
items_select <- function(items, selection) {
UseMethod("items_select", items)
}

#' @rdname items_functions
#'
#' @export
items_select.doc_items <- function(items, selection) {
check_items(items)
items$features <- items$features[selection]
# clear numberMatched information
if ("search:metadata" %in% names(items))
items$`search:metadata`$matched <- NULL
if ("context" %in% names(items))
items$`context`$matched <- NULL
if ("numberMatched" %in% names(items))
items$numberMatched <- NULL
items
}
13 changes: 13 additions & 0 deletions man/items_functions.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/rstac.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit deb978b

Please sign in to comment.