Skip to content

Commit

Permalink
Update json code - see a-b-street/docs#19
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Sep 2, 2021
1 parent deb043c commit c587267
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 58 deletions.
55 changes: 0 additions & 55 deletions R/ab_scenario_activity_test.R

This file was deleted.

22 changes: 22 additions & 0 deletions data-raw/minimal_sf_scenario.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Aim: generate a minimal dataset corresponding to a minimal example scenario
json = jsonlite::read_json("inst/extdata/minimal_scenario2.json")
json_df = jsonlite::read_json("inst/extdata/minimal_scenario.json", simplifyVector = TRUE)
# Try importing the data into abstreet
json_df$people$trips[[1]]
data.table::rbindlist(json_df$people$trips)
trip_data = dplyr::bind_rows(json_df$people$trips, .id = "id")

# code below could be generalised to a json_to_sf() function
linestrings = od::odc_to_sf(cbind(
trip_data$origin$Position$longitude,
trip_data$origin$Position$latitude,
trip_data$destination$Position$longitude,
trip_data$destination$Position$latitude
))
mapview::mapview(linestrings)
od::odc_to_sf()
sf_data =
sf_linestring = sf::st_sf(

)

7 changes: 4 additions & 3 deletions vignettes/activity.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ od = tibble::tribble(
od_sf = od::od_to_sf(od, places_sf)
plot(od_sf["departure"], reset = FALSE, key.pos = 1, lwd = 6:2)
plot(places_sf$geometry, pch = places$name, add = TRUE, cex =2)
mapview::mapview(od_sf["departure"])
```

```{r, eval=FALSE}
Expand All @@ -102,9 +103,9 @@ departure_times = c(
17
)
od_sf$departure = ab_time_normal(hr = departure_times, sd = 0.15, n = length(departure_times))
od_json1 = abstr::ab_json(desire_lines_out = od_sf[1, ], scenario_name = "activity")
od_json2 = abstr::ab_json(desire_lines_out = od_sf[1:2, ], scenario_name = "activity")
od_json = abstr::ab_json(desire_lines_out = od_sf, scenario_name = "activity")
od_json1 = ab_json(desire_lines_out = od_sf[1, ], scenario_name = "activity")
od_json2 = ab_json(desire_lines_out = od_sf[1:2, ], scenario_name = "activity")
od_json = ab_json(desire_lines_out = od_sf, scenario_name = "activity")
```

```{r, results='asis'}
Expand Down

0 comments on commit c587267

Please sign in to comment.