Skip to content

Commit

Permalink
Use od_dissaggrate backend for #39
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Dec 5, 2021
1 parent 4b6a3e2 commit 021b53c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
20 changes: 16 additions & 4 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 @@ -69,17 +73,25 @@ od_jitter = function(
subpoints = NULL,
code_append = "_ag",
population_column = 3,
max_per_od = 5,
max_per_od = 100000,
keep_ids = TRUE,
integer_outputs = FALSE,
# od_jitter-specific arguments (and zd)
subpoints_o = NULL,
subpoints_d = 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)
Expand Down
14 changes: 10 additions & 4 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 021b53c

Please sign in to comment.