| spacetime {sfdep} | R Documentation |
Construct a spacetime object
Description
A spacetime object is a collection of a linked data frame and an sf objects. It can be thought of as geography linked to a table that represents those geographies over one or more time periods.
Usage
spacetime(.data, .geometry, .loc_col, .time_col, active = "data")
new_spacetime(.data, .geometry, .loc_col, .time_col, active = "data")
validate_spacetime(.data, .geometry, .loc_col, .time_col)
is_spacetime(x, ...)
is.spacetime(x, ...)
Arguments
.data |
an object with base class |
.geometry |
an |
.loc_col |
the quoted name of the column containing unique location identifiers. Must be present in both |
.time_col |
the quoted name of the column containing time periods must be present |
active |
default |
x |
an object to test |
... |
unused |
Details
Create a spacetime representation of vector data from a data.frame and an
sf object with spacetime()
.time_col must be able to be sorted. As such, .time_col
cannot be a character vector. It must have a base type of (typeof()) either
double or integer—the case in dates or factors respectively. An edge case
exists with POSIXlt class objects as these can be sorted appropriately but
have a base type of list.
spacetime() is a wrapper around new_spacetime(). Spacetimes are
validated before creation with validate_spacetime().
Check if an object is a spacetime object with is_spacetime() or
is.spacetime().
Value
-
spacetime()andnew_spacetime()construct spacetime clss objects -
validate_spacetime()returns nothing but will elicit a warning or error if the spacetime object is not validly constructed -
is_spacetime()andis.spacetime()return a logical scalar indicating if an object inherits the spacetime class
Validation
validate_spacetime() checks both .data and .geometry to ensure that
the constructed spacetime object meets minimum requirements.:
-
.datainherits thedata.frameclass -
.geometryis ansfobject ensures that
.time_colis of the proper classensures there are no missing geometries in
.geometrychecks for duplicate geometries
ensures
.loc_colare the same type in.dataand.geometrylastly informs of missing values in additional columns in
.data
Examples
df_fp <- system.file("extdata", "bos-ecometric.csv", package = "sfdep")
geo_fp <- system.file("extdata", "bos-ecometric.geojson", package = "sfdep")
# read in data
df <- read.csv(
df_fp, colClasses = c("character", "character", "integer", "double", "Date")
)
geo <- sf::st_read(geo_fp)
bos <- spacetime(df, geo, ".region_id", "year")
is_spacetime(bos)
bos