ab_json: Convert geographic ('sf') representation of OD data to 'JSON...

View source: R/ab_scenario.R

ab_jsonR Documentation

Convert geographic ('sf') representation of OD data to 'JSON list' structure

Description

This function takes outputs from ab_scenario() and returns a list that can be saved as a JSON file for import into A/B Street.

Usage

ab_json(
  desire_lines,
  mode_column = NULL,
  time_fun = ab_time_normal,
  scenario_name = "test",
  default_purpose = "Work",
  ...
)

Arguments

desire_lines

OD data represented as geographic lines created by ab_scenario().

mode_column

The column name in the desire lines data that contains the mode of transport. "mode_baseline" by default.

time_fun

The function used to calculate departure times. ab_time_normal() by default.

scenario_name

The name of the scenario to appear in A/B Street. The default value is "test", which generates a message to tell you to think of a more imaginative scenario name!

default_purpose

In case a purpose column is not present in the input, or there are missing values in the purpose column, this argument sets the default, fallback purpose, as "Work" by default, reflecting the prevalence of work-based data and thinking in transport models.

...

Additional arguments to pass to ab_json()

Details

Note: the departure time in seconds is multiplied by 10000 on conversion to a .json list object for compatibility with the A/B Street schema.

Value

A list that can be saved as a JSON file with ab_save()

Examples

# Starting with tabular data
od = leeds_od
od[[1]] = c("E02006876")
zones = leeds_zones
ablines = ab_scenario(od, zones = zones)
ab_list = ab_json(ablines, mode_column = "mode", scenario_name = "test")
ab_list$scenario
f = tempfile(fileext = ".json")
ab_save(ab_list, f)
readLines(f)[1:30]

# Starting with JSON data from A/B Street (multiple trips per person)
f = system.file("extdata/minimal_scenario2.json", package = "abstr")
desire_lines = ab_sf(f)
desire_lines
json_list = ab_json(desire_lines)
json_list

a-b-street/abstr documentation built on April 22, 2022, 7:38 p.m.