2.1 - Using video tracking data
library(trackdf)
library(lubridate)
if (requireNamespace("readr", quietly = TRUE) & requireNamespace("dplyr", quietly = TRUE)) {
library(readr)
library(dplyr)
raw <- read_csv(system.file("extdata/video/01.csv", package = "trackdf")) %>%
filter(., !ignore)
} else {
raw <- read.csv(system.file("extdata/video/01.csv", package = "trackdf"))
raw <- raw[raw$ignore, ]
}
raw
## # A tibble: 21,982 x 8
## id x y size frame track ignore track_fixed
## <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <lgl> <dbl>
## 1 1 629. 882. 1154 1 1 FALSE 1
## 2 2 1056. 657. 1064 1 2 FALSE 2
## 3 3 508. 375. 1624 1 3 FALSE 3
## 4 4 1278. 374. 1443 1 4 FALSE 4
## 5 5 1379. 343. 1431 1 5 FALSE 5
## 6 6 1137. 175. 1321 1 6 FALSE 6
## 7 7 737. 116. 1419 1 7 FALSE 7
## 8 8 922. 103. 1237 1 8 FALSE 8
## 9 1 629. 882. 1148 2 1 FALSE 1
## 10 2 1056. 656. 1068 2 2 FALSE 2
## # … with 21,972 more rows
vid_df <- track(x = raw$x, y = raw$y, t = raw$frame, id = raw$track,
origin = "2019-03-24 12:55:23", period = period("1 second") / 30,
tz = "America/New_York", table = "df")
head(vid_df)
## Track table [6 observations]
## Number of tracks: 6
## Dimensions: 2D
## Geographic: FALSE
## Table class: data frame
## id t x y
## 1 1 2019-03-24 12:55:23 629.3839 882.4783
## 2 2 2019-03-24 12:55:23 1056.1692 656.5207
## 3 3 2019-03-24 12:55:23 508.0092 375.2451
## 4 4 2019-03-24 12:55:23 1277.6466 373.7491
## 5 5 2019-03-24 12:55:23 1379.2844 343.0853
## 6 6 2019-03-24 12:55:23 1137.1378 174.5110
vid_tbl <- track(x = raw$x, y = raw$y, t = raw$frame, id = raw$track,
origin = "2019-03-24 12:55:23", period = period("1 second") / 30,
tz = "America/New_York", table = "tbl")
print(vid_tbl)
## Track table [21982 observations]
## Number of tracks: 83
## Dimensions: 2D
## Geographic: FALSE
## Table class: tibble
## # A tibble: 21,982 x 4
## id t x y
## <chr> <dttm> <dbl> <dbl>
## 1 1 2019-03-24 12:55:23 629. 882.
## 2 2 2019-03-24 12:55:23 1056. 657.
## 3 3 2019-03-24 12:55:23 508. 375.
## 4 4 2019-03-24 12:55:23 1278. 374.
## 5 5 2019-03-24 12:55:23 1379. 343.
## 6 6 2019-03-24 12:55:23 1137. 175.
## 7 7 2019-03-24 12:55:23 737. 116.
## 8 8 2019-03-24 12:55:23 922. 103.
## 9 1 2019-03-24 12:55:23 629. 882.
## 10 2 2019-03-24 12:55:23 1056. 656.
## # … with 21,972 more rows
vid_dt <- track(x = raw$x, y = raw$y, t = raw$frame, id = raw$track,
origin = "2019-03-24 12:55:23", period = period("1 second") / 30,
tz = "America/New_York", table = "dt")
vid_dt
## Track table [21982 observations]
## Number of tracks: 83
## Dimensions: 2D
## Geographic: FALSE
## Table class: data table
## id t x y
## 1: 1 2019-03-24 12:55:23 629.3839 882.4783
## 2: 2 2019-03-24 12:55:23 1056.1692 656.5207
## 3: 3 2019-03-24 12:55:23 508.0092 375.2451
## 4: 4 2019-03-24 12:55:23 1277.6466 373.7491
## 5: 5 2019-03-24 12:55:23 1379.2844 343.0853
## ---
## 21978: 82 2019-03-24 12:56:56 580.7614 587.2513
## 21979: 34 2019-03-24 12:56:56 493.5477 529.5454
## 21980: 47 2019-03-24 12:56:56 498.8001 432.5990
## 21981: 58 2019-03-24 12:56:56 562.6123 266.9754
## 21982: 67 2019-03-24 12:56:56 1046.3904 146.4723
2.2 - Using GPS tracker data
if (requireNamespace("readr", quietly = TRUE) & requireNamespace("dplyr", quietly = TRUE)) {
raw <- read_csv(system.file("extdata/gps/01.csv", package = "trackdf")) %>%
na.omit()
} else {
raw <- read.csv(system.file("extdata/gps/01.csv", package = "trackdf"))
raw <- raw[complete.cases(raw), ]
}
raw
## # A tibble: 3,596 x 4
## date time lon lat
## <date> <time> <dbl> <dbl>
## 1 2015-09-10 07:00:00 15.8 -22.4
## 2 2015-09-10 07:00:01 15.8 -22.4
## 3 2015-09-10 07:00:04 15.8 -22.4
## 4 2015-09-10 07:00:05 15.8 -22.4
## 5 2015-09-10 07:00:08 15.8 -22.4
## 6 2015-09-10 07:00:09 15.8 -22.4
## 7 2015-09-10 07:00:09 15.8 -22.4
## 8 2015-09-10 07:00:10 15.8 -22.4
## 9 2015-09-10 07:00:11 15.8 -22.4
## 10 2015-09-10 07:00:12 15.8 -22.4
## # … with 3,586 more rows
gps_df <- track(x = raw$lon, y = raw$lat, t = paste(raw$date, raw$time), id = 1,
proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df")
## Warning: 1 failed to parse.
## Track table [6 observations]
## Number of tracks: 1
## Dimensions: 2D
## Geographic: TRUE
## Projection: +proj=longlat +datum=WGS84 +no_defs
## Table class: data frame
## id t x y
## 1 1 2015-09-10 07:00:00 15.76468 -22.37957
## 2 1 2015-09-10 07:00:01 15.76468 -22.37957
## 3 1 2015-09-10 07:00:04 15.76468 -22.37958
## 4 1 2015-09-10 07:00:05 15.76468 -22.37958
## 5 1 2015-09-10 07:00:08 15.76467 -22.37959
## 6 1 2015-09-10 07:00:09 15.76467 -22.37959
gps_tbl <- track(x = raw$lon, y = raw$lat, t = paste(raw$date, raw$time), id = 1,
proj = "+proj=longlat", tz = "Africa/Windhoek", table = "tbl")
## Warning: 1 failed to parse.
## Track table [3596 observations]
## Number of tracks: 1
## Dimensions: 2D
## Geographic: TRUE
## Projection: +proj=longlat +datum=WGS84 +no_defs
## Table class: tibble
## # A tibble: 3,596 x 4
## id t x y
## <chr> <dttm> <dbl> <dbl>
## 1 1 2015-09-10 07:00:00 15.8 -22.4
## 2 1 2015-09-10 07:00:01 15.8 -22.4
## 3 1 2015-09-10 07:00:04 15.8 -22.4
## 4 1 2015-09-10 07:00:05 15.8 -22.4
## 5 1 2015-09-10 07:00:08 15.8 -22.4
## 6 1 2015-09-10 07:00:09 15.8 -22.4
## 7 1 2015-09-10 07:00:09 15.8 -22.4
## 8 1 2015-09-10 07:00:10 15.8 -22.4
## 9 1 2015-09-10 07:00:11 15.8 -22.4
## 10 1 2015-09-10 07:00:12 15.8 -22.4
## # … with 3,586 more rows
gps_dt <- track(x = raw$lon, y = raw$lat, t = paste(raw$date, raw$time), id = 1,
proj = "+proj=longlat", tz = "Africa/Windhoek", table = "dt")
## Warning: 1 failed to parse.
## Track table [3596 observations]
## Number of tracks: 1
## Dimensions: 2D
## Geographic: TRUE
## Projection: +proj=longlat +datum=WGS84 +no_defs
## Table class: data table
## id t x y
## 1: 1 2015-09-10 07:00:00 15.76468 -22.37957
## 2: 1 2015-09-10 07:00:01 15.76468 -22.37957
## 3: 1 2015-09-10 07:00:04 15.76468 -22.37958
## 4: 1 2015-09-10 07:00:05 15.76468 -22.37958
## 5: 1 2015-09-10 07:00:08 15.76467 -22.37959
## ---
## 3592: 1 2015-09-10 07:59:55 15.76231 -22.37752
## 3593: 1 2015-09-10 07:59:56 15.76230 -22.37752
## 3594: 1 2015-09-10 07:59:57 15.76229 -22.37752
## 3595: 1 2015-09-10 07:59:58 15.76229 -22.37751
## 3596: 1 2015-09-10 07:59:59 15.76228 -22.37751