Skip to content

Commit

Permalink
Add od_disag args to od_jitter for #39 (#40)
Browse files Browse the repository at this point in the history
* Add od_disag args to od_jitter for #39

* Use od_dissaggrate backend for #39
  • Loading branch information
Robinlovelace authored Dec 5, 2021
1 parent 41de756 commit 4109071
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
36 changes: 28 additions & 8 deletions R/jitter.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#' @param zd Zones with ids matching the destination codes in input OD data
#' @param subpoints_o Points within origin zones representing possible destinations
#' @param subpoints_d Points within destination zones representing possible destinations
#' @param disag Should the od_disaggregate function be used as a 'back end' where possible?
#' TRUE by default. See https://github.com/ITSLeeds/od/issues/39.
#' @inheritParams od_disaggregate
#'
#' @return An `sf` data frame
Expand All @@ -21,8 +23,10 @@
#' dlr = od_jitter(od, z) # desire_lines_random
#' desire_lines = od_to_sf(od, z)
#' plot(z$geometry)
#' plot(dlr, add = TRUE, lwd = 3)
#' plot(desire_lines, add = TRUE, lwd = 5)
#' plot(dlr["all"], add = TRUE, lwd = 3)
#' dlr$all
#' desire_lines$all
#' plot(desire_lines["all"], add = TRUE, lwd = 5)
#'
#' # Example showing use of subpoints
#' subpoints_o = sf::st_sample(z, 200)
Expand Down Expand Up @@ -62,20 +66,36 @@
#' # plot(od_sf[od$all > 200, 1])
#' # plot(dlr3[od$all > 200, 1])
#' # mapview::mapview(od_sf$geometry[od$all > 200])
od_jitter = function(od,
z,
zd = NULL,
subpoints_o = NULL,
subpoints_d = NULL) {
od_jitter = function(
od,
z,
zd = NULL,
subpoints = NULL,
code_append = "_ag",
population_column = 3,
max_per_od = 100000,
keep_ids = TRUE,
integer_outputs = FALSE,
# od_jitter-specific arguments (and zd)
subpoints_o = NULL,
subpoints_d = NULL,
disag = TRUE
) {

if (!methods::is(od, "sf")) {
# the data structure to reproduce for matching OD pairs
od = od::od_to_sf(od, z = z, zd = zd)
}
disag = all(is.null(zd), is.null(subpoints_o), is.null(subpoints_d), disag)
if(disag) {
message("Using od_disaggregate") # todo remove once tested
return(od_disaggregate(od, z, subpoints, code_append, population_column,
max_per_od, keep_ids, integer_outputs))
}
odc_new = odc_original = od::od_coordinates(od)
od = sf::st_drop_geometry(od)
odc_df = data.frame(o = od[[1]], d = od[[2]], odc_original)
z_geo = sf::st_geometry(z)
# browser()
id_origins = od[[1]]
points_per_zone = data.frame(table(id_origins))
names(points_per_zone)[1] = names(z)[1]
Expand Down
42 changes: 39 additions & 3 deletions man/od_jitter.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4109071

Please sign in to comment.