R/ltraj2spdf.r

"ltraj2spdf" <- function(ltr)
{
    ## Verifications
    if (!inherits(ltr, "ltraj"))
      stop("ltr should be of class \"ltraj\"")

    ## Conversion
    tr <- do.call("rbind", ltr)
    if (!is.null(infolocs(ltr))) {
        tr2 <- do.call("rbind", infolocs(ltr))
        tr <- cbind(tr, tr2)
    }
    class(tr) <- "data.frame"
    xy <- tr[!is.na(tr$x),c("x","y")]
    tr <- tr[!is.na(tr$x),]
    tr$y <- tr$x <- NULL
    res <- SpatialPointsDataFrame(xy, tr, proj4string=.checkp4(ltr))

    ## Output
    return(res)
  }

Try the adehabitatLT package in your browser

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

adehabitatLT documentation built on April 6, 2023, 5:18 p.m.