Learn R Programming

topdowntimeratio (version 0.1.0)

getSegments: Get Segments

Description

Extract segment info from the segmented data.table.

Usage

getSegments(
  data,
  coord.type = c("coordinate", "distance", "both"),
  group = FALSE
)

Value

data.table with segments only, containing information about the start and end locations, start and end time and distance covered by the segment

Arguments

data

data.table returned from function tdtr()

coord.type

return actual coordinates, relative distance, or both (see Details)

group

separate by group, default is FALSE

Details

Segment location information can be either in lat/lon coordinates, or expressed in terms of distance for a more anonymous presentation of small trajectories. (Full anonymity is not guaranteed as sufficiently long trajectories with small error parameters can provide enough data to match against a map.)

Examples

Run this code
df <- data.frame(entity_id = rep(1, 12),
   timestamp = c(1, 2, 4, 10, 14, 18, 20, 21, 24, 25, 28, 29),
   lon = c(5.1299311, 5.129979, 5.129597, 5.130028, 5.130555, 5.131083,
           5.132101, 5.132704, 5.133326, 5.133904, 5.134746, 5.135613),
   lat = c(52.092839, 52.092827, 52.092571, 52.092292, 52.092076, 52.091821,
           52.091420, 52.091219, 52.091343, 52.091651, 52.092138, 52.092698))
# First generate segments
res30 <- tdtr(df,
     group_col = NULL,
     max_error = 30)
# Then extract a data.table of segments
getSegments(res30)

# Calculating distance instead of coordinates
segs <- getSegments(res30, coord.type = "distance")
segs
plot(c(0, 700), c(0, 200), col = "white",
     xlab = "East-West distance",
     ylab = "North-South distance")
with(segs,
     segments(seg_start_lon_dist, seg_start_lat_dist,
      seg_end_lon_dist, seg_end_lat_dist))

Run the code above in your browser using DataLab