stoscan: Spatio-temporal clustering from tdbscan outpout manipulated...

Description Usage Arguments Value Examples

View source: R/stoscan.R

Description

Spatio-temporal clustering from tdbscan outpout manipulated by dt2Convexhull

Usage

1
2
3
4
5
6
7
stoscan(
  d,
  pid = "pid",
  arrival = "arrival",
  departure = "departure",
  geometry = "geometry"
)

Arguments

d

a data.frame including points which belong to clusters (tdbscan output), latitude, longitude and datetime

pid

ID unique for points that belong to one cluster

arrival

arrival datetime in polygon

departure

departure time from polygon

geometry

convex hull of points of a unique cluster

Value

data.table including pid, s_clustID = ID unique for spatial overlapping clusters, st_clustID = ID unique for spatial temporal overlapping clusters

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
require(data.table)
require(ggplot2)

data(zbird)
z = tdbscan(zbird, eps = 12, minPts   = 5, maxLag = 5, borderPoints = TRUE )
z = z[, clustID := factor(clustID)]

d = data.frame(zbird) %>% data.table
d = merge(z, d, by.x = 'id', by.y = 'sp.ID')

d = rbindlist(list(copy(d[, tagID := 'bird1']), copy(d[, tagID := 'bird2'])), use.names = TRUE)
d[tagID == 'bird2', x := x + 5]
d[tagID == 'bird2', x := x + 5]
d[!is.na(clustID), ID := paste0(tagID, '_', clustID)]

dp = dt2Convexhull(d, pid = 'ID', projection = '+proj=utm +zone=4 +datum=WGS84')

s = stoscan(dp)
d = merge(d, s, by.x = 'ID', by.y = 'pid', all.x = TRUE)

# plot of spatial overlapping clusters
ggplot(d, aes(x, y, color = as.character(s_clustID) ) ) +
  geom_path(aes(color = NULL), col = 'grey', size = .5) +
  geom_point( alpha = .5, size = 2)

# plot of spatial and temporal overlapping clusters
ggplot(d, aes(x, y, color = as.character(st_clustID) ) ) +
  geom_path(aes(color = NULL), col = 'grey', size = .5) +
  geom_point( alpha = .5, size = 2)

mpio-be/tdbscan documentation built on March 10, 2021, 1:20 p.m.