R/read.seg.transects.R

Defines functions process.seg.transects read.seg.transects

read.seg.transects <- function(filename, design, warnings = list(), rep = NA){
  # Read in shapefile
  # Identify type of shapefile (point/linestring/multilinestring)
  # Check shapefile type matches with specified design

  # Information extracted from design (general to all)
  # - design
  # - strata.area
  # - effort.allocation
  # - spacing
  # - design.angle
  # - edge.protocol
  # Information extracted from design (segment)
  # - seg.length
  # - seg.threshold

  # Information obtained from shapefile (general to all)
  # - samplers
  # - cov.area
  # - cov.area.polys
  # - samp.count
  # Information obtained from shapefile (line / segment )
  # - line.length

  # Information that cannot be obtained
  # - trackline
  # - cyclictrackline

  all.transects <- sf::read_sf(filename)

  # Get geometry
  sf.column <- attr(all.transects, "sf_column")
  sf.geom <- all.transects[[sf.column]]

  # Check that it is of type point
  if(!is(sf.geom, "sfc_MULTILINESTRING") && !is(sf.geom, "sfc_LINESTRING")){
    warnings <- message.handler(warnings, paste("The following file cannot be used, shapefile not of type line / multi-line: ", filename, sep = ""), rep)
    return(list(transects = NULL, warnings = warnings))
  }

  # Process the shape and create a Point.Transect object
  transects <- process.seg.transects(transects = all.transects,
                                     design = design,
                                     warnings = warnings,
                                     rep = rep)
  return(transects)
}

process.seg.transects <- function(transects, design, warnings = list(), rep = NA){
  # Split into sub function for testing purposes

  # Process the shapefile in case it came from Distance for Windows
  transects <- process.dist.shapes(transects, design@region)

  # Find covered areas
  cov.areas <- get.covered.area.lines(transects,
                                      design@truncation,
                                      design@region)

  # Extract information
  sampler.count <- cov.areas$sampler.count
  areas <- cov.areas$area
  line.length <- cov.areas$line.length
  cov.area.polys <- cov.areas$polys

  #Make a survey object
  transect <- new(Class="Segment.Transect",
                  design = design@design,
                  lines = transects,
                  samp.count = sampler.count,
                  line.length = line.length,
                  seg.length = design@seg.length,
                  effort.allocation = design@effort.allocation,
                  spacing = design@spacing,
                  design.angle = design@design.angle,
                  edge.protocol = design@edge.protocol,
                  cov.area = areas,
                  cov.area.polys = cov.area.polys ,
                  strata.area = design@region@area,
                  strata.names = design@region@strata.name,
                  trackline = numeric(0),
                  cyclictrackline = numeric(0),
                  seg.threshold = design@seg.threshold)

  return(list(transects = transect, warnings = warnings))
}

Try the dsims package in your browser

Any scripts or data that you put into this service are public.

dsims documentation built on Aug. 30, 2022, 5:06 p.m.