Skip to content

Commit

Permalink
Fix #450
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Nov 28, 2020
1 parent 902ccc0 commit fac562c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export(quadrant)
export(read_table_builder)
export(reproject)
export(rnet_add_node)
export(rnet_boundary_df)
export(rnet_boundary_points)
export(rnet_boundary_points_lwgeom)
export(rnet_boundary_unique)
Expand Down
30 changes: 19 additions & 11 deletions R/rnet_boundary_points.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,33 @@
#' if(has_sfheaders) {
#' rnet <- rnet_roundabout
#' bp1 <- rnet_boundary_points(rnet)
#' bp2 <- rnet_boundary_points_lwgeom(rnet) # slower version with lwgeom
#' bp3 <- line2points(rnet) # slower version with lwgeom
#' bp2 <- line2points(rnet) # slower version with lwgeom
#' bp3 <- rnet_boundary_points_lwgeom(rnet) # slower version with lwgeom
#' bp4 <- rnet_boundary_unique(rnet)
#' nrow(bp1)
#' nrow(bp3)
#' identical(sort(sf::st_coordinates(bp1)), sort(sf::st_coordinates(bp2)))
#' identical(sort(sf::st_coordinates(bp3)), sort(sf::st_coordinates(bp4)))
#' plot(rnet$geometry)
#' plot(bp1, add = TRUE)
#' plot(bp3, add = TRUE)
#' }
rnet_boundary_points <- function(rnet) {
pairs <- rnet_boundary_df(rnet)
pairs_xyz <- pairs[names(pairs) %in% c("x", "y", "z")]
boundary_points <- sfheaders::sf_point(pairs_xyz)
sf::st_crs(boundary_points) <- sf::st_crs(rnet)
boundary_points
}
#' @rdname rnet_boundary_points
#' @export
rnet_boundary_df <- function(rnet) {
stopifnot(requireNamespace("sfheaders", quietly = TRUE))
coordinates <- sfheaders::sf_to_df(rnet)
# names(coordinates) # "sfg_id" "linestring_id" "x" "y"
# head(coordinates)
coordinates <- coordinates[-1]
first_pair <- !duplicated(coordinates[, 1])
last_pair <- !duplicated(coordinates[, 1], fromLast = TRUE)
first_pair <- !duplicated(coordinates[["sfg_id"]])
last_pair <- !duplicated(coordinates[["sfg_id"]], fromLast = TRUE)
idxs <- first_pair | last_pair
pairs <- coordinates[idxs, ]
boundary_points <- sfheaders::sf_point(pairs)
sf::st_crs(boundary_points) <- sf::st_crs(rnet)
boundary_points
pairs
}
#' @rdname rnet_boundary_points
#' @export
Expand Down
13 changes: 10 additions & 3 deletions man/rnet_boundary_points.Rd

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

0 comments on commit fac562c

Please sign in to comment.