-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.qmd
93 lines (77 loc) · 2.84 KB
/
README.qmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
format: gfm
bibliography: references.bib
---
# overline
Overline is a function that takes overlapping linestrings and converts them into a route network [@morgan2020] as illustrated in a minimal reproducible example below.
```{r, message=FALSE}
library(sf)
library(stplanr)
library(tidyverse)
library(tmap)
sl = routes_fast_sf[2:3, 0]
sl$n = 1:2
plot(sl)
rnet = overline(sl, attrib = "n")
plot(rnet)
sf::write_sf(sl, "minimal-example-input.geojson", delete_dsn = TRUE)
sf::write_sf(rnet, "minimal-example-output.geojson", delete_dsn = TRUE)
```
The function has been implemented in the [`overline()` function](https://docs.ropensci.org/stplanr/reference/overline.html) in the R package `stplanr`. The function works fine for city sized datasets but for national datasets is slow, buggy and not feature complete, as it does not retain OSM IDs. This repo provides a place to discuss and develop example code to solve this problem.
In Python, the input and outputs can be visualised as follows:
```python
import geopandas as gpd
input = gpd.read_file("input.geojson")
input.plot()
```
```python
output = gpd.read_file("output.geojson")
output.plot()
```
![](README_files/figure-commonmark/unnamed-chunk-3-3.png)
# Example with road names
The example below takes routes at the segment level and calculates average gradient for each segment. Road names are NOT currently implemented in `overline()` in R.
```{r}
sl_desire_lines = stplanr::flowlines_sf[2:3, ]
qtm(sl_desire_lines) +
qtm(sl)
route_segments_minimal = stplanr::route(
l = sl_desire_lines,
route_fun = cyclestreets::journey
)
names(route_segments_minimal)
tm_shape(route_segments_minimal) +
tm_lines("name")
rnet_from_cyclestreets = overline(
route_segments_minimal,
attrib = c("All", "gradient_smooth", "quietness"),
fun = c(sum = sum, mean = mean)
)
rnet_from_cyclestreets = rnet_from_cyclestreets %>%
transmute(All = All_sum, Gradient = gradient_smooth_mean, Quietness = quietness_mean)
plot(rnet_from_cyclestreets)
sf::write_sf(route_segments_minimal, "route_segments_minimal.geojson", delete_dsn = TRUE)
sf::write_sf(rnet_from_cyclestreets, "rnet_from_cyclestreets.geojson", delete_dsn = TRUE)
```
# Large example
A large example plus benchmark is shown below:
```{r}
#| eval: false
# list.files()
cycle_routes_london = pct::get_pct_routes_fast("london")
sf::write_sf(cycle_routes_london, "cycle_routes_london.geojson")
zip("cycle_routes_london.zip", "cycle_routes_london.geojson")
system("gh release upload v0 cycle_routes_london.zip")
```
```{r, cache=TRUE}
#| eval: false
system.time({
cycle_routes_london = geojsonsf::geojson_sf("cycle_routes_london.geojson")
names(cycle_routes_london)
rnet = overline(cycle_routes_london, attrib = "foot")
})
# sf::write_sf(rnet, "rnet_london.geojson")
# system("gh release upload v0 rnet_london.geojson")
```
The operation took around 2 minutes.
# References