mt_as_move2: Create a new move2 object

View source: R/new_move.R

mt_as_move2R 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 data.frame, sf, telemetry, telemetry list, track_xyt, Move or MoveStack object

...

Additional arguments passed to st_as_sf if x is a data.frame, see the details below for more information

time_column

The name of the column in x containing timestamps

track_id_column

The name of the column in x containing the track identities

track_attributes

The name(s) of the column(s) that contain track level attributes

Details

Frequently used arguments to st_as_sf are:

  • coords a character vector indicating the columns used as coordinates, the length is generally two, for x and y, but can also be more if z is included

  • sf_column_name if a geometry column is present the name of the geometry column to use as coordinates as a character scalar

  • crs the coordinate reference system to use, either as character, number or a crs object for more details see st_crs

  • na.fail normally when the coordinate columns are converted to spatial points NA values cause an error, if set to FALSE empty 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"
)


move2 documentation built on April 4, 2025, 12:24 a.m.