This function takes a path to a JSON file representing an A/B Street scenario, or an R representation of the JSON in a list, and returns an sf object with the same structure as objects returned by ab_scenario().

ab_sf(json)

Arguments

json

Character string or list representing a JSON file or list that has been read into R and converted to a data frame.

Value

An sf data frame representing travel behaviour scenarios from, and which can be fed into, A/B Street. Contains the following columns: person (the ID of each agent in the simulation), departure (seconds after midnight of the travel starting), mode (the mode of transport, being Walk, Bike, Transit and Drive), purpose (what the trip was for, e.g. Work), and geometry (a linestring showing the start and end point of the trip/stage).

Details

Note: the departure time in seconds is divided by 10000 on conversion to represent seconds, which are easier to work with that 10,000th of a second units.

Examples

file_name = system.file("extdata/minimal_scenario2.json", package = "abstr")
ab_sf(file_name)
#> Simple feature collection with 4 features and 4 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -122.319 ymin: 47.63728 xmax: -122.3037 ymax: 47.64048
#> Geodetic CRS:  WGS 84
#>   person departure mode    purpose                       geometry
#> 1      1       0.1 Bike       Meal LINESTRING (-122.3037 47.63...
#> 2      1    1000.0 Walk Recreation LINESTRING (-122.3191 47.63...
#> 3      2       1.1 Walk       Meal LINESTRING (-122.3037 47.63...
#> 4      2    1001.0 Bike       Work LINESTRING (-122.3191 47.63...
json = jsonlite::read_json(file_name, simplifyVector = TRUE)
ab_sf(json)
#> Simple feature collection with 4 features and 4 fields
#> Geometry type: LINESTRING
#> Dimension:     XY
#> Bounding box:  xmin: -122.319 ymin: 47.63728 xmax: -122.3037 ymax: 47.64048
#> Geodetic CRS:  WGS 84
#>   person departure mode    purpose                       geometry
#> 1      1       0.1 Bike       Meal LINESTRING (-122.3037 47.63...
#> 2      1    1000.0 Walk Recreation LINESTRING (-122.3191 47.63...
#> 3      2       1.1 Walk       Meal LINESTRING (-122.3037 47.63...
#> 4      2    1001.0 Bike       Work LINESTRING (-122.3191 47.63...