From 021b53c9c79890e51461782ed39d6730b37a6c22 Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Sun, 5 Dec 2021 11:21:03 +0000 Subject: [PATCH] Use od_dissaggrate backend for #39 --- R/jitter.R | 20 ++++++++++++++++---- man/od_jitter.Rd | 14 ++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/R/jitter.R b/R/jitter.R index f4b2ef3..7f24393 100644 --- a/R/jitter.R +++ b/R/jitter.R @@ -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 @@ -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) @@ -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) diff --git a/man/od_jitter.Rd b/man/od_jitter.Rd index d6410f1..631ab0b 100644 --- a/man/od_jitter.Rd +++ b/man/od_jitter.Rd @@ -11,11 +11,12 @@ od_jitter( subpoints = NULL, code_append = "_ag", population_column = 3, - max_per_od = 5, + max_per_od = 1e+05, keep_ids = TRUE, integer_outputs = FALSE, subpoints_o = NULL, - subpoints_d = NULL + subpoints_d = NULL, + disag = TRUE ) } \arguments{ @@ -46,6 +47,9 @@ https://github.com/ITSLeeds/od/issues/31 for details.} \item{subpoints_o}{Points within origin zones representing possible destinations} \item{subpoints_d}{Points within destination zones representing possible destinations} + +\item{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.} } \value{ An \code{sf} data frame @@ -64,8 +68,10 @@ z = od_data_zones_min 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)