How to create an animation of geospatial / temporal data

I have a dataset that contains about 150,000 observations of 800 items. Each observation has: the identifier of the object, latitude, longitude and time during which the object was in these coordinates. Data refer to a 24-hour period.

If I build all the data at once, I just get a blob. Can someone give me some tips on how I can animate this data so that I can track the paths of objects as a function of time?

I read the space-time firmware, but I'm not quite sure that it will do what I want. At the moment, I spend a lot of time searching on Google, but I don’t really come up with anything that suits my needs.

Any tips and pointers are greatly appreciated!

+4
source share
2 answers

Your question is a little vague, but I will tell you how I did this animation in the past.

  • Create a function that displays all the objects of the object for one time fragment:

    plot_time = function(dataset, time_id) { # make a plot with your favorite plotting package (eg `ggplot2`) # Save it as a file on disk (eg using `ggsave`), under a regular name, # frame001.png, frame002.png, see sprintf('frame%03d', time_index) } 
  • Call this function on each of your time series, for example. using lapply :

     lapply(start_time_id:stop_time_id, plot_time) 

    leads to a set of image files on the hard drive with the name frame001 to framexxx .

  • Use a tool to render these frames into a movie, for example. using ffmpeg , see for example .

This is a common workflow that has already been implemented in the animation package (thanks for reminding me of @mdsummer). You can probably use this package to get the animation.

+1
source

Here is my first use of the animation package. It was easier than I expected, and especially saveHTML really awesome. Here is my scenario (even I think my R code will be clearer :)

  • I am generating some data
  • I draw the main plot for all people as a wallpaper.
  • I modify the data to get to a wide format so that I can build an arrow between the current and next position for each person.
  • I loop through the clock to generate many stories. I put llop in the powerful saveHTML function.
  • You get an html file with nice animation. I am showing here one interim plot.

enter image description here

Here is my code:

 library(animation) library(ggplot2) library(grid) ## creating some data of hours N.hour <- 24 dat <- data.frame(person=rep(paste0('p',1:3),N.hour), lat=sample(1:10,3*N.hour,rep=TRUE), long=sample(1:10,3*N.hour,rep=TRUE), time=rep(1:N.hour,each=3)) # the base plot with base <- ggplot() + geom_point(data=dat,aes(x=lat, y=long,colour = person), size=5)+ theme(legend.position = "none") ## reshape data to lat and long formats library(plyr) dat.segs <- ddply(dat,.(person),function(x){ dd <- do.call(rbind, lapply(seq(N.hour-1), function(y)c(y,x[x$time %in% c(y,y+1),]$lat, x[x$time %in% c(y,y+1),]$long))) dd }) colnames(dat.segs) <- c('person','path','x1','x2','y1','y2') # a function to create the animation oopt <- ani.options(interval = 0.5) saveHTML({ print(base) interval = ani.options("interval") for(hour in seq(N.hour-1)){ # a segment for each time tn <- geom_segment(aes(x= x1, y= y1, xend = x2, yend = y2,colour = person), arrow = arrow(), inherit.aes = FALSE, data =subset(dat.segs,path==hour)) print(base <- base + tn) ani.pause() } }, img.name = "plots", imgdir = "plots_dir", htmlfile = "random.html", autobrowse = FALSE, title = "Demo of animated lat/long for different persons", outdir=getwd()) 
+3
source

Source: https://habr.com/ru/post/1486981/


All Articles