aggregate: Spatio-temporal aggregation of trajectory data

Description Usage Arguments Value Note Examples

Description

The method aggregate performs spatio-temporal (optionally weighted) aggregation of trajectory data over spatial or spatio-temporal geometries.

For further detailed information please see the vignette!

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## S4 method for signature 'Track'
aggregate(x, by, FUN = mean, ..., simplify = TRUE,
  use.data = TRUE, weight.points = NULL)

## S4 method for signature 'Tracks'
aggregate(x, by, FUN = mean, ..., simplify = TRUE,
  use.data = TRUE, weight.points = NULL, weight.tracks = NULL)

## S4 method for signature 'TracksCollection'
aggregate(x, by, FUN = mean, ...,
  simplify = TRUE, use.data = TRUE, weight.points = NULL,
  weight.tracks = NULL, byID = FALSE)

Arguments

x

object of class Track, Tracks or TracksCollection (see section 'Usage')

by

object of class SpatialGrid, SpatialPixels, SpatialPolyons or STF with SpatialPixels or SpatialPolyons in the sp slot. data.frame counterparts of these objects are accepted as well.

FUN

aggregation function used to calculate the aggregated values, optional a function that expects a vector with weights as its second argument to perform a weighted aggregation.

...

optional additional arguments to FUN

simplify

logical, should the return object be simplified (if possible)

use.data

TRUE (all data), an index vector or a vector of column names, indicating which data should be considered from the data slot(s) of the trajectories object.

weight.points

NULL, 'byTime', 'byDist' or 'equal', indicates the weighting of points' attribute data when calculating the aggregated values from a Track object's attributes for a spatio-temporal geometry.

weight.tracks

NULL, 'byTime', 'byDist' or 'equal', indicates the weighting of track objects when calculating the aggregated values from several Track objects' parts for a spatio-temporal geometry.

byID

logical, indicating if the aggregation should be performed individually for each Tracks object if x is a TracksCollection

Value

An object of class STFDF is returned, whose data slot contains the aggregated values for each spatio-temporal geometry.

Note

The arguments weight.points and weight.tracks should just be specified, if a function is passed to FUN that expects a vector with weights!

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
30
31
32
33
## load toy example data
load(system.file("extdata","trajaggr_TestData.RData", package = "trajaggr"), verbose = FALSE)
## Aggregation over STF objects
# Aggregate Track over STF with two time intervals
# FUN = max
agg <- aggregate(Track_A1, stf_Polys_2t, FUN = max)
class(agg)
dim(stf_Polys_2t)
dim(agg)
slot(agg, "data")
# FUN = sum
agg_0 <- aggregate(Track_A1, stf_Polys_2t, FUN = sum, na.rm= TRUE)
slot(agg_0, "data")
# FUN = weighted.mean, weighted by time
agg_1 <- aggregate(Track_A1, stf_Polys_2t, FUN = weighted.mean, 
weight.points = "byTime")
slot(agg_1, "data")
##
# Aggregate Tracks over STF with two time intervals
agg_2 <- aggregate(Tracks_A, stf_Polys_2t, FUN = weighted.mean, na.rm = TRUE, 
weight.points = "byTime")
slot(agg_2, "data")
##
# Aggregate TracksCollection over STF with two time intervals
agg_3 <- aggregate(TrColl, stf_Polys_2t, FUN = weighted.mean, na.rm = TRUE, 
weight.points = "byTime")
slot(agg_3, "data")
##
# Aggregate TracksCollection seperated by individuals over STF with two time 
# intervals,
agg_3 <- aggregate(TrColl, stf_Polys_2t, FUN = weighted.mean, na.rm = TRUE, 
weight.points = "byTime", byID = TRUE)
slot(agg_3, "data")

roland-h/trajaggr documentation built on Jan. 19, 2021, 1:02 p.m.