Skip to content

Commit

Permalink
Reproject result of elevation_get() for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Sep 3, 2021
1 parent fbe5740 commit 4476a38
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 14 additions & 8 deletions R/slope_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#' [README](https://github.com/hypertidy/ceramic#local-caching-of-tiles).
#'
#' @param ... Options passed to `cc_elevation()`
#' @param output_format What format to return the data in?
#' Accepts `"raster"` (the default) and `"terra"`.
#' @inheritParams slope_raster
#' @return A raster object with cell values representing elevations in the
#' bounding box of the input `routes` object.
Expand All @@ -27,11 +29,12 @@
#' routes = cyclestreets_route
#' e = elevation_get(routes)
#' class(e)
#' crs(e)
#' e
#' plot(e)
#' plot(st_geometry(routes), add = TRUE)
#' }
elevation_get = function(routes, ...) {
elevation_get = function(routes, ..., output_format = "raster") {
if(requireNamespace("ceramic")) {
mid_ext = sf_mid_ext_lonlat(routes)
bw = max(c(mid_ext$width, mid_ext$height)) / 1 # buffer width
Expand All @@ -41,13 +44,16 @@ elevation_get = function(routes, ...) {
} else {
message("Install the package ceramic")
}
# issue: cannot convert CRS currently
# cr = sf::st_crs(routes)
# cr$wkt
# raster::crs(e) = raster::crs("+init=epsg:3857")
# raster::projectRaster(e, "+init=epsg:4326")
# raster::projectRaster(e, sf::st_crs(routes)[[2]])
e
crs_routes = sf::st_crs(routes)
if(!requireNamespace("terra", quietly = TRUE)) {
message('install.packages("terra") # for this to work')
}
et = terra::rast(e)
res = terra::project(et, y = crs_routes$wkt)
if(output_format == "raster") {
res = raster::raster(res)
}
res
}

sf_mid_ext_lonlat = function(routes) {
Expand Down
6 changes: 5 additions & 1 deletion man/elevation_get.Rd

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

0 comments on commit 4476a38

Please sign in to comment.