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

Respond to rev2 #31

Merged
merged 28 commits into from
Jun 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b0775b4
move Benchmark from readme to a proper vignette
temospena Jun 13, 2021
11e1531
Load bench pkg before running benchmark
Robinlovelace Jun 13, 2021
41f9b1d
Do not run benchmarking code
Robinlovelace Jun 13, 2021
fc13e43
remove benchmark
temospena Jun 13, 2021
a6bf901
Update vigentte title
Robinlovelace Jun 13, 2021
1e8e37f
Merge branch 'rev2' of https://github.com/ITSLeeds/slopes into rev2
temospena Jun 13, 2021
fdc9a48
Rename argument r to routes
Robinlovelace Jun 13, 2021
61ef5b3
Rename r as routes in plotting code
Robinlovelace Jun 13, 2021
6a7dbdd
Merge branch 'rev2' of https://github.com/ITSLeeds/slopes into rev2
temospena Jun 13, 2021
5af6cdd
rename r to routes in README
temospena Jun 13, 2021
988fa38
Update slope_get with routes not r...
Robinlovelace Jun 13, 2021
f407629
Update without browser()
Robinlovelace Jun 13, 2021
aecd734
Update without and rs!
Robinlovelace Jun 13, 2021
930c35e
update parameter in README
temospena Jun 13, 2021
8f89c3d
replace e for elevations (values) and e for dem (raster)
temospena Jun 13, 2021
fdfb3e3
remane e to dem in README
temospena Jun 13, 2021
915168c
Make xyz
Robinlovelace Jun 13, 2021
22b5dc3
Merge branch 'rev2' of github.com:itsleeds/slopes into rev2
Robinlovelace Jun 13, 2021
fbe66fc
Update lonlat argument settings
Robinlovelace Jun 13, 2021
f8db428
Do not export plot_dz()
Robinlovelace Jun 13, 2021
a9335bb
create vignette for example with Isle of Wight
temospena Jun 13, 2021
27bc145
Dont run unexported function (plot_dz)
Robinlovelace Jun 13, 2021
196f27c
Suggest osmextract
Robinlovelace Jun 13, 2021
1942e94
Update without evaluating interactive map
Robinlovelace Jun 13, 2021
18e4950
Add stplanr and dplyr as Suggests
Robinlovelace Jun 13, 2021
fd19706
add rgdal to description and rebuild
temospena Jun 14, 2021
eb434d5
Import (dont just Suggest) pbapply - see #32
Robinlovelace Jun 21, 2021
03a963b
update slides
Robinlovelace Jun 21, 2021
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
10 changes: 7 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,23 @@ RoxygenNote: 7.1.1
Imports:
sf,
raster,
methods
methods,
pbapply
Depends:
R (>= 2.10)
Suggests:
geodist,
pbapply,
terra,
colorspace,
knitr,
rmarkdown,
ceramic,
bookdown,
covr,
testthat
testthat,
osmextract,
stplanr,
dplyr,
rgdal
VignetteBuilder: knitr
Config/testthat/edition: 3
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

