| mt_as_move2 {move2} | R Documentation |
Create a new move2 object
Description
Create a new move2 object from a data.frame, sf, telemetry, telemetry list, track_xyt, Move or MoveStack object
Usage
mt_as_move2(x, ...)
## S3 method for class 'sf'
mt_as_move2(x, time_column, track_id_column, track_attributes = "", ...)
## S3 method for class 'data.frame'
mt_as_move2(x, time_column, track_id_column, track_attributes = "", ...)
## S3 method for class 'track_xyt'
mt_as_move2(x, time_column, track_id_column, track_attributes = "", ...)
## S3 method for class 'telemetry'
mt_as_move2(x, time_column, track_id_column, track_attributes = "", ...)
## S3 method for class 'list'
mt_as_move2(x, time_column, track_id_column, track_attributes = "", ...)
## S3 method for class '.MoveTrack'
mt_as_move2(x, ...)
Arguments
x |
A |
... |
Additional arguments passed to |
time_column |
The name of the column in |
track_id_column |
The name of the column in |
track_attributes |
The name(s) of the column(s) that contain track level attributes |
Details
Frequently used arguments to st_as_sf are:
-
coordsa character vector indicating the columns used as coordinates, the length is generally two, forxandy, but can also be more ifzis included -
sf_column_nameif a geometry column is present the name of the geometry column to use as coordinates as a character scalar -
crsthe coordinate reference system to use, either as character, number or acrsobject for more details seest_crs -
na.failnormally when the coordinate columns are converted to spatial pointsNAvalues cause an error, if set toFALSEempty points are allowed
Value
A move2 object
See Also
Other move2-convert:
to_move()
Examples
## create a move2 object from a data.frame and defining projection
n <- 5
data <- data.frame(
x = cumsum(rnorm(n)), y = cumsum(rnorm(n)),
time = seq(n), track = "a"
)
mt_as_move2(data,
coords = c("x", "y"), time_column = "time",
track_id_column = "track"
) |> sf::st_set_crs(4326L)
## Dealing with empty coordinates:
## If the data frame contains NA coordinates, the coords argument in sf
## will fail. An alternative is to first create an sfc column,
## or to use the na.fail argument
nn <- 3
data <- data.frame(
x = c(cumsum(rnorm(n)), rep(NA, nn)), y = c(cumsum(rnorm(n)), rep(NA, nn)),
time = seq(n + nn), track = "a",
sensor = c(rep("sensor1", n), rep("sensor2", nn)),
sensor2values = c(rep(NA, n), runif(nn))
)
mt_as_move2(data,
coords = c("x", "y"),
na.fail = FALSE,
time_column = "time",
track_id_column = "track"
)
## create a move2 object from a sf object
data$geometry <- sf::st_sfc(apply(data[, c("x", "y")], 1, sf::st_point, simplify = FALSE))
mt_as_move2(data,
sf_column_name = c("geometry"), time_column = "time",
track_id_column = "track"
)