From deb978bb99a4df41e5eb9f4e15669d8cb2d1e970 Mon Sep 17 00:00:00 2001 From: Rolf Simoes Date: Wed, 14 Feb 2024 13:54:15 +0100 Subject: [PATCH] Add items_select() (closes #146) --- DESCRIPTION | 1 - NAMESPACE | 2 ++ R/items-funs.R | 30 ++++++++++++++++++++++++++++++ man/items_functions.Rd | 13 +++++++++++++ man/rstac.Rd | 4 ++-- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index ae667379..494df321 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -80,4 +80,3 @@ Collate: 'rstac.R' 'rstac-funs.R' Roxygen: list(markdown = TRUE) -VignetteBuilder: knitr diff --git a/NAMESPACE b/NAMESPACE index 540c0421..5400e132 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) @@ -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) diff --git a/R/items-funs.R b/R/items-funs.R index bff8353e..399392a9 100644 --- a/R/items-funs.R +++ b/R/items-funs.R @@ -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 @@ -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 @@ -215,6 +220,8 @@ #' #' stac_item %>% items_as_tibble() #' +#' stac_item %>% items_select(c(1, 4, 10, 20)) +#' #' } #' #' @name items_functions @@ -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 +} diff --git a/man/items_functions.Rd b/man/items_functions.Rd index d3b64bb9..dd25fdce 100644 --- a/man/items_functions.Rd +++ b/man/items_functions.Rd @@ -50,6 +50,8 @@ \alias{items_properties} \alias{items_properties.doc_item} \alias{items_properties.doc_items} +\alias{items_select} +\alias{items_select.doc_items} \title{Items functions} \usage{ items_length(items) @@ -147,6 +149,10 @@ items_properties(items) \method{items_properties}{doc_item}(items) \method{items_properties}{doc_items}(items) + +items_select(items, selection) + +\method{items_select}{doc_items}(items, selection) } \arguments{ \item{items}{a \code{doc_items} object.} @@ -177,6 +183,9 @@ and returns an item signed.} \item{crs}{a \code{character} representing the geometry projection.} \item{geom}{a \code{sf} or \code{sfc} object.} + +\item{selection}{an \code{integer} vector containing the indices of the items +to select.} } \value{ \itemize{ @@ -216,6 +225,8 @@ otherwise or a \code{list}. \item \code{items_properties()}: returns a \code{character} value with all properties of all items. +\item \code{items_select()}: select features from an items object. + } } \description{ @@ -363,6 +374,8 @@ stac_item \%>\% items_as_sf() stac_item \%>\% items_as_tibble() +stac_item \%>\% items_select(c(1, 4, 10, 20)) + } } diff --git a/man/rstac.Rd b/man/rstac.Rd index 292a75e7..71076468 100644 --- a/man/rstac.Rd +++ b/man/rstac.Rd @@ -76,11 +76,11 @@ Useful links: } \author{ -\strong{Maintainer}: Rolf Simoes \email{rolfsimoes@gmail.com} +\strong{Maintainer}: Felipe Carvalho \email{lipecaso@gmail.com} Authors: \itemize{ - \item Felipe Carvalho \email{lipecaso@gmail.com} + \item Rolf Simoes \email{rolfsimoes@gmail.com} \item Brazil Data Cube Team \email{brazildatacube@inpe.br} }