Learn R Programming

sfdep (version 0.2.5)

as_sf: 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 sf as_spacetime(x, .loc_col, .time_col, ...)

Value

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

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.

Examples

Run this code

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")
  }
}

Run the code above in your browser using DataLab