Description Usage Arguments Value Author(s) References Examples
This random trajectory generator (RTG) works as described in Technitis et al.(2015). It creates a trajectory based on the space-time prism concept, it randomly adds a user defined number of points between the points of a trajectory. The new point is randomly placed in the PPA of the corresponding point in time. The added points are evenly divided over time and are always within the space-time prism.
1 2 |
STP_track |
the STP_Track to which the randomly generated space-time points are added |
n_points |
number of points will be added between the two points. If no value is provided new point(s) will be added between all consecutive space-time points |
max_time_interval |
The max_time_interval(numeric) is the maximum allowed time difference in minutes between existing control points. If the time difference between two points is bigger than max_time_interval, new control point(s) are added in between the original control points. The Default is NULL, in which case between all control points n_points are added. |
quadsegs |
Passed to buffer. Number of line segments to use to approximate a quarter circle. Only used where paramter time_interval is relavant |
iter |
number of times to try to place sample points in the PPA before giving up and returning NULL (default = 4). This may occur when trying to hit a small and awkwardly shaped polygon in a large bounding box with a small number of points. |
A STP_Track with the newly added random space-time points. Slot data has NAs for the new points. Vmax values for new connections are equal to the vmax values of the original connections.
Mark ten Vregelaar
- Technitis, G., Othman, W., Safi, K., & Weibel, R. (2015). From A to B, randomly: A point-to-point random trajectory generator for animal movement. International Journal of Geographical Information Science, 29(6), 912-934. http://www.tandfonline.com/doi/abs/10.1080/13658816.2014.999682
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | library(spacetime)
library(sp)
#------------------------------example 1------------------------------
## Create a random trajecory based on a begin and end point
## Create trajectory with only two points
# Time
t1 <- as.POSIXct(strptime("01/01/2017 00:00:00", "%m/%d/%Y %H:%M:%S"))
t2 <- t1+0.5*60*60 # 2 hours after t1
time<-c(t1,t2)
# Spatial coordinates
x=c(5,10);y=c(10,20)
n = length(x)
crs_NL = CRS("+init=epsg:28992")
# create class STIDF
stidf1 = STIDF(SpatialPoints(cbind(x,y),crs_NL), time, data.frame(co2 = rnorm(n),O2=rnorm(n)))
# Track-class {trajectories}
track1<-Track(stidf1)
# Set maximum speed
v1<-getVmaxtrack(track1)+0.001
# STP_track class
STP1<-STP_Track(track1,v1)
plot(STP1,type='p',col='red',pch=16,cex=2)
# Create a random trajectory between the two points
random_STP_track<-RTG(STP1,n_points = 10)
plot(random_STP_track,type='b',add=TRUE)
#------------------------------example 2------------------------------
## Add points to a trajectory with multple points
## Create a STP_track
np <-6 # Number of points orignal track
t1 <- as.POSIXct(strptime("01/01/2017 00:00:00", "%m/%d/%Y %H:%M:%S"))
random1<-cumsum(sample((0.5*60):(2.8*60*60),np))
time<-t1+random1
x=random1/2
y=seq(1,100,length.out = np)
n = length(x)
crs_NL = CRS("+init=epsg:28992")
# Create class STIDF
stidf2 = STIDF(SpatialPoints(cbind(x,y),crs_NL), time, data.frame(co2 = rnorm(n),O2=rnorm(n)))
# Track-class {trajectories}
track2<-Track(stidf2)
# Set maximum speed
v1<-getVmaxtrack(track2)+0.1
# STP_track class
STP_track2<-STP_Track(track2,v1)
# STP_track2 is track with different time intervals between the space-time points.
# The distance between two points increases with the time interval
plot(STP_track2,type='p',col='red',pch=16,cex=2)
## Fill blank spot of trajecotries in two steps
# Add 2 random points in between two sapce-time points that more than 90 minutes apart
filled_track1 <-RTG(STP_track2,n_points = 2,max_time_interval = 120)
plot(filled_track1,type='p',pch=16,add=TRUE,col='blue')
# Add 1 random point in between two sapce-time points that more than 45 minutes apart
filled_track2 <-RTG(filled_track1,n_points = 1,max_time_interval = 60)
plot(filled_track2,type='b',add=TRUE,cex=0.7)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.