R/tracks_as_geojson.R

Defines functions tracks_as_geojson

Documented in tracks_as_geojson

#' Convert tracks to a GeoJSON string
#'
#' \lifecycle{stable}
#'
#' Turns calendar_date_awst (required) into start and end (start + 1 day) dates,
#' converts dataframe to GeoJSON string.
#' @template param-tracks
#' @export
#' @family helpers
tracks_as_geojson <- function(tracks) {
  tracks %>%
    dplyr::mutate(
      start = calendar_date_awst %>% as.Date(),
      end = start + 1
    ) %>%
    geojsonio::geojson_json(
      lat = "observed_at_latitude",
      lon = "observed_at_longitude"
    )
}

# usethis::use_test("tracks_as_geojson")
parksandwildlife/wastdr documentation built on Nov. 17, 2022, 4:52 p.m.