R/create_transect.R

Defines functions create_transect

Documented in create_transect

# Generated by fusen: do not edit by hand


#' Create transect
#'
#' This function allows to create transects by reusing the `make.design` function of the `dssd` package. The `make.design` function allows to:     
#' * choose different types of survey design such as zigzag or parallel transects `design`      
#' * choose the desired transect length (approximately) `line.transect`      
#' * choose the angle of the transects `design angle`      
#' * choose the spacing between transects `spacing`      
#' * and others : see `?make.design`            
#' 
#' In contrast to `make.design`, the `create_transect` function returns an `sf` object (`data.frame`) containing information about the different transects created. 
#' @param region_obj Region object from dssd package. The map containing information about the geometry of the study area.
#' @param crs Numeric. Projection system. 
#' @param design Character. Variable describing the type of design. Either "random", "systematic", "eszigzag" (equal-spaced zigzag), "eszigzagcom" (equal spaced zigzag with complementary lines) or "segmentedgrid". See dssd package for more information.
#' @param design.angle Numeric. Value detailing the angle of the design. A value of -1 will cause a random design angle to be generated. See dssd package for more information.
#' @param line.length Numeric. The approximative total line length desired. 
#' @param truncation Numeric. A single numeric value (in m) describing the longest distance at which an object may be observed. 
#' @param ... All other arguments that could be used in the make.design function. See dssd package for more information.
#'
#' @importFrom dssd make.design generate.transects
#' @importFrom sf st_cast st_sf
#' @importFrom dplyr select
#' @importFrom assertthat assert_that
#'
#' @return sf object. The created transects.
#' @export

#' @examples
#' library(sf)
#' library(dssd)
#' library(dsims)
#' 
#' # Use of the St Andrews bay map from the dssd package
#' shapefile.name <- system.file("extdata", "StAndrew.shp", package = "dssd")
#' 
#' # Creation of the object with the make.region function of the dsims package
#' region <- make.region(region.name = "St Andrews bay",
#'                       shape = shapefile.name,
#'                       units = "m")
#' 
#' transects <- create_transect(region_obj = region,
#'                              crs = 2154,
#'                              design = "eszigzag",
#'                              line.length = 400000,
#'                              design.angle = 30,
#'                              truncation = 400)
#' 
#' head(transects)
#' 
#' transects %>%
#'   st_length() %>%
#'   sum()
#' 
create_transect <- function(region_obj, crs, design, design.angle, line.length, truncation, ...) {
  
  # Function checks
  
  
  assert_that(inherits(region_obj, "Region"))
  
  # Function
  
  zigzag.design <- make.design(region = region_obj,
                               design = design,
                               design.angle = design.angle,
                               line.length = line.length,
                               truncation = truncation,
                               ...)
  
  z.survey <- generate.transects(zigzag.design)
  
  x <- z.survey@samplers %>%
    as.data.frame() %>%
    select("transect","geometry") %>%
    st_sf(crs = crs) %>%
    st_cast("MULTILINESTRING")
  
  return(x)
}
maudqueroue/intercali documentation built on Oct. 8, 2022, 2:09 p.m.