st_as_sftime | R Documentation |
sftime
objectConvert a foreign object to an sftime
object
st_as_sftime(x, ...) ## S3 method for class 'ST' st_as_sftime(x, ...) ## S3 method for class 'Track' st_as_sftime(x, ...) ## S3 method for class 'Tracks' st_as_sftime(x, ...) ## S3 method for class 'TracksCollection' st_as_sftime(x, ...) ## S3 method for class 'sftime' st_as_sftime(x, ...) ## S3 method for class 'sf' st_as_sftime(x, ..., time_column_name = NULL) ## S3 method for class 'stars' st_as_sftime(x, ..., long = TRUE, time_column_name = NULL) ## S3 method for class 'data.frame' st_as_sftime( x, ..., agr = NA_agr_, coords, wkt, dim = "XYZ", remove = TRUE, na.fail = TRUE, sf_column_name = NULL, time_column_name = NULL, time_column_last = FALSE )
x |
An object to be converted into an object of class
|
... |
Further arguments passed to methods. |
time_column_name |
A character value; name of the active time column. In
case there is more than one and |
long |
A logical value; See |
agr |
A character vector; see details section of |
coords |
In case of point data: names or numbers of the numeric columns holding coordinates. |
wkt |
The name or number of the character column that holds WKT encoded geometries. |
dim |
Passed on to |
remove |
A logical value; when |
na.fail |
A logical value; if |
sf_column_name |
A character value; name of the active list-column with
simple feature geometries; in case there is more than one and
|
time_column_last |
A logical value; if |
x
converted to an sftime
object.
st_as_sftime.Tracks
furthermore adds a column
track_name
with the names of the tracks
slot of the input
Tracks
object.
st_as_sftime.TracksCollection
furthermore adds the columns
tracks_name
with the names of the tracksCollection
slot and
track_name
with the names of the tracks
slot of the input
Tracks
object.
# modified from spacetime: library(sp) library(spacetime) sp <- cbind(x = c(0,0,1), y = c(0,1,1)) row.names(sp) <- paste("point", 1:nrow(sp), sep="") sp <- SpatialPoints(sp) time <- as.POSIXct("2010-08-05") + 3600 * (10:12) x <- STI(sp, time) st_as_sftime(x) # convert a Track object from package trajectories to an sftime object library(trajectories) x1_Track <- trajectories::rTrack(n = 100) x1_Track@data$speed <- sort(rnorm(length(x1_Track))) x1_sftime <- st_as_sftime(x1_Track) # convert a Tracks object from package trajectories to an sftime object x2_Tracks <- trajectories::rTracks(m = 6) x2_sftime <- st_as_sftime(x2_Tracks) # convert a TracksCollection object from package trajectories to an sftime object x3_TracksCollection <- trajectories::rTracksCollection(p = 2, m = 3, n = 50) x3_sftime <- st_as_sftime(x3_TracksCollection) # convert an sftime object to an sftime object st_as_sftime(x3_sftime) # convert an sf object to an sftime object g <- st_sfc(st_point(c(1, 2)), st_point(c(1, 3)), st_point(c(2, 3)), st_point(c(2, 1)), st_point(c(3, 1))) x4_sf <- st_sf(a = 1:5, g, time = Sys.time() + 1:5) x4_sftime <- st_as_sftime(x4_sf) # convert a Tracks object from package trajectories to an sftime object x5_stars <- stars::read_stars(system.file("nc/bcsd_obs_1999.nc", package = "stars")) x5_sftime <- st_as_sftime(x5_stars, time_column_name = "time") # this requires some thought to not accidentally drop time dimensions. For # example, setting `merge = TRUE` will drop the time dimension and thus throw # an error: ## Not run: x5_sftime <- st_as_sftime(x5_stars, merge = TRUE, time_column_name = "time") ## End(Not run) # convert a data frame to an sftime object x5_df <- data.frame(a = 1:5, g, time = Sys.time() + 1:5, stringsAsFactors = FALSE) x5_sftime <- st_as_sftime(x5_df)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.