monitor_writeCurrentStatusGeoJSON: Write current monitor data to geojson file

Description Usage Arguments Value Examples

View source: R/monitor_writeCurrentStatusGeoJSON.R

Description

Writes a geoJSON file containing current monitor data. For details on what is included, see monitor_getCurrentStatus.

Usage

1
2
3
4
5
6
7
8
monitor_writeCurrentStatusGeoJSON(
  ws_monitor,
  filename,
  datetime = lubridate::now(tzone = "UTC"),
  properties = NULL,
  propertyNames = NULL,
  metadataList = list()
)

Arguments

ws_monitor

ws_monitor object.

filename

Filename where geojson file will be saved.

datetime

Time to which data will be 'current' (integer or character representing YYYYMMDDHH or POSIXct. If not POSIXct, interpreted as UTC time). So if datetime is 3 hours ago, a dataframe with the most current data from 3 hours ago will be returned.

properties

Optional character vector of properties to include for each monitor in geoJSON. If NULL all are included. May include any ws_monitor metadata and additional columns generated in monitor_getCurrentStatus.

propertyNames

Optional character vector supplying custom names for properties in geoJSON. If NULL or different length than properties defaults will be used.

metadataList

List of top-level foreign members to include. May include nested lists as long as they can be converted into JSON using jsonlite::toJSON(). For more information on what can be included see https://tools.ietf.org/html/rfc7946#section-6.1.

Value

Invisibly returns geoJSON string.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# Fail gracefully if any resources are not available
try({

library(PWFSLSmoke)

wa <-
  monitor_loadLatest() %>%
  monitor_subset(stateCodes = "WA")

geojson_file <- tempfile(fileext = ".geojson")
wa_current_geojson <- monitor_writeCurrentStatusGeoJSON(wa, geojson_file)
wa_current_list <- jsonlite::fromJSON(wa_current_geojson)
wa_spdf <- rgdal::readOGR(dsn = geojson_file)
map("state", "washington")
points(wa_spdf)

}, silent = FALSE)

PWFSLSmoke documentation built on Nov. 23, 2021, 5:06 p.m.