as_spacetime: Cast between 'spacetime' and 'sf' classes

View source: R/spacetime-methods.R

as_sfR Documentation

Cast between spacetime and sf classes

Description

Cast between spacetime and sf classes

Convert sf object to spacetime

Usage

as_sf(x, ...)

as_spacetime(x, .loc_col, .time_col, ...)

## S3 method for class 'sf'
as_spacetime(x, .loc_col, .time_col, ...)

Arguments

x

for sf::st_as_sf() a spacetime object. For as_spacetime() an sf object.

...

arguments passed to merge.

.loc_col

the quoted name of the column containing unique location identifiers.

.time_col

the quoted name of the column containing time periods.

Value

For as_spacetime() returns a spacetime object. For as_sf(), an sf object.

Examples


if (require(dplyr, quietly = TRUE)) {
  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)

  # Create spacetime object called `bos`
  bos <- spacetime(df, geo,
                   .loc_col = ".region_id",
                   .time_col = "time_period")

  as_sf(bos)
  if (require("dplyr", quietly=TRUE)) {
    as_spacetime(as_sf(bos) , ".region_id", "year")
  }
}

sfdep documentation built on Sept. 13, 2024, 5:07 p.m.