three-dimensional-analysis

Question: How to create an animation of events in a two-dimensional space

For each event we have coordinates and postion in time. Create images for each sub-period. Here we choose 7 days as the length of sub-periods.

startdate <- dates("01/01/00")
enddate <- dates("11/02/09")
subperiods <- seq(from = startdate, to = enddate, by = 365)
lag <- 7

sapply(1:length(subperiods), function(x) {
   png(file=paste("/media/home.local/hans/foo/",x,".png", sep=""), width=1024, height=768, bg="transparent")
   plot(yta[which(yta$KKOD == 5),], col = "transparent")
   plot(coords[which(the.chron.object[anlagda[anlagda.to.plot]] < subperiods[x] & the.chron.object[anlagda[anlagda.to.plot]] > subperiods[x]-lag)], add=T, col="green", cex=1)
   plot(coords[which(the.chron.object[anlagda[anlagda.to.plot]] > subperiods[x] & the.chron.object[anlagda[anlagda.to.plot]] < subperiods[x+1])], add=T, col="black", cex=2)
   dev.off()
 }
)

Per sub-area summaries

input: a list of sub-areas + startdate + enddate + lag animated-output: an animation with each (criminal) fire represented as a dot. graphical-output: a graph with a line for each sub-area, with each subperiod as a tick on the x-axis. tabular-output: a table for each sub-area with adres

Per sub-area and per type of burning object summaries

input: a list of sub-areas + a list of types of burning object + startdate + enddate + lag output: a animation for each combination of sub-area and burning object type

attach(bränder)

anlagda <- which(bränder$Orsak == "Anlagd med uppsåt" | bränder$Orsak == "Barns lek med eld" | bränder$Orsak == "Fyrverkerier")
skolbränder <- which(bränder$"SRV-text" == "Fritidsgård" | bränder$"SRV-text" == "Förskola" | bränder$"SRV-text" == "Skola")

# dessa.bränder <- anlagda
dessa.bränder <- intersect(anlagda, skolbränder)

named.polygon <- "14 Tynnered"

index.in.dessa.bränder <- which(overlay(bränder[dessa.bränder,], sdn[sdn$NAMN == named.polygon,]) == 1)

intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider < subperiods[x])

bränder[intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider < enddate)),]

a <- sapply(1:length(subperiods), function(x) {
#   png(file=paste("/media/home.local/hans/foo/",x,".png", sep=""), width=1024, height=768, bg="transparent")
#   plot(sdn[sdn$NAMN == named.polygon,])
#   plot(yta[which(yta$KKOD == 5),], col = "white", add=T)
  intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider > subperiods[x] & bränder$tider > subperiods[x+1]))
#  plot(bränder[intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider < subperiods[x] & bränder$tider > subperiods[x]-lag)),], add=T, col="green")
#  plot(bränder[intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider > subperiods[x] & bränder$tider > subperiods[x+1])),], add=T, col="black")
#  dev.off()
 }
)

plot(bränder[dessa.bränder[intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider < subperiods[x] & bränder$tider > subperiods[x]-lag)),], add=T, col="green")

plot(bränder[which(intersect(dessa.bränder,which(bränder$tider < subperiods[x] & bränder$tider > subperiods[x]-lag)) == 1),], add=T, col="green") plot(bränder[which(intersect(dessa.bränder,which(bränder$tider > subperiods[x] & bränder$tider > subperiods[x+1])) == 1),], add=T, col="black")

dessa.bränder <- intersect(anlagda, skolbränder)

named.polygon <- "Gunnared"
index.in.dessa.bränder <- which(overlay(bränder[dessa.bränder,], sdn[sdn$NAMN == named.polygon,]) == 1)

a <- sapply(1:length(subperiods), function(x) {
  intersect(dessa.bränder[index.in.dessa.bränder],which(bränder$tider > subperiods[x] & bränder$tider > subperiods[x+1]))
 }
)

gunnared <- as.data.frame(bränder[a[[1]], c(6,7,11,16,22)])[, 1:5]

mylist <- list(gunnared, lärjedalen, torslanda, tynnered, frölunda)
names(mylist) <- as.vector(sdn$NAMN[c(2,3,9,11,13)])
null <- sapply(1:length(mylist), function(x) {write.csv(mylist[[x]], paste(names(mylist[x]),".csv",sep=""), row.names = F)})

comments powered by Disqus


Back to the index

Blog roll

R-bloggers, Debian Weekly
Valid XHTML 1.0 Strict [Valid RSS] Valid CSS! Emacs Muse Last modified: oktober 17, 2019