From f24b8a9bd7e5727ebd8e98f34ace75a4a8f79b5a Mon Sep 17 00:00:00 2001 From: Robin Lovelace Date: Thu, 18 Aug 2022 20:25:07 +0100 Subject: [PATCH] No dodgr (#494) --- DESCRIPTION | 3 +- NAMESPACE | 1 - R/route.R | 88 ---------------------------------------------- man/route.Rd | 2 -- man/route_dodgr.Rd | 41 --------------------- man/route_osrm.Rd | 1 - 6 files changed, 1 insertion(+), 135 deletions(-) delete mode 100644 man/route_dodgr.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 17d452ce..5545d19d 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -53,7 +53,6 @@ Imports: sfheaders Suggests: cyclestreets, - dodgr (>= 0.0.3), geodist, igraph (>= 1.2.2), knitr (>= 1.20), @@ -70,5 +69,5 @@ VignetteBuilder: Encoding: UTF-8 LazyData: yes Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.0 +RoxygenNote: 7.2.1 SystemRequirements: GNU make diff --git a/NAMESPACE b/NAMESPACE index f30348ae..e691180a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -91,7 +91,6 @@ export(rnet_get_nodes) export(rnet_group) export(route) export(route_average_gradient) -export(route_dodgr) export(route_google) export(route_nearest_point) export(route_osrm) diff --git a/R/route.R b/R/route.R index d9a2a885..0d5cde2f 100644 --- a/R/route.R +++ b/R/route.R @@ -157,91 +157,3 @@ most_common_class_of_list <- function(l, class_to_find = "sf") { is_class <- class_out == class_to_find is_class } -#' Route on local data using the dodgr package -#' -#' @inheritParams route -#' @param net sf object representing the route network -#' @family routes -#' @export -#' @examples -#' if (requireNamespace("dodgr")) { -#' from <- c(-1.5327, 53.8006) # from <- geo_code("pedallers arms leeds") -#' to <- c(-1.5279, 53.8044) # to <- geo_code("gzing") -#' # next 4 lines were used to generate `stplanr::osm_net_example` -#' # pts <- rbind(from, to) -#' # colnames(pts) <- c("X", "Y") -#' # net <- dodgr::dodgr_streetnet(pts = pts, expand = 0.1) -#' # osm_net_example <- net[c("highway", "name", "lanes", "maxspeed")] -#' r <- route_dodgr(from, to, net = osm_net_example) -#' plot(osm_net_example$geometry) -#' plot(r$geometry, add = TRUE, col = "red", lwd = 5) -#' } -route_dodgr <- function(from = NULL, - to = NULL, - l = NULL, - net = NULL - # , - # return_net = FALSE -) { - if (!requireNamespace("dodgr", quietly = TRUE)) { - stop("dodgr must be installed for this function to work.") - } - od_coordinate_matrix <- od_coords(from, to, l) - to_coords <- od_coordinate_matrix[, 3:4, drop = FALSE] - fm_coords <- od_coordinate_matrix[, 1:2, drop = FALSE] - # Try to get route network if net not provided - if (is.null(net)) { - pts <- rbind(fm_coords, to_coords) - net <- dodgr::dodgr_streetnet(pts = pts, expand = 0.2) - message("Network not provided, fetching network using dodgr_streetnet") - } - - ckh <- dodgr::dodgr_cache_off() - suppressMessages( - ways_dg <- dodgr::weight_streetnet(net) - ) - - verts <- dodgr::dodgr_vertices(ways_dg) # the vertices or points for routing - # suppressMessages ({ - from_id <- unique(verts$id[dodgr::match_pts_to_graph(verts, fm_coords, - connected = TRUE - )]) - to_id <- unique(verts$id[dodgr::match_pts_to_graph(verts, to_coords, - connected = TRUE - )]) - # }) - dp <- dodgr::dodgr_paths(ways_dg, from = from_id, to = to_id) - paths <- lapply(dp, function(i) { - lapply(i, function(j) { - if (is.null(j)) { - return(NULL) - } - res <- verts[match(j, verts$id), c("x", "y")] - sf::st_linestring(as.matrix(res)) - }) - }) - nms <- as.character(unlist(lapply(paths, function(i) names(i)))) - from_to <- do.call(rbind, strsplit(nms, "-")) - from_xy <- fm_coords[match(from_to[, 1], unique(from_to[, 1])), , drop = FALSE] - to_xy <- fm_coords[match(from_to[, 2], unique(from_to[, 2])), , drop = FALSE] - - # remove any NULL paths: - paths <- unlist(paths, recursive = FALSE) - index <- which(vapply(paths, is.null, logical(1))) - if (any(index)) { - message("unable to trace ", length(index), " path(s)") - message("Failed path index numbers are:") - message(list(as.integer(index))) - } - index <- which(!seq(paths) %in% index) - paths <- sf::st_sfc(paths[index], crs = 4326) - sf::st_sf( - from = from_to[index, 1], - from_x = from_xy [index, 1], - from_y = from_xy [index, 2], - to = from_to[index, 2], - to_x = to_xy [index, 1], - to_y = to_xy [index, 2], - geometry = paths - ) -} diff --git a/man/route.Rd b/man/route.Rd index 22c47c47..dfc00423 100644 --- a/man/route.Rd +++ b/man/route.Rd @@ -49,11 +49,9 @@ The definition of optimal depends on the routing function used } \seealso{ Other routes: -\code{\link{route_dodgr}()}, \code{\link{route_osrm}()} Other routes: -\code{\link{route_dodgr}()}, \code{\link{route_osrm}()} } \concept{routes} diff --git a/man/route_dodgr.Rd b/man/route_dodgr.Rd deleted file mode 100644 index 6e69683b..00000000 --- a/man/route_dodgr.Rd +++ /dev/null @@ -1,41 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/route.R -\name{route_dodgr} -\alias{route_dodgr} -\title{Route on local data using the dodgr package} -\usage{ -route_dodgr(from = NULL, to = NULL, l = NULL, net = NULL) -} -\arguments{ -\item{from}{An object representing origins -(if lines are provided as the first argument, from is assigned to \code{l})} - -\item{to}{An object representing destinations} - -\item{l}{A spatial (linestring) object} - -\item{net}{sf object representing the route network} -} -\description{ -Route on local data using the dodgr package -} -\examples{ -if (requireNamespace("dodgr")) { - from <- c(-1.5327, 53.8006) # from <- geo_code("pedallers arms leeds") - to <- c(-1.5279, 53.8044) # to <- geo_code("gzing") - # next 4 lines were used to generate `stplanr::osm_net_example` - # pts <- rbind(from, to) - # colnames(pts) <- c("X", "Y") - # net <- dodgr::dodgr_streetnet(pts = pts, expand = 0.1) - # osm_net_example <- net[c("highway", "name", "lanes", "maxspeed")] - r <- route_dodgr(from, to, net = osm_net_example) - plot(osm_net_example$geometry) - plot(r$geometry, add = TRUE, col = "red", lwd = 5) -} -} -\seealso{ -Other routes: -\code{\link{route_osrm}()}, -\code{\link{route}()} -} -\concept{routes} diff --git a/man/route_osrm.Rd b/man/route_osrm.Rd index 1a4cf277..d614978a 100644 --- a/man/route_osrm.Rd +++ b/man/route_osrm.Rd @@ -51,7 +51,6 @@ slower R interface to OSRM routing services compared with the excellent } \seealso{ Other routes: -\code{\link{route_dodgr}()}, \code{\link{route}()} } \concept{routes}