Skip to content

Commit

Permalink
Use library(sf) in examples for #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Sep 3, 2021
1 parent cb0e2e5 commit e854cb4
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 16 deletions.
3 changes: 2 additions & 1 deletion R/plot_slope.R
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ plot_slope = function(
#' @param z Elevations at points across a linestring
#' @inherit plot_slope
#' @examples
#' library(sf)
#' route_xyz = lisbon_road_segment_3d
#' m = sf::st_coordinates(route_xyz)
#' m = st_coordinates(route_xyz)
#' d = cumsum(sequential_dist(m, lonlat = FALSE))
#' d = c(0, d)
#' z = m[, 3]
Expand Down
2 changes: 1 addition & 1 deletion R/slope_get.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#' class(e)
#' e
#' plot(e)
#' plot(sf::st_geometry(routes), add = TRUE)
#' plot(st_geometry(routes), add = TRUE)
#' }
elevation_get = function(routes, ...) {
if(requireNamespace("ceramic")) {
Expand Down
14 changes: 9 additions & 5 deletions R/slopes.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
#' x = c(0, 2, 3, 4, 5, 9)
#' elevations = c(1, 2, 2, 4, 3, 0) / 10 # downward slope overall
#' slope_vector(x, elevations)
#' m = sf::st_coordinates(lisbon_road_segment)
#' library(sf)
#' m = st_coordinates(lisbon_road_segment)
#' d = sequential_dist(m, lonlat = FALSE)
#' elevations = elevation_extract(m, dem_lisbon_raster)
#' slope_distance(d, elevations)
Expand Down Expand Up @@ -226,7 +227,9 @@ slope_matrices = function(m_xyz_split, fun = slope_matrix_weighted, ...) {
#' (s = slope_raster(routes, dem))
#' cor(routes$Avg_Slope, s)
#' slope_raster(routes, dem, directed = TRUE)
#' slope_raster(sf::st_reverse(routes), dem, directed = TRUE)
#' # Demonstrate that reverse routes have the opposite directed slope
#' library(sf)
#' slope_raster(st_reverse(routes), dem, directed = TRUE)
slope_raster = function(
routes,
dem,
Expand Down Expand Up @@ -381,9 +384,10 @@ elevation_extract = function(
#' routes = lisbon_road_network[204, ]
#' dem = dem_lisbon_raster
#' (r3d = elevation_add(routes, dem))
#' sf::st_z_range(routes)
#' sf::st_z_range(r3d)
#' plot(sf::st_coordinates(r3d)[, 3])
#' library(sf)
#' st_z_range(routes)
#' st_z_range(r3d)
#' plot(st_coordinates(r3d)[, 3])
#' plot_slope(r3d)
#' \donttest{
#' # Get elevation data (requires internet connection and API key):
Expand Down
2 changes: 1 addition & 1 deletion R/z.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#' @export
#' @examples
#' x = slopes::lisbon_route_3d
#' sf::st_geometry(x)
#' x
#' z_value(x)[1:5]
#' xy = slopes::lisbon_route
#' try(z_value(xy)) # error message
Expand Down
7 changes: 4 additions & 3 deletions man/elevation_add.Rd

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

2 changes: 1 addition & 1 deletion man/elevation_get.Rd

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

3 changes: 2 additions & 1 deletion man/plot_dz.Rd

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

4 changes: 3 additions & 1 deletion man/slope_raster.Rd

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

3 changes: 2 additions & 1 deletion man/slope_vector.Rd

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

2 changes: 1 addition & 1 deletion man/z_value.Rd

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

0 comments on commit e854cb4

Please sign in to comment.