Skip to content

Commit

Permalink
More for #332
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Apr 3, 2022
1 parent fa2ea0c commit 41b20d3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
5 changes: 0 additions & 5 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,10 @@ S3method(geo_bb,sf)
S3method(geo_bb_matrix,matrix)
S3method(geo_bb_matrix,numeric)
S3method(geo_bb_matrix,sf)
S3method(geo_buffer,Spatial)
S3method(geo_buffer,sf)
S3method(geo_buffer,sfc)
S3method(geo_length,Spatial)
S3method(geo_length,sf)
S3method(geo_projected,Spatial)
S3method(geo_projected,sf)
S3method(geo_select_aeq,Spatial)
S3method(geo_select_aeq,sf)
S3method(geo_select_aeq,sfc)
S3method(geo_toptail,Spatial)
Expand Down Expand Up @@ -75,7 +71,6 @@ export(geo_length)
export(geo_projected)
export(geo_select_aeq)
export(geo_toptail)
export(gprojected)
export(gsection)
export(is_linepoint)
export(islines)
Expand Down
50 changes: 0 additions & 50 deletions R/geo_projected.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ geo_select_aeq <- function(shp) {
UseMethod("geo_select_aeq")
}
#' @export
geo_select_aeq.Spatial <- function(shp) {
cent <- rgeos::gCentroid(shp)
aeqd <- sprintf(
"+proj=aeqd +lat_0=%s +lon_0=%s +x_0=0 +y_0=0",
cent@coords[[2]], cent@coords[[1]]
)
sp::CRS(aeqd)
}
#' @export
geo_select_aeq.sf <- function(shp) {
cent <- sf::st_geometry(shp)
coords <- sf::st_coordinates(shp)
Expand All @@ -51,7 +42,6 @@ geo_select_aeq.sfc <- function(shp) {
sf::st_crs(aeqd)
}


#' Perform GIS functions on a temporary, projected version of a spatial object
#'
#' This function performs operations on projected data.
Expand Down Expand Up @@ -108,36 +98,6 @@ geo_projected.sfc <- function(shp, fun, crs = geo_select_aeq(shp), silent = TRUE
}
res
}
#' @export
geo_projected.Spatial <- 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(sp::is.projected(shp))) {
if (sp::is.projected(shp)) {
res <- fun(shp, ...)
} else {
shp_projected <- reproject(shp, crs = crs)
if (!silent) {
message(paste0("Running function on a temporary projection: ", crs))
}
res <- fun(shp_projected, ...)
if (is(res, "Spatial")) {
res <- sp::spTransform(res, sp::CRS("+init=epsg:4326"))
}
}
} else {
shp_projected <- reproject(shp, crs = crs)
if (!silent) {
message(paste0("Running function on a temporary projection: ", crs$proj4string))
}
res <- fun(shp_projected, ...)
if (is(res, "Spatial")) {
res <- sp::spTransform(res, sp::CRS("+init=epsg:4326"))
}
}
res
}
#' @export
gprojected <- geo_projected.Spatial
#' Perform a buffer operation on a temporary projected CRS
#'
#' This function solves the problem that buffers will not be circular when used on
Expand Down Expand Up @@ -177,10 +137,6 @@ geo_buffer.sfc <- function(shp, ...) {
geo_projected(shp, sf::st_buffer, ...)
}

#' @export
geo_buffer.Spatial <- function(shp, ...) {
geo_projected.Spatial(shp = shp, fun = rgeos::gBuffer, ...)
}
#' Calculate line length of line with geographic or projected CRS
#'
#' Takes a line (represented in sf or sp classes)
Expand All @@ -207,9 +163,3 @@ geo_length.sf <- function(shp) {
}
as.numeric(l)
}

#' @export
geo_length.Spatial <- function(shp) {
shp <- sf::st_as_sf(shp)
geo_length(shp)
}

0 comments on commit 41b20d3

Please sign in to comment.