Skip to contents

Coercing trip objects to other classes.

Function to create a SpatialLinesDataFrame from a trip object, resulting in a line segment for each implicit segment along the tracks. The object stores the start and end times, duration and the ID of the segment.

Usage

# S3 method for class 'trip'
as.ppp(X, ..., fatal)

# S3 method for class 'trip'
as.psp(x, ..., from, to)

as.track_xyt.trip(x, ..., from, to)

explode(x, ...)

Arguments

from

see as.psp for that method.

to

See as.psp.

X

trip object.

...

reserved for future methods

fatal

Logical value, see Details of as.ppp

x

trip object

Value

ppp object

psp object

SpatialLinesDataFrame

SpatialLinesDataFrame object with each individual line segment identified by start/end time and trip ID

Examples

d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
sp::coordinates(d) <- ~x+y
tr <- trip(d, c("tms", "id"))
#> Warning: input looks like longitude/latitude data, assuming +proj=longlat +datum=WGS84

as(tr, "ppp")
#> Marked planar point pattern: 10 points
#> Mark variables: tms, id 
#> window: rectangle = [1, 10] x [-0.782706, 2.3539448] units
d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
tr <- trip(d, c("tms", "id"))
#> Warning: input looks like longitude/latitude data, assuming +proj=longlat +datum=WGS84

 as(tr, "psp")
#> marked planar line segment pattern: 8 line segments
#> Mark variables:  origMarks, pattern
#> window: rectangle = [1, 10] x [-0.8723159, 0.7698603] units
 as.psp(tr)
#> marked planar line segment pattern: 8 line segments
#> Mark variables:  origMarks, pattern
#> window: rectangle = [1, 10] x [-0.8723159, 0.7698603] units
 d <- data.frame(x=1:10, y=rnorm(10), tms=Sys.time() + 1:10, id=gl(2, 5))
 tr <- trip(d)
#> Warning: input looks like longitude/latitude data, assuming +proj=longlat +datum=WGS84

spldf <- explode(tr)
summary(tr)
#> 
#> Object of class trip
#>   tripID ("id") No.Records   startTime ("tms")     endTime ("tms") tripDuration
#> 1             1          5 2026-11-29 10:29:10 2026-11-29 10:29:14       4 secs
#> 2             2          5 2026-11-29 10:29:15 2026-11-29 10:29:19       4 secs
#>   tripDistance meanSpeed maxSpeed
#> 1     748.3087  673477.8 964197.9
#> 2     794.0083  714607.5 963281.5
#> 
#> Total trip duration: 8 seconds (0 hours, 8 seconds)
#> 
#> Derived from Spatial data:
#> 
#> Object of class SpatialPointsDataFrame
#> Coordinates:
#>         min       max
#> x  1.000000 10.000000
#> y -2.052404  1.405109
#> Is projected: FALSE 
#> proj4string : [+proj=longlat +datum=WGS84]
#> Number of points: 10
#> Data attributes:
#>       tms                      id   
#>  Min.   :2026-11-29 10:29:10   1:5  
#>  1st Qu.:2026-11-29 10:29:12   2:5  
#>  Median :2026-11-29 10:29:15        
#>  Mean   :2026-11-29 10:29:15        
#>  3rd Qu.:2026-11-29 10:29:17        
#>  Max.   :2026-11-29 10:29:19        
#>