Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
cd2d3c9
Merge pull request #4 from edzer/master
Moradii Nov 6, 2018
ffba931
some updates on the text and References
Moradii Nov 16, 2018
6b9af4b
.Rd files updated + updates in some print functions
Moradii May 21, 2019
6de5a19
legend of K and pair plots edited
Moradii May 26, 2019
9213e13
range.Tracks & range.TracksCollection
Moradii Jun 6, 2019
a319f13
tsqTracks modified
Moradii Jun 6, 2019
bfad67b
from and to added to tsqTracks
Moradii Jun 6, 2019
5546fac
typo fixed
Moradii Jun 6, 2019
a09a813
ylab in plot.distrack modified
Moradii Jul 9, 2019
a33cb83
idw as method
Moradii Jul 9, 2019
aca6dbd
Voronoi method accommodated in density.list
Moradii Oct 13, 2019
86123d1
reTrack is replaced by approxTrack
Moradii Oct 22, 2019
ce01530
Merge remote-tracking branch 'refs/remotes/edzer/master' into master-…
Moradii Oct 23, 2019
a174fb0
get rid of some conflicts
Moradii Oct 23, 2019
d207d35
get rid of some conflicts
Moradii Oct 23, 2019
50f7ed6
Frechet distance fixed
Moradii Oct 27, 2019
048e3f0
FrechetDist fixed
Moradii Oct 27, 2019
8afd2f0
density.list now accepets functions to be applied to pixel values ove…
Moradii Oct 27, 2019
5fd095c
idw now accepets functions to be applied to pixel values over time
Moradii Oct 27, 2019
2a8f8ca
typo
Moradii Oct 27, 2019
6009b8d
separate documentation for TrackStats, TrackSummary and TracksSummary
Moradii Nov 10, 2019
c013ab2
small edit
Moradii Nov 10, 2019
9a63cab
unnecessary removed
Moradii Nov 11, 2019
81d8bb9
spatstat::as.im
Moradii Nov 27, 2019
9eff7d0
Tracks-methods updated
Moradii Nov 27, 2019
962dbb6
new ,Rd docs
Moradii Nov 27, 2019
4614f91
args added
Moradii Nov 27, 2019
6ae00b6
Track-class edited according to new .Rd files
Moradii Nov 27, 2019
ef5b6d3
R and Rd of generalize updated
Moradii Dec 3, 2019
4a505b1
{} added
Moradii Dec 3, 2019
054705d
Rd of classes and methods updated
Moradii Dec 3, 2019
80017a5
some Rd docs updated
Moradii Dec 3, 2019
ed0df8f
Description updated
Moradii Dec 14, 2019
ff6a88c
help of approxTrack updated
Moradii Dec 14, 2019
563b6d3
Revert "Description updated"
Moradii Dec 14, 2019
e776780
Description updated
Moradii Dec 14, 2019
8bea511
help of as.list.Tracks updated
Moradii Dec 14, 2019
1d37fe7
as.list updated
Moradii Dec 14, 2019
2784f57
all documentation updated
Moradii Dec 15, 2019
566c2dc
update
Moradii Dec 15, 2019
5a3080b
updated variable names - consistency
Moradii Dec 15, 2019
232876a
Merge remote-tracking branch 'refs/remotes/edzer/master' into master-…
Moradii Dec 15, 2019
b8bc462
library(sp) added to example
Moradii Dec 15, 2019
4ad288a
bug fixed - get rid of errors
Moradii Dec 15, 2019
58547ac
comment lines in example
Moradii Dec 15, 2019
5abd5b5
exapmle edited
Moradii Dec 15, 2019
9069420
example commented
Moradii Dec 15, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ Imports: stats, utils, graphics, methods, lattice, sp (>= 1.1-0),
spacetime (>= 1.0-0), zoo
Suggests: rgdal, rgeos, OpenStreetMap, RCurl, rjson, adehabitatLT, xts,
knitr, rgl, forecast, MASS, spatstat, taxidata
Description: Classes and methods for trajectory data, with support for nesting individual Track objects in track sets (Tracks) and track sets for different entities in collections of Tracks. Methods include selection, generalization, aggregation, intersection, simulation, and plotting.
Description: Classes and methods for trajectory data, with support for nesting individual Track objects in track sets (Tracks) and track sets for different entities in collections of Tracks. Methods include selection, generalization, aggregation, intersection, simulation, and plotting. It further includes exploratory methods such as Kernel smoothing, Voronoi tessellation, distance analysis, K- and pair correlation functions.
License: GPL (>= 2)
URL: http://github.com/edzer/trajectories
Additional_repositories: http://pebesma.staff.ifgi.de
BugReports: http://github.com/edzer/trajectories/issues
VignetteBuilder: knitr
Collate: Class-Tracks.R Tracks-methods.R generalize.R stcube.R stplot.R
difftrack.R compare-methods.R rtracks.R Trackstat.R
RoxygenNote: 6.0.1
RoxygenNote: 7.0.2
NeedsCompilation: no
Packaged: 2018-09-25 11:59:22 UTC; edzer
Author: Edzer Pebesma [aut, cre] (<https://orcid.org/0000-0001-8049-7069>),
Expand Down
15 changes: 14 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export(
approxTrack, approxTracks, approxTracksCollection,
rTrack, rTracks, rTracksCollection, as.Track, as.Track.arrow,
as.Track.ppp, auto.arima.Track, avedistTrack, avemove, chimaps,
Kinhom.Track, pcfinhom.Track, reTrack, Track.idw, tsqTracks
Kinhom.Track, pcfinhom.Track, reTrack,
tsqTracks,unique.Track,as.list.Tracks,as.list.TracksCollection,range.Track,
idw.Track
)

exportMethods(
Expand Down Expand Up @@ -64,6 +66,17 @@ S3method(plot, arwlen)
S3method(print, summary.Track)
S3method(print, summary.Tracks)
S3method(print, summary.TracksCollection)
S3method("as", "list.Tracks")
S3method("as", "list.TracksCollection")
S3method("unique", "Track")
S3method(range, Track)
S3method(range, Tracks)
S3method(range, TracksCollection)
S3method(stack, TracksCollection)
S3method(unstack, TracksCollection)
S3method(c, Track)
S3method(c, Tracks)
S3method(c, TracksCollection)
S3method(print, arwlen)
S3method(print, distrack)
S3method(print, gTrack)
Expand Down
9 changes: 6 additions & 3 deletions R/Class-Tracks.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ TrackStats = function(track) {
stopifnot(!any(duration == 0))
# if (class(try(cc <- coordinates(track), silent=TRUE)) == "try-error" ||
# !is.matrix(cc))
if (!is(track@sp, "SpatialPoints"))
data.frame(matrix(nrow = length(track@sp) - 1, ncol = 0)) # empty
if (!is(track@sp, "SpatialPoints")){
data.frame(matrix(nrow = length(track@sp) - 1, ncol = 0)) # empty
}
else {
cc = coordinates(track@sp)
ll = identical(is.projected(track), FALSE)
Expand Down Expand Up @@ -100,7 +101,7 @@ TrackSummary = function(track) {
ix = index(track@time)
bb = bbox(track@sp)
conn = track@connections
data.frame(
d <- data.frame(
xmin = bb[1,1],
xmax = bb[1,2],
ymin = bb[2,1],
Expand All @@ -112,6 +113,8 @@ TrackSummary = function(track) {
medspeed = quantile(conn$speed, 0.5)
# TODO Compute some mean direction?
)
rownames(d) <- NULL
d
}

# Pre-computes elements of tracksData.
Expand Down
99 changes: 52 additions & 47 deletions R/Tracks-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ setAs("Tracks", "segments", function(from) {
ret = do.call(rbind, lapply(from@tracks,
function(x) as(x, "segments")))
ret$Track = rep(names(from@tracks),
times = sapply(from@tracks, length) - 1)
times = sapply(from@tracks, dim) - 1)
ret
}
)
Expand All @@ -42,7 +42,7 @@ setAs("Track", "data.frame",

setAs("Tracks", "data.frame",
function(from) {
l = lapply(from@tracks, function(x) rbind(as(x, "data.frame"), NA))
l = lapply(from@tracks, function(x) as(x, "data.frame"))
d = do.call(rbind, l)
d$Track = rep(names(from@tracks), times = sapply(l, nrow))
d
Expand Down Expand Up @@ -230,6 +230,7 @@ plot.TracksCollection <- function(x, y, ..., xlim = stbox(x)[,1],
plot(as(x, "SpatialLines"), xlim = xlim, ylim = ylim, axes = axes,
col = col, lwd = lwd, lty = lty, add = add, ...)
}

setMethod("plot", "TracksCollection", plot.TracksCollection)

setMethod("plot", "Tracks", function(x, ...) plot(TracksCollection(list(x)), ...))
Expand Down Expand Up @@ -378,10 +379,6 @@ summary.Tracks = function(object, ...) {
obj
}

setMethod("show", "Track", function(object) print.Track(object))
setMethod("show", "Tracks", function(object) print.Tracks(object))
setMethod("show", "TracksCollection", function(object) print.TracksCollection(object))

setMethod("summary", "Tracks", summary.Tracks)

print.summary.Tracks = function(x, ...) {
Expand Down Expand Up @@ -439,14 +436,20 @@ print.summary.TracksCollection = function(x, ...) {
invisible(x)
}

# Provide show methods.

setMethod("show", "Track", function(object) print.Track(object))
setMethod("show", "Tracks", function(object) print.Tracks(object))
setMethod("show", "TracksCollection", function(object) print.TracksCollection(object))

# Provide selection methods.
subs.Track <- function(x, i, j, ..., drop = TRUE) {
Track(as(x, "STIDF")[i, j, ..., drop = drop])
subs.Track <- function(x, i, ..., drop = TRUE) {
Track(as(x, "STIDF")[i, ..., drop = drop])
}

setMethod("[", "Track", subs.Track)

subs.Tracks <- function(x, i, j, ... , drop = TRUE) {
subs.Tracks <- function(x, i, ... , drop = TRUE) {
if (missing(i))
i = 1:length(x@tracks)
else if (is(i, "Spatial"))
Expand All @@ -461,34 +464,34 @@ subs.Tracks <- function(x, i, j, ... , drop = TRUE) {
if (!any(i))
NULL
else
Tracks(x@tracks[i], x@tracksData[i, j, drop=FALSE])
Tracks(x@tracks[i])
}
}

setMethod("[", "Tracks", subs.Tracks)

subs.TracksCollection <- function(x, i, j, ... , drop = TRUE) {
if (!missing(j) && is.character(j)) {
for(tz in seq_along(x@tracksCollection)) {
for(t in seq_along(x[tz]@tracks)) {
data = x[tz][t]@data
connections = x[tz][t]@connections
if(j %in% names(data))
data = data[j]
else
# An empty data slot is returned if the passed attribute
# does not exist. The same applies to the connections slot.
data = data.frame(matrix(nrow = dim(x[tz][t])["geometries"], ncol = 0))
if(j %in% names(connections))
connections = connections[j]
else
connections = data.frame(matrix(nrow = dim(x[tz][t])["geometries"] - 1, ncol = 0))
# Write back the just processed data and connection slots.
x@tracksCollection[[tz]]@tracks[[t]]@data = data
x@tracksCollection[[tz]]@tracks[[t]]@connections = connections
}
}
}
subs.TracksCollection <- function(x, i, ... , drop = TRUE) {
# if (!missing(j) && is.character(j)) {
# for(tz in seq_along(x@tracksCollection)) {
# for(t in seq_along(x[tz]@tracks)) {
# data = x[tz][t]@data
# connections = x[tz][t]@connections
# if(j %in% names(data))
# data = data[j]
# else
# # An empty data slot is returned if the passed attribute
# # does not exist. The same applies to the connections slot.
# data = data.frame(matrix(nrow = dim(x[tz][t])["geometries"], ncol = 0))
# if(j %in% names(connections))
# connections = connections[j]
# else
# connections = data.frame(matrix(nrow = dim(x[tz][t])["geometries"] - 1, ncol = 0))
# # Write back the just processed data and connection slots.
# x@tracksCollection[[tz]]@tracks[[t]]@data = data
# x@tracksCollection[[tz]]@tracks[[t]]@connections = connections
# }
# }
# }
if (missing(i))
s = 1:length(x@tracksCollection)
else if (is(i, "Spatial"))
Expand Down Expand Up @@ -531,8 +534,10 @@ subs.TracksCollection <- function(x, i, j, ... , drop = TRUE) {

setMethod("[", "TracksCollection", subs.TracksCollection)



setMethod("[[", c("Track", "ANY", "missing"),
function(x, i, j, ...) {
function(x, i, ...) {
# TODO What if the attribute name coexists in both the data and
# connections slot? Returning a list is inconvenient in the way that it
# raises new design issues when making selections on objects of class
Expand All @@ -548,19 +553,19 @@ setMethod("[[", c("Track", "ANY", "missing"),
)

setMethod("[[", c("Tracks", "ANY", "missing"),
function(x, i, j, ...) {
do.call(c, lapply(x@tracks, function(t) t[[i]]))
function(x, i, ...) {
do.call(list, lapply(x@tracks, function(t) t[[i]]))
}
)

setMethod("[[", c("TracksCollection", "ANY", "missing"),
function(x, i, j, ...) {
do.call(c, lapply(x@tracksCollection, function(t) t[[i]]))
function(x, i, ...) {
do.call(list, lapply(x@tracksCollection, function(t) t[[i]]))
}
)

setReplaceMethod("[[", c("Track", "ANY", "missing", "ANY"),
function(x, i, j, value) {
function(x, i, value) {
if (i %in% names(x@connections)) {
warning(paste("replacing", i, "in connections slot"))
x@connections[[i]] = value
Expand All @@ -571,7 +576,7 @@ setReplaceMethod("[[", c("Track", "ANY", "missing", "ANY"),
)

setReplaceMethod("[[", c("Tracks", "ANY", "missing", "ANY"),
function(x, i, j, value) {
function(x, i,value) {
for(index in seq_along(x@tracks)) {
if(i %in% names(x[index]@data)) {
# "dim" (and with that "from" and "to") have to be reinitialized
Expand All @@ -594,7 +599,7 @@ setReplaceMethod("[[", c("Tracks", "ANY", "missing", "ANY"),
)

setReplaceMethod("[[", c("TracksCollection", "ANY", "missing", "ANY"),
function(x, i, j, value) {
function(x, i,value) {
index = 1
for(tz in seq_along(x@tracksCollection)) {
for(t in seq_along(x[tz]@tracks)) {
Expand Down Expand Up @@ -719,11 +724,11 @@ setMethod("spTransform", c("TracksCollection", "CRS"),
# include.lowest = FALSE, right = TRUE, dig.lab = 3,
# ordered_result = FALSE, ...)

cut.Track = function(x, breaks, ..., include.lowest = TRUE, touch = TRUE) {
i = index(x)
cut.Track = function(track, breaks, ..., include.lowest = TRUE, touch = TRUE) {
i = index(track)
f = cut(i, breaks, ..., include.lowest = include.lowest)
d = dim(x) # nr of pts
x = as(x, "STIDF")
d = dim(track) # nr of pts
x = as(track, "STIDF")
if (! touch)
spl = lapply(split(x = seq_len(d), f), function(ind) x[ind, , drop = FALSE])
else
Expand All @@ -736,10 +741,10 @@ cut.Track = function(x, breaks, ..., include.lowest = TRUE, touch = TRUE) {
Tracks(lapply(spl[sapply(spl, length) > 1], Track))
}

cut.Tracks = function(x, breaks, ...) do.call(c, lapply(x@tracks, cut, breaks = breaks, ...))
cut.Tracks = function(tr, breaks, ...) do.call(c, lapply(tr@tracks, cut, breaks = breaks, ...))

cut.TracksCollection = function(x, breaks, ...)
TracksCollection(lapply(x@tracksCollection, cut, breaks = breaks, ...))
cut.TracksCollection = function(tc, breaks, ...)
TracksCollection(lapply(tc@tracksCollection, cut, breaks = breaks, ...))

"index<-.Track" = function(x, value) {
index(x@time) = value
Expand Down
Loading