R/old/class-vector.extract.R

Defines functions new_vector.extract is.vector.extract

#' @name class-vector.extract
#' @aliases vector.extract
#'
#' @title Class "vector.extract" for vector data extraction
#'
#' @description A S3 class inheriting from class
#' \code{\link[glr:class-extract]{extract}} to store outputs stemming from
#' vectorial data (polygons, lines and points) extractions and manipulations.
#'
#' @usage
#' ## The constructor function
#' new_vector.extract(meta, output, type)
#'
#' @param meta An object of class \code{\link[glr:class-meta]{meta}}.
#'
#' @param output An array or a \code{\link{vector}}. Typically, a
#' \code{\link[data.table]{data.table}}, a \code{\link{data.frame}},
#' a \code{\link{list}} or a \code{\link{matrix}}. If a \code{\link{vector}},
#' classes \code{\link{complex}} and \code{\link{raw}} are not supported.
#'
#' @param type A character. Value must be in
#' \code{c("polygons", "lines", "points")}.
#'
#' @param x Any \R object.
#'
#' @details Class \code{\link[glr:class-vector.extract]{vector.extract}} is a
#' class \emph{inheriting} from class
#' \code{\link[glr:class-extract]{extract}}. For more information on S3
#' inheritance mechanism, see \code{\link[base:class]{class}}. Usually, this
#' class is used to structure the output of any function performing
#' operations on vectorial shapes (polygons, lines or points). It is a wrapper
#' to \code{\link{new_extract}}.
#'
#' @return Function \code{\link{new_vector.extract}} is a constructor function:
#' it returns an object of class
#' \code{\link[glr:class-vector.extract]{vector.extract}} from its arguments.
#' Function \code{\link{is.vector.extract}} checks if \code{x} is of class
#' \code{\link[glr:class-vector.extract]{vector.extract}} and returns a logical.
#' For the associated methods, the usual outputs should be expected.
#'
#' @section Components (slots):
#'
#' \describe{
#' \item{\code{meta}:}{
#' Information on the layers that were used for the extraction. See
#' \code{\link[glr:class-meta]{meta}}.
#' }
#' \item{\code{output}:}{
#' The extracted values from the layers.
#' }
#' \item{\code{type}:}{
#' The type of the underlying shapes.
#' }
#' }
#'
#' @section S3 methods for objects of class \code{vector.extract}:
#' None implemented. Methods for class \code{\link[glr:class-extract]{extract}}
#' are used through the inheritance mechanism.
#'
#' An object of class \code{\link[glr:class-vector.extract]{vector.extract}} is
#' stored as a list. Therefore, usual methods for lists such as
#' \code{\link[base:Extract]{[}}, \code{\link[base:Extract]{[[}},
#' \code{\link[base:Extract]{$}}, etc. will all work.
#'
#' @family extract classes
#' @family glr classes
#'
#' @export
new_vector.extract <- function(meta, output, type)
{
  ok <- match(type, c("polygons", "lines", "points"))

  if (is.na(ok)) {
    stop("type must be a character in 'polygons', 'lines' or 'points'.",
         call. = FALSE)
  }

  new_extract(meta, output, type = type,
              .subclass  = "vector.extract")
}

#' @rdname class-vector.extract
#' @export
is.vector.extract <- function(x)
{
  inherits(x, "vector.extract")
}
jeanmathieupotvin/scr documentation built on Dec. 3, 2019, 8:53 p.m.