-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.qmd
147 lines (120 loc) · 3.7 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
---
title: "Demo of od2net"
format: gfm
execute:
message: false
warning: false
---
The in this repo is intended to demonstrate how to use [`od2net`](https://github.com/Urban-Analytics-Technology-Platform/od2net) to generate route networks and to compare the workflow, and results, with the R-based approach currently used in the NPT project.
# od2net minimum example
The following is based on [`od2net`'s docs](https://github.com/Urban-Analytics-Technology-Platform/od2net/blob/main/docs/tutorial_examples.md#running-the-edinburgh-example) and the code in the examples/edinburgh folder.
Setup the files in the input folder as follows:
```{r}
#| eval: false
source("R/setup.R")
main()
```
Run the tool with Docker as follows:
```{bash}
#| eval: false
# Time it:
docker run -v $(pwd):/app ghcr.io/urban-analytics-technology-platform/od2net:main /app/config.json
# Summary:
# - Load network took 100.799767ms
# - Loading origins took 175.604547ms
# - Loading destinations took 174.229604ms
# - Loading zones from /app/input/zones.geojson took 714.082µs
# - Matching points to zones took 54.914894ms
# - Generating requests from /app/input/od.csv took 659.614µs
# - Loading or generating requests took 406.16771ms
# - Building RTree for matching request points to OSM nodes took 16.235263ms
# - Routing took 56.808164ms
# - Writing output CSV took 18.805512ms
# - Writing output GJ took 125.66129ms
# - Converting to pmtiles for rendering took 7.733441909s
# - everything took 8.441747553s
```
```{r}
#| eval: false
#| echo: false
system("docker run -v $(pwd):/app ghcr.io/urban-analytics-technology-platform/od2net:main /app/config.json")
```
After that you should see the following in the output folder:
```{r}
fs::dir_tree("output")
```
## R minimum example
```{r}
library(tidyverse)
od = readr::read_csv("input/od.csv")
zones = sf::read_sf("input/zones.geojson")
desire_lines = od::od_to_sf(od, zones)
```
```{r}
#| eval: false
# Requires API key:
system.time({
routes = cyclestreets::batch(desire_lines, username = "robinlovelace", wait = TRUE)
})
# 133 seconds
rnet = stplanr::overline(routes, attrib = "count")
sf::write_sf(rnet, "output/output-r.geojson")
```
## Comparison
```{r}
output_od2net = sf::read_sf("output/output.geojson")
output_r = sf::read_sf("output/output-r.geojson")
sum(sf::st_length(output_od2net))
sum(sf::st_length(output_r))
names(output_od2net)
names(output_r)
summary(output_od2net$way)
sum(output_od2net$count * sf::st_length(output_od2net), na.rm = TRUE) |>
units::set_units("km")
sum(output_r$count * sf::st_length(output_r), na.rm = TRUE) |>
units::set_units("km")
# Vs flow implied from desire lines (expectation: ~1.3 x this amount):
sum(desire_lines$count * sf::st_length(desire_lines), na.rm = TRUE) |>
units::set_units("km")
```
```{r}
#| label: rnet-basic
output_combined = bind_rows(
output_od2net |>
filter(!is.na(way)) |>
# Only large counts:
filter(count > 5) |>
mutate(source = "od2net"),
output_r |>
mutate(source = "R") |>
filter(count > 5)
)
central_edinburgh = zonebuilder::zb_zone("Edinburgh", n_circles = 2)
output_combined = output_combined |>
sf::st_intersection(central_edinburgh)
output_combined |>
ggplot() +
geom_sf(aes(colour = count)) +
scale_colour_viridis_c() +
facet_wrap(~source) +
theme_void()
```
## Setup
<details>
Run the code on a computer with Ubuntu 22.04 after running the setup outlined in the link above.
```{bash}
#| eval: false
#| echo: false
sudo apt install osmium-tool
```
```{bash}
#| eval: false
gh repo clone Urban-Analytics-Technology-Platform/od2net
# Copy the example to this folder:
cp -r od2net/examples/edinburgh/* .
cp -r od2net/
```
```{bash}
#| eval: false
# Setup quarto-publish:
```