Skip to content

Commit

Permalink
Tidy up and add new input dataset (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Jul 19, 2023
1 parent 31fda4a commit 7d26e4f
Show file tree
Hide file tree
Showing 13 changed files with 205 additions and 111 deletions.
114 changes: 54 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,28 @@

Overline is a function that takes overlapping linestrings and converts
them into a route network (Morgan and Lovelace 2020) as illustrated in a
minimal reproducible example below.
minimal reproducible example created with
[ATIP](https://github.com/acteng/atip/).

``` r
library(sf)
library(stplanr)
library(tidyverse)
library(tmap)
sl = routes_fast_sf[2:3, 0]
sl$n = 1:2
plot(sl)
```
The input is a dataset in which some segments overlap:

![](README_files/figure-commonmark/unnamed-chunk-1-1.png)
Reading layer `minimal_2_lines' from data source
`/home/robin/github/acteng/overline/test-data/minimal_2_lines.txt'
using driver `GeoJSON'
Simple feature collection with 2 features and 5 fields
Geometry type: LINESTRING
Dimension: XY
Bounding box: xmin: -1.29569 ymin: 50.69972 xmax: -1.295337 ymax: 50.69987
Geodetic CRS: WGS 84

``` r
rnet = overline(sl, attrib = "n")
plot(rnet)
```
![](README_files/figure-commonmark/unnamed-chunk-1-1.png)

![](README_files/figure-commonmark/unnamed-chunk-1-2.png)
The output is a dataset in which the overlapping segments have been
combined:

``` r
sf::write_sf(sl, "minimal-example-input.geojson", delete_dsn = TRUE)
sf::write_sf(rnet, "minimal-example-output.geojson", delete_dsn = TRUE)
```
![](README_files/figure-commonmark/unnamed-chunk-2-1.png)

The function has been implemented in the [`overline()`
The functionality 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
Expand All @@ -41,14 +36,19 @@ In Python, the input and outputs can be visualised as follows:
``` python
import geopandas as gpd
input = gpd.read_file("input.geojson")
input.plot()
# Plot with colour by value:
input.plot(column="value")
```

![](README_files/figure-commonmark/unnamed-chunk-3-1.png)

``` python
output = gpd.read_file("output.geojson")
output.plot()
output.plot(column="value")
```

![](README_files/figure-commonmark/unnamed-chunk-4-3.png)

![](README_files/figure-commonmark/unnamed-chunk-3-3.png)

# Example with road names
Expand All @@ -59,13 +59,8 @@ implemented in `overline()` in R.

``` r
sl_desire_lines = stplanr::flowlines_sf[2:3, ]
qtm(sl_desire_lines) +
qtm(sl)
```

![](README_files/figure-commonmark/unnamed-chunk-2-1.png)

``` r
# qtm(sl_desire_lines) +
# qtm(sl)
route_segments_minimal = stplanr::route(
l = sl_desire_lines,
route_fun = cyclestreets::journey
Expand Down Expand Up @@ -98,41 +93,40 @@ names(route_segments_minimal)
[18] "distances"
[19] "time"
[20] "busynance"
[21] "elevations"
[22] "start_longitude"
[23] "start_latitude"
[24] "finish_longitude"
[25] "finish_latitude"
[26] "crow_fly_distance"
[27] "event"
[28] "whence"
[29] "speed"
[30] "itinerary"
[31] "plan"
[32] "note"
[33] "length"
[34] "quietness"
[35] "west"
[36] "south"
[37] "east"
[38] "north"
[39] "leaving"
[40] "arriving"
[41] "grammesCO2saved"
[42] "calories"
[43] "edition"
[44] "gradient_segment"
[45] "elevation_change"
[46] "provisionName"
[47] "gradient_smooth"
[48] "geometry"
[21] "quietness"
[22] "gradient_segment"
[23] "elevation_change"
[24] "provisionName"
[25] "start_longitude"
[26] "start_latitude"
[27] "finish_longitude"
[28] "finish_latitude"
[29] "crow_fly_distance"
[30] "event"
[31] "whence"
[32] "speed"
[33] "itinerary"
[34] "plan"
[35] "note"
[36] "length"
[37] "west"
[38] "south"
[39] "east"
[40] "north"
[41] "leaving"
[42] "arriving"
[43] "grammesCO2saved"
[44] "calories"
[45] "edition"
[46] "gradient_smooth"
[47] "geometry"

``` r
tm_shape(route_segments_minimal) +
tm_lines("name")
```

![](README_files/figure-commonmark/unnamed-chunk-2-2.png)
![](README_files/figure-commonmark/unnamed-chunk-5-5.png)

``` r
rnet_from_cyclestreets = overline(
Expand All @@ -145,7 +139,7 @@ rnet_from_cyclestreets = rnet_from_cyclestreets %>%
plot(rnet_from_cyclestreets)
```

![](README_files/figure-commonmark/unnamed-chunk-2-3.png)
![](README_files/figure-commonmark/unnamed-chunk-5-6.png)

``` r
sf::write_sf(route_segments_minimal, "route_segments_minimal.geojson", delete_dsn = TRUE)
Expand Down
47 changes: 29 additions & 18 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,46 @@ 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.
Overline is a function that takes overlapping linestrings and converts them into a route network [@morgan2020] as illustrated in a minimal reproducible example created with [ATIP](https://github.com/acteng/atip/).

```{r, message=FALSE}
library(sf)
library(stplanr)
The input is a dataset in which some segments overlap:

```{r, message=FALSE, echo=FALSE}
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)
library(stplanr)
layers = sf::st_layers("test-data/minimal_2_lines.txt")
minimal_2_lines = sf::st_read("test-data/minimal_2_lines.txt", layer = layers[[1]])
minimal_2_lines = minimal_2_lines %>%
transmute(value = c(2, 1), name = c("A", "B"))
sf::write_sf(minimal_2_lines, "input.geojson", delete_dsn = TRUE)
tm_shape(minimal_2_lines) +
tm_lines("name", palette = "Set1", lwd = "value", scale = 9)
```

The output is a dataset in which the overlapping segments have been combined:

```{r, message=FALSE, echo=FALSE}
minimal_2_rnet = overline(minimal_2_lines, attrib = "value")
tm_shape(minimal_2_rnet) +
tm_lines("value", palette = "Set1", lwd = "value", scale = 15)
sf::write_sf(minimal_2_rnet, "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.
The functionality 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
```{python}
import geopandas as gpd
input = gpd.read_file("input.geojson")
input.plot()
# Plot with colour by value:
input.plot(column="value")
```

```python
```{python}
output = gpd.read_file("output.geojson")
output.plot()
output.plot(column="value")
```
![](README_files/figure-commonmark/unnamed-chunk-3-3.png)

Expand All @@ -44,8 +55,8 @@ The example below takes routes at the segment level and calculates average gradi

```{r}
sl_desire_lines = stplanr::flowlines_sf[2:3, ]
qtm(sl_desire_lines) +
qtm(sl)
# qtm(sl_desire_lines) +
# qtm(sl)
route_segments_minimal = stplanr::route(
l = sl_desire_lines,
route_fun = cyclestreets::journey
Expand Down
Binary file modified README_files/figure-commonmark/unnamed-chunk-1-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed README_files/figure-commonmark/unnamed-chunk-1-2.png
Binary file not shown.
Binary file modified README_files/figure-commonmark/unnamed-chunk-2-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file removed README_files/figure-commonmark/unnamed-chunk-2-3.png
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 7d26e4f

Please sign in to comment.