[R-sig-Geo] dynamic (interactive) representation of several GPS trajectories

Gabriele Cozzi gab.cozzi at gmail.com
Mon Feb 23 10:08:49 CET 2015


Roman,
thanks for your input. Animate works fine.


Mathieu,
thanks a lot for the codes! I will soon try them out on my data.

Cheers,
Gabriele



On Fri, Feb 20, 2015 at 10:39 PM, Mathieu Basille <
basille.web at ase-research.org> wrote:

> In addition to Roman's suggestion, I tweaked the function 'plot.ltraj' to
> successfully implement a non-interactive version of what (I think) you
> want, that is a video (for an interactive version of it, keep reading and
> see below, but there would be only one individual unfortunately). Among a
> few other things, the function now allows to plot all (selected)
> individuals on the same plot (argument 'by = "none"), which is relevant for
> your purpose. It also allow you to modify point/line graphical settings.
>
> The modified function is available in the package "hab":
>
> http://ase-research.org/basille/hab
>
> (probably better to install the one from GitHub directly)
>
> Keep in mind that this is not a package as stable as adehabitatLT. I do my
> best, but use at your own risks! ;)
>
> Now, if you would like to export a video, you could use the modified
> 'plot.ltraj' to do essentially the following steps:
>
> * prepare a time sequence
> * use this sequence to loop over the whole ltraj, subset the relevant time
> period, and plot it
> * export as PNG at each step
> * use ffmpeg to convert it in mp4 video
>
> The resulting video looks like this:
>
> http://ase-research.org/basille/pres/Basille_FLREC_2014/video/wost.mp4
>
> or that:
>
> http://ase-research.org/basille/pres/Basille_FLREC_
> 2014/video/wost-dark.mp4
>
> with different graphical parameters. In details (but you'll have to adjust
> it to your own data), it goes like this ['wlt' is the ltraj object]:
>
> ## ================================================ ##
> ## Load 'hab' and 'lubridate' (for time management)
> library(hab)
> library(lubridate)
>
> ## Prepare the sequence (tseq12 every 12 hours)
> tseq12 <- seq(ymd("20090301"), ymd("20111231"), by = 3600*12)
> length(tseq12)
>
> ## Prepare the graphical parameters with the complete plot
> library(RColorBrewer)
> wcol <- brewer.pal(8, "Dark2")
> names(wcol) <- burst(wlt)
> par(mar = c(0, 0, 0, 0), bg = "#3b3f43")
> plot(wlt, by = "none", axes = FALSE, ppar = list(pch = 20, col = wcol),
> lpar = list(col = wcol, lwd = 3), spoldf = wMapc, spoldfpar = list(col =
> "#ecececff", border = NA), final = FALSE)
> text(x = 0, y = 3000000, label = paste(month(tseq12[1], label = TRUE),
> year(tseq12[1]), sep = "\n"), cex = 3, col = "#ecececff")
>
> ## And plot windows of 5 days in a loop
> library(Cairo)
> for (i in 1:length(tseq12)) {
>     CairoPNG(filename = paste0("img/wost", sprintf("%05d", i),
>         ".png"), bg = "#fdfbf4ff", width = 1000, height = 1000)
>     par(mar = c(0, 0, 0, 0), bg = "#fdfbf4ff")
>     plot(subset(wlt, date >= tseq12[i] & date < tseq12[i] + 3600 *
>         24 * 5), by = "none", axes = FALSE, ppar = list(pch = 20,
>         col = wcol, cex = 4), lpar = list(col = wcol, lwd = 12),
>         spoldf = wMapc, spoldfpar = list(col = "white", border =
> "#a6a6a6ff", lwd = 3),
>         final = FALSE, xlim = range(coordinates(wostsub)[, "x"]),
>         ylim = range(coordinates(wostsub)[, "y"]))
>     text(x = 0, y = 3e+06, label = paste(month(tseq12[i], label = TRUE),
>         year(tseq12[i]), sep = "\n"), cex = 6, col = "#a6a6a6ff")
>     dev.off()
> }
>
> ## Finally convert to a video with ffmpeg
> ## https://trac.ffmpeg.org/wiki/Create%20a%20video%
> 20slideshow%20from%20images
> system("ffmpeg -r 0.3 -framerate 30 -i img/wost%05d.png -c:v libx264
> -pix_fmt yuv420p video/wost.mp4")
> ## ================================================ ##
>
> Looks quite complicated, but I promise it's not that difficult!
>
> Now for the interactive version: I also tweaked 'trajdyn' quite a bit: it
> allows to display only a given number of steps, increment by a given number
> of steps, change point/line graphical parameters, etc. *But* it doesn't
> allow to display several bursts/individuals at once, just as 'plot.ltraj'
> now does... This is a strong limitation to what you want to achieve, and
> I'm afraid that implementing it (which would be interesting, but I did not
> have that in mind yet) would be a tremendous work.
>
> Hope this helps,
> Mathieu.
>
>
> Le 20/02/2015 05:43, Gabriele Cozzi a écrit :
>
>  Dear list,
>>
>> I have relocation data for about 20 individuals (ID) for a total of about
>> 70K rows organised in the following data frame:
>> timevar <-as.numeric(Timestamp); SB is categorical with 2 levels, the
>> other
>> variables are self-explanatory I think
>>
>> ID       Date        Time           Timestamp              Lon       Lat
>>           Alti SB timevar
>> D 2013-01-01 18:40:00 2013-01-01 18:40:00 21.85803 -26.99953 917  0
>> 1500
>> D 2013-01-01 18:55:00 2013-01-01 18:55:00 21.85877 -27.00000 921  0
>> 2400
>> D 2013-01-01 19:10:00 2013-01-01 19:10:00 21.85907 -27.00015 925  0
>> 3300
>> A 2013-01-01 19:27:00 2013-01-01 19:27:00 21.85875 -27.00142 922  1
>> 4320
>> A 2013-01-02 06:40:00 2013-01-02 06:40:00 21.85872 -27.00142 919  1
>>  44700
>> A 2013-01-02 06:55:00 2013-01-02 06:55:00 21.86060 -27.00090 916  0
>>  45600
>> ..    ...............     ...........           ......................
>>     ........      .........      ....  ..    ......
>>
>> What I would like to do is to create an animated plot where I can see how
>> the various individuals move in relationship to each other.
>>
>> The gvisMotionChart() function from the googleVis package does what I need
>> on a small subset of my data but it crashes if I try to do the same on the
>> entire data set.
>>
>> A reproducible example for two individuals:
>>       x <- rnorm(40, 21, 0.5)
>>       y <- rnorm(40, -27, 0.5)
>>       ID <- rep(c("A","B"), each=20)
>>       Alt <- floor(rnorm(40, 900, 10))
>>       tvar <- 1:40
>>       tvarA <- sample(tvar,20)
>>       tvarB <- setdiff(tvar, tvarA)
>>
>>       DF <- data.frame(ID,x,y,Alt,tvar = c(tvarA,tvarB))
>>       DF <- DF[order(DF$ID,DF$tvar),]
>>
>>       library(googleVis)
>>       plot(gvisMotionChart(DF, idvar="ID", timevar= "tvar"))
>>
>>
>> An alternative along the lines of what I want would be  the
>> trajdyn{adehabitatLT}, even if it does not allow dynamic movements of more
>> than one individual at the time, which is unfortunate in my case.
>>
>> Any suggestion regarding alternative packages/functions is highly
>> appreciated.
>>
>> Thanks in advance,
>> Gabriele
>>
>>
>>
> --
>
> ~$ whoami
> Mathieu Basille
> http://ase-research.org/basille
>
> ~$ locate --details
> University of Florida \\
> Fort Lauderdale Research and Education Center
> (+1) 954-577-6314
>
> ~$ fortune
> « Le tout est de tout dire, et je manque de mots
> Et je manque de temps, et je manque d'audace. »
>  -- Paul Éluard
>
> --
>
> ~$ whoami
> Mathieu Basille
> http://ase-research.org/basille
>
> ~$ locate --details
> University of Florida \\
> Fort Lauderdale Research and Education Center
> (+1) 954-577-6314
>
> ~$ fortune
> « Le tout est de tout dire, et je manque de mots
> Et je manque de temps, et je manque d'audace. »
>  -- Paul Éluard
>
>


-- 
Gabriele Cozzi
Postdoctoral Research Associate
Population Ecology Research Group
http://www.popecol.org

Zurich University
Institute of Evolutionary Biology and Environmental Studies
Winterthurerstr. 190
8057 Zurich - Switzerland
E-mail: gabriele.cozzi at uzh.ch
Office: 34-J-38
Phone: +41(0)44 635 47 56
Fax: +41(0)16355711
http://www.ieu.uzh.ch

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list