R/get_sim_points.R

Defines functions get_sim_points

Documented in get_sim_points

#' SpatialPoints from a list of Simulated Tracks
#'
#' @param sim_tracks simulated tracks returned from get_sim_tracks()
#' @param locType which locTypes to filter
#' @param crs a valid CRS object that will be associated with returned SPDF
#'
#' @return a SpatialPointsDataFrame containing all points from sim_tracks
#' @export
#'
get_sim_points <- function(sim_tracks, locType = c('p','o'), crs) {

  sim_tracks <- lapply(sim_tracks,
                      function(x) {
                        if (inherits(x,"crwIS")) {
                          crawlr:::as.data.frame.crwIS(x)
                          } else if (inherits(x,"data.frame")) {
                            x
                          }
                      }
                            )

  simPoints <- dplyr::bind_rows(sim_tracks) %>%
    dplyr::filter(locType %in% locType)

  sp::coordinates(simPoints) <- ~mu.x+mu.y
  if (!missing(crs)) {
    sp::proj4string(simPoints) <- crs
  }
  simPoints
}
jmlondon/crawlr documentation built on May 19, 2019, 1:53 p.m.