potential_stay: potential_stay

Description Usage Arguments Value Examples

View source: R/potential_stay.R

Description

Function that calculates the time intervals at which the individual could have been at spgeom, a spatial location as a point, line or polygon. The total potential stay time might not be equal to the sum of the intervals. This applies to STP_tracks with multiple intersections for one STP and if the track has time uncertainty. If the track has time unceratinty the method calculates the max potential stay for each STP, which may result in a time overlap in the returned potential stay time intervals. If space-time prism has an activity_time, it is assumed that individual is at the location for the activity. The potential_stay time interval is thus not affected by the activity_time if the sp_geom can be reached.

Usage

1
potential_stay(STP_track, spgeom, x_density = 250)

Arguments

STP_track

A STP_Track

spgeom

A Spatialpoints,Spatiallines or Spatialpolygons object

x_density

Paramter used for calculating PPA. Default is 250 coordinates The amount of x coordinates for which the corresponding y coordinate(s) will be calculated.

Value

A named list with the potential stay time intervals for each STP that intersects with the spatial geometry

Examples

 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
library(rgeos)
library(sp)
library(spacetime)
library(rgl)
#--------------------------create a STP_Track--------------------------
# set time
t1 <- as.POSIXct(strptime("01/01/2017 12:00:00", "%m/%d/%Y %H:%M:%S"))
t2 <- as.POSIXct(strptime("01/01/2017 14:00:00", "%m/%d/%Y %H:%M:%S"))
n<-5
time<-seq(t1,t2,length.out = n)
# set coordinates
x=c(1,3,4,7,6)
y=c(2,5,8,9,11)

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}
my_track1<-Track(stidf1)

# set maximum speed
v1<-getVmaxtrack(my_track1)*1.5

# STP_track class
STP_track1<-STP_Track(my_track1,v1)

#--------------------------create a spatialpolygon--------------------------
lake <- readWKT("POLYGON((1 8,1.3 8.5,1.7 8.7,2 9,2.5 9.2,3 9,3.5 8.5,3.2 7.7,2.5 7.5,2 7.5,1 8))")
lake@proj4string<-crs_NL

# calculate the potential stay time for point
intervals <- potential_stay(STP_track = STP_track1,spgeom = lake)
intervals
# calculate the time the individual could have been at the lake
lake_time <- sum(sapply(intervals, function(STP){difftime(STP[2],STP[1],units = 'mins')}))

print(paste('Total time individual could have been at the lake is ',round(lake_time,2),'minutes'))

# visulise in 2D
plot(STP_track1,type='b')
PPA_track<-PPA(STP_track1)
plot(PPA_track,add=T)
plot(lake,add=T,border= 'blue',lwd=2)

# visulise in 3D
open3d()
zfac<-STP_plot(STP_track1,time_interval = 0.6)

axes_STP_plot(c(STP_track1@endTime[1],STP_track1@endTime[n]),z_factor = zfac,n_ticks_z = 5,n_ticks_xy = 4)

x<-lake@polygons[[1]]@Polygons[[1]]@coords[,1]
y<-lake@polygons[[1]]@Polygons[[1]]@coords[,2]
z<-difftime(STP_track1@endTime[n],STP_track1@endTime[1],units = 'mins')*zfac

shade3d(translate3d(
 extrude3d(x,y,thickness = z),0,0,0),col='blue',add=TRUE)

markvregel/STPtrajectories documentation built on May 21, 2019, 12:25 p.m.