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

View source: R/stoscan.R

stoscanR Documentation

Spatio-temporal clustering from tdbscan outpout manipulated by dt2Convexhull

Description

Spatio-temporal clustering from tdbscan outpout manipulated by dt2Convexhull

Usage

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

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 June 30, 2024, 7:39 a.m.