FilterTraj: Filter trajectory based on conditions

View source: R/FilterTraj.r

FilterTrajR Documentation

Filter trajectory based on conditions

Description

The function FilterTraj is a function for extracting portions of a trajectory based on some filter criteria.

Usage

FilterTraj(traj, type = "attribute", filter = NA)

Arguments

traj

an object of the class ltraj which contains the time-stamped movement fixes of the object. Note this object must be a type II ltraj object. For more information on objects of this type see help(ltraj).

type

The type of filter to apply (one of 'attribute',temporal','tod').

filter

The filter criteria (see details).

Details

The function FilterTraj can be used to extract a portion of a trajectory based on temporal criteria (such as time-of-day or a temporal window) or based on attributes of the trajectory. In the case of attribute filtering, the criteria can be any of the default attributes of an ltraj object, or based on additional attributes stored alongside the trajectory. The filter parameter is a flexible way to define the criteria for filtering. The filter object can be one of:
- POSIX class objects (list of length=2) for filtering based on some temporal window (see examples);
- character object (list of length=2) for filtering based on time-of-day (see examples);
- character object containing the attribute filter criteria as a logical expression (see examples and ?subset).

NOTE: When using FilterTraj be very careful about using the output ltraj object in further analysis. When a new ltraj object is created, all the movement parameters (e.g., dist, dt) are recalculated and thus not necessarily valid. Therefore, subsequent analysis should ideally focus only on the raw fix information (i.e., x, y, date).

Value

A ltraj object with only those fixes satisfying the filter criteria.

See Also

GetTO

Examples

data(deer)
deer37 <- deer[1]
deer38 <- deer[2]


#Temporal Filter
t1 <- as.POSIXct(strptime('2005-03-09 00:00:00', format= '%Y-%m-%d %H:%M:%S'))
t2 <- as.POSIXct(strptime('2005-03-11 00:00:00', format= '%Y-%m-%d %H:%M:%S'))
twin <- c(t1,t2)
x <- FilterTraj(deer37,type='temporal',filter=twin)

#tod Filter
tod <- c('06:00:00', '10:00:00')
x <- FilterTraj(deer37,type='tod',filter=tod)

#attribute Filter
q <- 'dist > 100'
x <- FilterTraj(deer37,type='attribute',filter=q)

q <- 'dist > 100 & rel.angle < 1'
x <- FilterTraj(deer37,type='attribute',filter=q)


wildlifeDI documentation built on Nov. 14, 2023, 1:09 a.m.