Spatiotemporal data S4 objects, methods, support for data with spatial and temporal components
Welcome to the spatiotemporal S4 class/method project. We are getting setup right now. Please join our project!
Note: This vignette was directly copied from the sp package, then edited. Hopefully they will see this as flattery...
The spt package provides S4 classes and methods for dealing with spatiotemporal data in S (R and S-Plus1 ). The spatiotemporal data structures implemented currently include points, with support for lines, polygons and grids coming in the next release, 0.01-02. We have chosen to use S4 classes and methods style (Chambers, 1998) to allow validation of objects created. Although we mainly aim at using spatiotemporal data in the geographical (two-dimensional) domain, the data structures that have a straightforward implementation in higher dimensions (points, grids) do allow this.
The motivation to write this package was born from my work at the EPA as a postdoc along with the SAMSI program on Spatiotemporal analysis where I had the privilege to be a party crasher. At this time, there are no packages with broad support for spatiotemporal data, however there are various associated
The package is available on R-forge. From the package home page, http://spt.r-forge.r-project.org, a graph gallery with R code, and the development source tree are available.
This vignette describes the initial classes, methods and functions provided by spt. Instead of manipulating the class slots (components) directly, we provide methods and functions to create the classes from elementary types such as data.frames or vectors and to convert them back to any of these types. Also, coercion (type casting) from one class to the other is provided sparsely, where relevant. If something isn’t provide, please request it from the author(s).
Package spt is installed by
Currently, I put a lot of dependencies and they’re not all necessary now (especially the suggested packages).
Package spt is loaded by
Spatiotemporal data is a complicated affair. There are many, many types of spatiotemporal data and many, many uses of it. I do not presuppose to help all users with all applications. The current efforts only pertain to my current work with air pollution data, monitoring sites located at lat/long locations (x,y), producing an observation such as the measurement of ozone in ppm at regular time intervals (eg hours, days, etc), usually which have some relation to the regulatory standard (I have the outline of functions to calculate the primary and secondary ozone standard, for example). These stations eventually produce flat (eg text) files which are 4 columns (lat, long, time, obs) and nobs rows.
The basic structure of spatiotemporal classes consists of 3 core classes and 1 optional class. The core classes are for storing the temporal part of the data, the spatial part of the data, and the observations. These are stored somewhat independently, with a unique identifier for the time and spatial location providing the map between the classes, in the spirit of a relational database. This has several advantages. First, the bulky temporal and spatial parts are reduced to their unique elements, reducing storage space and speeding up computation by performing operations on the unique elements, then duplicating those results as needed. Second, it allows the data to be stored in different places. This is not currently implemented, but it would allow the spatial parts to be stored using, say, the SQLiteMap package for the spatial part.
The current class is SpatialTemporalDataFrame. However, only point data is currently (v 0.01-01) supported.
Currently, this class contains objects of the other classes. From a big picture view, I don’t know if it’s better to use setClassUnion instead.
Currently, the temporal class is called stTemporal. It consists of a pairlist (but it’s currently 2 vectors, the integer unique temporal IDs, and the timeDate time stamps.
The format is very important to ensure that the timedates are read correctly. Please visit the help page for strptime for the complete list.
Example: create, get,
Currently, the spatial class is called stSpatial. It consists of 2 objects, the integer unique spatial IDs, and a Spatial object, currently only SpatialPoints is supported.
Please visit the vignett for the sp package for the complete list of items to be supported in version 1. Note that none of the data containing classes will be supported here since we have our own data classes.
Currently I inherit the spatial class, and I’m not sure what the implications are for that (there’s a big difference whether you contain an object of a class or whether you extend a class).
Example: create, get,
The main data class is called stDataFrame
Originally I had put in a metadata class to provide information about the data: units, collection data, url, citation info, etc, but I have removed it until the package is more mature unless there is rampant support.
There are methods for: dist, join, subset, apply, but I don’t have time to fully go into them yet (short on time)....
This code will be in need of constant performance work. I have tested the SpatialTemporalDataFrame with a maxtrix of about 3.5 million observations, with about 4,400 unique times and 900 unique locations. The original text file was about 240 Mb, it took aboud 10 min to create the R object (with match and spfrtTime taking the most- I should be able to increase the speed by removing match and replacing it with some unique/duplicated work), and the resulting saved Rdata file was about 140 Mb. This data set has lat, long, time, obs1, obs2. I used Rprof and calls to Sys.time() (verbose option inside constructor) to get data.
No ambitious project would be complete without feature requests.
The project summary page you can find here.