Skip to content

Commit

Permalink
return coords of pts from match_pts_to_graph for #103
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed May 8, 2023
1 parent 919501e commit cb9a833
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: dodgr
Title: Distances on Directed Graphs
Version: 0.2.20.022
Version: 0.2.20.023
Authors@R: c(
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre")),
person("Andreas", "Petutschnig", role = "aut"),
Expand Down
15 changes: 8 additions & 7 deletions R/match-points.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,24 @@ pre_process_xy <- function (xy) {
#' @param graph A `dodgr` graph with spatial coordinates, such as a
#' `dodgr_streetnet` object.
#' @param distances If `TRUE`, return a 'data.frame' object with 'index' column
#' as described in return value; and additional 'dist' column with perpendicular
#' distance to nearest edge in graph. See description of return value for
#' details.
#' as described in return value; and additional columns with perpendicular
#' distance to nearest edge in graph, and coordinates of points of intersection.
#' See description of return value for details.
#' @inheritParams match_pts_to_verts
#'
#' @return For `distances = FALSE` (default), a vector index matching the `xy`
#' coordinates to nearest edges. For bi-directional edges, only one match is
#' returned, and it is up to the user to identify and suitably process matching
#' edge pairs. For 'distances = TRUE', a 'data.frame' of two columns:
#' edge pairs. For 'distances = TRUE', a 'data.frame' of four columns:
#' \itemize{
#' \item "index" The index of closest edges in "graph", as described above.
#' \item "d_signed" The perpendicular distance from ech point to the nearest
#' edge, with negative distances denoting points to the left of edges, and
#' positive distances denoting points to the right. Distances of zero denote
#' points lying precisely on the line of an edge (potentially including cases
#' where nearest point of bisection lies beyond the actual edge).
#' \item "x" The x-coordinate of the point of intersection.
#' \item "y" The y-coordinate of the point of intersection.
#' }
#' @family match
#' @export
Expand Down Expand Up @@ -171,7 +173,7 @@ match_pts_to_graph <- function (graph, xy,
if (distances) {
ret <- data.frame (
index = graph_index,
d_signed = signed_intersection_dists (graph, xy, res)
signed_intersection_dists (graph, xy, res)
)
} else {
ret <- graph_index
Expand Down Expand Up @@ -202,7 +204,6 @@ signed_intersection_dists <- function (graph, xy, res) {
# rcpp_points_index is 0-indexed, so ...
graph_index <- as.integer (res [index]) + 1L

# coordinates not yet used here; see #103
xy_intersect <- data.frame (
x = res [index + nrow (xy)],
y = res [index + 2L * nrow (xy)]
Expand All @@ -224,7 +225,7 @@ signed_intersection_dists <- function (graph, xy, res) {
which_side [which_side < 0.0] <- -1
which_side [which_side > 0.0] <- 1

return (d * which_side)
return (cbind (d_signed = d * which_side, xy_intersect))
}

#' Insert new nodes into a graph, breaking edges at point of nearest
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ATFutures/dodgr",
"issueTracker": "https://github.com/ATFutures/dodgr/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.2.20.022",
"version": "0.2.20.023",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
4 changes: 3 additions & 1 deletion man/match_points_to_graph.Rd

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

10 changes: 6 additions & 4 deletions man/match_pts_to_graph.Rd

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

4 changes: 2 additions & 2 deletions tests/testthat/test-match-pts-fns.R
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ test_that ("match with distances", {
res <- match_pts_to_graph (graph0, xy, distances = TRUE)
)
expect_s3_class (res, "data.frame")
expect_equal (ncol (res), 2L)
expect_identical (names (res), c ("index", "d_signed"))
expect_equal (ncol (res), 4L)
expect_identical (names (res), c ("index", "d_signed", "x", "y"))
expect_true (length (which (res$d_signed < 0)) > 0L)
expect_true (length (which (res$d_signed > 0)) > 0L)
expect_true (length (which (res$d_signed == 0)) > 0L)
Expand Down

0 comments on commit cb9a833

Please sign in to comment.