export(elevation_extract)
export(elevations_get)
export(plot_dz)
export(plot_slope)
export(sequential_dist)
export(slope_3d)
Expand Down
34 changes: 14 additions & 20 deletions R/plot_slope.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#' Plot slope data for a 3d linestring with base R graphics
#'
#' @param r A linestring with xyz dimensions
#' @inheritParams slope_raster
#' @inheritParams plot_dz
#' @inheritParams sequential_dist
#'
#' @export
#' @examples
#' plot_slope(lisbon_route_3d)
#' r = lisbon_road_segment_3d
#' plot_slope(r)
#' r = lisbon_road_segment_3d
plot_slope = function(r,
lonlat = sf::st_is_longlat(r),
#' routes = lisbon_road_segment_3d
#' plot_slope(routes)
#' routes = lisbon_road_segment_3d
plot_slope = function(routes,
lonlat = sf::st_is_longlat(routes),
fill = TRUE,
horiz = FALSE,
p = ifelse(
Expand All @@ -27,7 +27,7 @@ plot_slope = function(r,
title = "Slope colors (percentage gradient)",
s = 3:18,
ncol = 4) {
dz = distance_z(r, lonlat = lonlat)
dz = distance_z(routes, lonlat = lonlat)
plot_dz(dz$d, dz$z, fill = fill)
}
#' Plot a digital elevation profile based on xyz data
Expand All @@ -48,14 +48,14 @@ plot_slope = function(r,
#' @param ncol Number of columns in legend
#' @param horiz Should the legend be horizontal (`FALSE` by default)
#' @param ... Additional parameters to pass to legend
#' @export
#' @examples
#' r = lisbon_road_segment_3d
#' m = sf::st_coordinates(r)
#' routes = lisbon_road_segment_3d
#' m = sf::st_coordinates(routes)
#' d = cumsum(sequential_dist(m, lonlat = FALSE))
#' d = c(0, d)
#' z = m[, 3]
#' plot_dz(d, z)
#' # not exported
#' # plot_dz(d, z)
plot_dz = function(d,
z,
fill = TRUE,
Expand All @@ -78,7 +78,7 @@ plot_dz = function(d,
if (fill) {
b = make_breaks(brks)
pal = make_pal(p, b)
g = slope_vector(x = d, e = z)
g = slope_vector(x = d, elevations = z)
colz = make_colz(g, b, pal)
lapply(seq(d)[-(length(d))], function(i) {
graphics::polygon(
Expand All @@ -95,15 +95,9 @@ plot_dz = function(d,
ncol = ncol, cex = cex)
}
}
# g = slope_matrix(m)
# abline(h = 0, lty = 2)
# points(x[-length(x)], gx, col = "red")
# points(x[-length(x)], gxy, col = "blue")
# title("Distance (in x coordinates) elevation profile",
# sub = "Points show calculated gradients of subsequent lines")

distance_z = function(r, lonlat) {
m = sf::st_coordinates(r)
distance_z = function(routes, lonlat) {
m = sf::st_coordinates(routes)
d = cumsum(sequential_dist(m, lonlat = lonlat))
d = c(0, d)
z = m[, 3]
Expand Down
31 changes: 11 additions & 20 deletions R/slope_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,35 @@
#' @examples
#' # time-consuming, and see
#' # https://github.com/ITSLeeds/slopes/runs/648128378#step:18:107
#' r = cyclestreets_route
#' # e = elevations_get(r)
#' routes = cyclestreets_route
#' # e = elevations_get(routes)
#' # class(e)
#' # e
#' # plot(e)
#' # plot(sf::st_geometry(r), add = TRUE)
elevations_get = function(r, file = NULL, ...) {
#' # plot(sf::st_geometry(routes), add = TRUE)
elevations_get = function(routes, file = NULL, ...) {
if(requireNamespace("ceramic")) {
mid_ext = sf_mid_ext_lonlat(r)
mid_ext = sf_mid_ext_lonlat(routes)
bw = max(c(mid_ext$width, mid_ext$height)) / 1 # buffer width
e = ceramic::cc_elevation(loc = mid_ext$midpoint, buffer = bw, ...)
} else {
message("Install the package ceramic")
}
# issue: cannot convert CRS currently
# cr = sf::st_crs(r)
# 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(r)[[2]])
# raster::projectRaster(e, sf::st_crs(routes)[[2]])
e
}
#
# trace_projected = sf::st_transform(trace, 3857)
# plot(e)
# plot(trace_projected$geometry, add = TRUE)
#
# # aim: get max distance from centrepoint
# bb = sf::st_bbox(sf::st_transform(trace, 4326))

# # max of those 2 and divide by 2

sf_mid_ext_lonlat = function(r) {
sf_mid_ext_lonlat = function(routes) {
res = list()
if(!sf::st_is_longlat(r)) {
r = sf::st_transform(r, 4326)
if(!sf::st_is_longlat(routes)) {
routes = sf::st_transform(routes, 4326)
}
bb = sf::st_bbox(r)
bb = sf::st_bbox(routes)
res$midpoint = c(mean(c(bb[1], bb[3])), mean(c(bb[2], bb[4])))
res$width = geodist::geodist(c(x = bb[1], y = bb[2]), c(x = bb[3], y = bb[2]))
res$height = geodist::geodist(
Expand Down
Loading