This project aims to develop methods and classes specifically designed for trajectory analysis. Over the past five weeks, I have made progress in three main aspects.
First, I have been learning the basics of developing packages for R and making a transition from an R user (a.k.a. a useR) to an R developer. Second, I wrote a function for converting raw trajectory files into STI objects and eventually into STTDF objects. Third, I wrote an additional function to enable a simple spatial overlay operation between one or more STTDF object(s) and a SpatialPolygons object (from sp package), both at the individual point level, as well as at the trajectory level.
More specifically, the function named STItoSTTDF creates an STTDF object from STI objects and attribute vectors (see the top three boxes in the diagram). In this process, it is assumed that each STI object contains a single trip (or burst) and the attributes of the points in each trip, such as altitude, user ID, and trip ID, are stored in attribute vectors. In addition, five more attributes will be calculated:
- The displacement (i.e., distance) (Unit: meter) between each pair of consecutive points;
- The time lapsed (Unit: second) between each pair of consecutive points;
- The average speed (Unit: km/h) between each pair of consecutive points;
- The absolute turning angle between each pair of consecutive points;
- The change in altitude between each pair of consecutive points.
All five attributes, along with the original attributes from the trajectory file (e.g., altitude), are stored in the data frame slot of the STTDF object.
The spatial overlay operation between an STTDF object and a SpatialPolygons object (from sp package) has two levels. On the first level, the spatial overlay operation is expected to return all trips from the STTDF object that overlay with a SpatialPolygons object. This is realized by coercing the STTDF object into a SpatialLines object (see the bottom two boxes in the diagram) such that the over() function from rgeos package can be employed to retrieve the indexes of the SpatialLines object that overlay the SpatialPolygons object or vice versa. In future weeks, I will attempt to convert SpatialLines objects back to STTDF objects (as indicated by the red arrow in the diagram).
On the second level, the spatial overlay operation is expected to return all trips completely inside the SpatialPolygons object. If a trip partially overlaps with the SpatialPolygons object, only the “inside” part of the trip will be returned. This is realized by using the points.in.polygon() function from the sp package.
The two levels of overlay operations discussed above are both solely based on the spatial dimension of trajectory data. This means the temporal dimension of trajectory data, as well as the attribute’s data, are being discarded. In the forthcoming weeks, I plan to keep working on the overlay operations so that the temporal dimension and attribute data will be included.
More information about this project can be found at https://r-forge.r-project.org/R/?group_id=1550
Leave a Reply