Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

546 bug in line segment when using certain values on projected data with rsgeo implementation #548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ Imports:
Rcpp (>= 0.12.1),
rlang (>= 0.2.2),
sf (>= 0.6.3),
sfheaders,
vctrs (>= 0.4.0)
sfheaders
Suggests:
cyclestreets,
dodgr (>= 0.2.15),
Expand All @@ -68,9 +67,11 @@ Suggests:
osrm,
pct,
rmarkdown (>= 1.10),
rsgeo (>= 0.1.6),
rsgeo (>= 0.1.6.9000),
testthat (>= 2.0.0),
tmap
Remotes:
JosiahParry/rsgeo
VignetteBuilder:
knitr
Encoding: UTF-8
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ S3method(line2pointsn,sf)
S3method(line2vertices,sf)
S3method(line_segment,sf)
S3method(line_segment,sfc_LINESTRING)
S3method(line_segment1,sf)
S3method(line_segment1,sfc_LINESTRING)
S3method(n_vertices,sf)
S3method(od2line,sf)
S3method(onewaygeo,sf)
Expand Down Expand Up @@ -60,6 +62,7 @@ export(line_breakup)
export(line_cast)
export(line_midpoint)
export(line_segment)
export(line_segment1)
export(line_via)
export(mats2line)
export(n_vertices)
Expand Down
25 changes: 11 additions & 14 deletions R/geo_projected.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ geo_projected.sf <- function(shp, fun, crs = geo_select_aeq(shp), silent = TRUE,
sf::st_crs(shp) <- sf::st_crs(4326)
}
crs_orig <- sf::st_crs(shp)
# If the original CRS is already projected, run the fun() on the original:
if (!is.na(sf::st_crs(shp)) && !sf::st_is_longlat(shp)) {
if (!silent) {
message("Running function on original projection")
}
res <- fun(shp, ...)
return(res)
}
shp_projected <- sf::st_transform(shp, crs)
if (!silent) {
message(paste0("Running function on a temporary projection: ", crs$proj4string))
Expand All @@ -86,20 +94,9 @@ geo_projected.sf <- function(shp, fun, crs = geo_select_aeq(shp), silent = TRUE,
}
#' @export
geo_projected.sfc <- function(shp, fun, crs = geo_select_aeq(shp), silent = TRUE, ...) {
# assume it's not projected (i.e. lat/lon) if there is no CRS
if (is.na(sf::st_crs(shp))) {
sf::st_crs(shp) <- sf::st_crs(4326)
}
crs_orig <- sf::st_crs(shp)
shp_projected <- sf::st_transform(shp, crs)
if (!silent) {
message(paste0("Running function on a temporary projection: ", crs$proj4string))
}
res <- fun(shp_projected, ...)
if (grepl("sf", x = class(res)[1])) {
res <- sf::st_transform(res, crs_orig)
}
res
shp_sf <- sf::st_as_sf(shp)
res <- geo_projected.sf(shp_sf, fun, crs, silent, ...)
sf::st_geometry(res)
}
#' Perform a buffer operation on a temporary projected CRS
#'
Expand Down
Loading