Quantcast

Working with trajectories: ltraj.

classic Classic list List threaded Threaded
3 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Working with trajectories: ltraj.

Dylann Kersusan
Hi again,

I am still working on class object ltraj. Here you have the summary of my
trajectory:

> summary(ltrj.obj)    id burst nb.reloc NAs          date.begin            date.end
1 Alma  Alma      136   0 2010-05-01 02:00:56 2010-06-30 02:00:41


and the output of the head function:

> head(ltrj.obj[[1]])        x       y                date   dx   dy       dist    dt    R2n abs.angle  rel.angle
1 1593865 7459671 2010-05-01 02:00:56    0    0   0.000000 32398
0        NA         NA
2 1593865 7459671 2010-05-01 11:00:54   -2    3   3.605551 32399
0  2.158799         NA
3 1593863 7459674 2010-05-01 20:00:53  202 -382 432.120354 21632
13 -1.084378  3.0400080
4 1594065 7459292 2010-05-02 02:01:25 -241 -303 387.156299 32493
183641 -2.242714 -1.1583352
5 1593824 7458989 2010-05-02 11:02:58 -101  367 380.644191 32276
466805  1.839353 -2.2011192
6 1593723 7459356 2010-05-02 20:00:54  188  293 348.127850 21590
119389  1.000322 -0.8390307


I am trying to select only a part of the trajectory stored in this ltraj
class object, following an example from Calenge in the package
'adehabitatLT':

lim <- as.POSIXct(strptime(c("28/05/2010 02:00:40", "30/06/2010 02:00:41"),
"%d/%m/%Y %H:%M:%S"))
ltrj.bis <- gdltraj(ltrj.obj, min=lim[1], max=lim[2], type="POSIXct" )

but for some reasons it does not work properly. I got this error message
that I do not understand:

Error in `[.default`(res, , names(res) %in% which, drop = FALSE) :
  number of dimensions incorrect


Anyone has an idea about why it doesn't work?
Thankx a lot.

Cheers

--
Dylann Kersusan
Master Biodiversity and Conservation
Zoology dept. Stockholm University
--
Grimsö Wildlife Research Center
Ecology dept. SLU
Riddarhyttan-Sweden

        [[alternative HTML version deleted]]


_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Working with trajectories: ltraj.

Clement Calenge

[snip]

> I am trying to select only a part of the trajectory stored in this ltraj
> class object, following an example from Calenge in the package
> 'adehabitatLT':
>
> lim <- as.POSIXct(strptime(c("28/05/2010 02:00:40", "30/06/2010 02:00:41"),
> "%d/%m/%Y %H:%M:%S"))
> ltrj.bis <- gdltraj(ltrj.obj, min=lim[1], max=lim[2], type="POSIXct" )
>
> but for some reasons it does not work properly. I got this error message
> that I do not understand:
>
> Error in `[.default`(res, , names(res) %in% which, drop = FALSE) :
>    number of dimensions incorrect
>
>
> Anyone has an idea about why it doesn't work?

You have identified a bug in the function gdltraj. I have corrected this
bug and uploaded a new version of the package to CRAN. It will be
available soon. Meanwhile, you can use this function instead:

gdltraj <- function (x, min, max, type = c("POSIXct", "sec", "min", "hour",
     "mday", "mon", "year", "wday", "yday"))
{
     if (!inherits(x, "ltraj"))
         stop("x should be of class \"ltraj\"")
     if (!attr(x, "typeII"))
         stop("x should be of type II (time recorded)")
     type <- match.arg(type)
     if (type == "POSIXct") {
         x <- lapply(x, function(y) {
             infol <- attr(y, "infolocs")
             if (!is.null(infol))
                 infol <- infol[(y$date > min) & (y$date < max),
                   , drop=FALSE]
             y <- y[(y$date > min) & (y$date < max), ]
             if (!is.null(infol))
                 attr(y, "infolocs") <- infol
             return(y)
         })
     }
     else {
         x <- lapply(x, function(y) {
             da <- as.POSIXlt(y$date)[[type]]
             infol <- attr(y, "infolocs")
             if (!is.null(infol))
                 infol <- infol[(da >= min) & (da < max), ,drop=FALSE]
             y <- y[(da >= min) & (da < max), ]
             if (!is.null(infol))
                 attr(y, "infolocs") <- infol
             return(y)
         })
     }
     if (all(sapply(x, nrow) == 0))
         stop("No relocations within the specified interval")
     x[sapply(x, nrow) == 0] <- NULL
     class(x) <- c("ltraj", "list")
     attr(x, "typeII") <- TRUE
     attr(x, "regular") <- is.regular(x)
     x <- rec(x)
     return(x)
}

HTH

Clément Calenge

--
Clément CALENGE
Cellule d'appui à l'analyse de données
Direction des Etudes et de la Recherche
Office national de la chasse et de la faune sauvage
Saint Benoist - 78610 Auffargis
tel. (33) 01.30.46.54.14

_______________________________________________
R-sig-ecology mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Working with trajectories: ltraj.

marta_TM
This post has NOT been accepted by the mailing list yet.
In reply to this post by Dylann Kersusan
Hi everyone,
I'm working also with trajectories (AdehabitatLT , ltraj), but with marine animals. I would like to know if this package can avoid certain cells when join the points to line.

I read in other forums that it's possible using the shortestPath join points to line avoiding a polygon.

Thanks in advance
Marta
Loading...