-
Notifications
You must be signed in to change notification settings - Fork 20
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
Slope-sensitive routing #46
Comments
It would be great to add remotes::install_github("itsleeds/slopes")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'slopes' from a github remote, the SHA1 (aaf4d36b) has not changed since last install.
#> Use `force = TRUE` to force installation
library(sfnetworks)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
r = slopes::lisbon_road_segments
e = slopes::dem_lisbon_raster
r$slope = slopes::slope_raster(r, e)
plot(r["slope"]) v = sf::st_coordinates(r)
nrow(v)
#> [1] 4365
set.seed(5)
p = v[sample(nrow(v), size = 10), ]
head(p)
#> X Y L1
#> [1,] -87754.50 -106090.5 253
#> [2,] -87615.91 -105512.5 154
#> [3,] -87388.56 -106119.0 118
#> [4,] -87673.75 -105314.2 84
#> [5,] -87303.96 -105826.8 249
#> [6,] -88268.24 -106002.7 54
psf = sf::st_as_sf(
data.frame(p),
coords = c("X", "Y")
)
l = stplanr::points2line(p = psf)
plot(l) net = as_sfnetwork(r)
net_t = net %>%
activate("edges") %>%
dplyr::mutate(length = sf::st_length(.))
igraph::shortest_paths(graph = net_t, 1, 200)$vpath
#> [[1]]
#> + 13/205 vertices, from ee62bb3:
#> [1] 1 2 3 4 10 11 12 13 19 157 156 199 200 Created on 2020-05-01 by the reprex package (v0.3.0) |
@luukvdmeer There is also code in |
Those links could be useful, thanks for sharing. We found that Also see here re auto-getting elevation data in the common scenario that a DEM data file isn't on your computer - is |
Interesting topic! I am not sure if I understand exactly what you'd like |
Good questions. The first thing I'd like to see is to be able to reproduce the routing code, specifically r_test = stplanr::sum_network_routes(sln = sln, start = 1, end = 9) with igraph::shortest_paths(graph = net_t, 1, 9)$vpath
#> Warning in igraph::shortest_paths(graph = net_t, 1, 9): At
#> structural_properties.c:745 :Couldn't reach some vertices
#> [[1]]
#> + 0/187 vertices, from 05a320d: So in some senses this hack idea isn't so much about slope-sensitive routing as it is about routing and modifying weighting profiles with
|
No, I think the slope-sensitive routing is a very interesting hackathon topic on its own! So that is useful as a hackathon labeled issue. Regarding the example with |
Great, thanks @luukvdmeer. It's certainly an interesting use case that made me delve into |
In the end I found out the issue was not a bug, but a design difference between When changing the Also, when calculating shortest paths with library(sfnetworks)
# Create an sf object with slopes.
r = slopes::lisbon_road_segments
r = stplanr::overline(r, "Avg_Slope")
# Create and clean SpatialLinesNetwork
sln = stplanr::SpatialLinesNetwork(r)
sln = stplanr::sln_clean_graph(sln)
# Convert to undirected sfnetwork
net = as_sfnetwork(sln@sl, directed = FALSE)
activate("edges") %>%
dplyr::mutate(length = sf::st_length(.))
# Shortest path with SpatialLinesNetwork
igraph::shortest_paths(graph = sln@g, 1, 9)$vpath
#> [[1]]
#> + 14/187 vertices, from ed56407:
#> [1] 1 2 44 108 87 60 20 119 52 51 106 8 7 9
# Shortest path with sfnetwork
weights = net %>% activate('edges') %>% dplyr::pull(length)
igraph::shortest_paths(graph = net, 1, 9, weights = weights)$vpath
#> [[1]]
#> + 14/187 vertices, from 8284e6c:
#> [1] 1 2 44 108 87 60 20 119 52 51 106 8 7 9 Findings:
|
Great discoveries @luukvdmeer, agree about the conversion functions. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I have hidden the "directed" discussion (which moved to #50), to keep this clean. @Robinlovelace I was thinking it might also be an option to use the Z-coordinate of a geometry for slope sensitive routing? I have never worked with that, but might be interesting. |
Yes, currently the |
Place where we can put code/data/tests for this: https://github.com/sfnetworks/sloperouting If you want to get involved in this hack let me know and I can add you to the repo! |
cool!
…On Tue, Jun 16, 2020 at 11:52 AM Robin ***@***.***> wrote:
Place where we can put code/data/tests for this:
https://github.com/sfnetworks/sloperouting
If you want to get involved in this hack let me know and I can add you to
the repo!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#46 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJKLUXXFTQVSL55I6FWULS3RW5FHBANCNFSM4MXFHS5Q>
.
|
Great just added you @temospena if anyone else wants to get involved let us know! |
Starting point for the hack topic: library(sfnetworks)
library(tidygraph)
#>
#> Attaching package: 'tidygraph'
#> The following object is masked from 'package:stats':
#>
#> filter
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 7.0.0
r = slopes::lisbon_road_segments
sf::st_is_longlat(r)
#> [1] FALSE
class(r)
#> [1] "sf" "tbl_df" "tbl" "data.frame"
names(r)
#> [1] "OBJECTID" "fid_1" "gradient_s" "Shape_Leng" "Z_Min"
#> [6] "Z_Max" "Z_Mean" "SLength" "Min_Slope" "Max_Slope"
#> [11] "Avg_Slope" "z0" "z1" "gradverifi" "query"
#> [16] "lat" "lon" "lat_min" "lat_max" "lon_min"
#> [21] "lon_max" "bbox" "geom"
plot(r["Avg_Slope"]) net = as_sfnetwork(r)
p1 = net %>%
activate(nodes) %>%
st_as_sf() %>%
slice(1)
p2 = net %>%
activate(nodes) %>%
st_as_sf() %>%
slice(9)
mapview::mapview(p1) + mapview::mapview(p2) path1 = net %>%
activate("edges") %>%
mutate(weight = edge_length()) %>%
convert(to_spatial_shortest_paths, p1, p2)
plot(path1) mapview::mapview(st_as_sf(path1)) +
mapview::mapview(p1) + mapview::mapview(p2) Created on 2020-06-16 by the reprex package (v0.3.0) |
Since the hackathon is now behind us, I will close the hackathon issues. But I look forward to new specific feature request issues that resulted from the hackathon! |
Please describe the problem.
It could be useful to be able to create weighting profiles that are sensitive to the slope, gradient, of route segments encoded as linestrings. I've recently developed a way to quickly estimate the slope of 1000s of routes based on a raster dataset with elevations: https://github.com/ITSLeeds/slopes
It could be a fun hackathon challenge. Heads-up @tempospena and @mpadge.
Describe how you currently solve the problem, or how attempted to solve it
I would like to calculate shortest paths as below, but one that responds to steepness:
Currently I can do routing on a network as follows:
Describe the desired functionality of sfnetworks
A clear and concise description of what functionalities you would like to see in the
sfnetworks
package such that your problem can be solved more conveniently.To be able to incorporate slope in the route estimate in a controlled way. Some demonstration code, showing 3 shortest routes calculated with the
route()
function instplanr
are shown below.Created on 2020-05-02 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: