Skip to content

Commit

Permalink
More simplifications for #16
Browse files Browse the repository at this point in the history
  • Loading branch information
robinlovelace-ate committed Jul 19, 2023
1 parent 7d1edb5 commit 1b0cd7e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 126 deletions.
99 changes: 1 addition & 98 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,115 +49,18 @@ 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

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
)
```

Most common output is sf

``` r
names(route_segments_minimal)
```

[1] "Area.of.residence"
[2] "Area.of.workplace"
[3] "All"
[4] "Work.mainly.at.or.from.home"
[5] "Underground..metro..light.rail..tram"
[6] "Train"
[7] "Bus..minibus.or.coach"
[8] "Taxi"
[9] "Motorcycle..scooter.or.moped"
[10] "Driving.a.car.or.van"
[11] "Passenger.in.a.car.or.van"
[12] "Bicycle"
[13] "On.foot"
[14] "Other.method.of.travel.to.work"
[15] "id"
[16] "route_number"
[17] "name"
[18] "distances"
[19] "time"
[20] "busynance"
[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-5-5.png)

``` r
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)
```

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

``` r
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)
```
![](README_files/figure-commonmark/rnet_from_cyclestreets-5.png)

# Large example

A large example plus benchmark is shown below:

``` r
# 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
system.time({
cycle_routes_london = geojsonsf::geojson_sf("cycle_routes_london.geojson")
Expand Down
19 changes: 12 additions & 7 deletions README.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -46,34 +46,38 @@ input.plot(column="value")
output = gpd.read_file("output.geojson")
output.plot(column="value")
```
![](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}
```{r rnet_from_cyclestreets, message=FALSE, echo=FALSE}
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")
# names(route_segments_minimal)
route_segments_minimal = route_segments_minimal %>%
transmute(All = All, name = name, gradient_smooth = gradient_smooth, quietness = quietness)
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)
m1 = tm_shape(route_segments_minimal) +
tm_lines("name", lwd = "All", palette = "Set1", scale = 15) +
tm_layout(legend.outside = TRUE)
m2 = tm_shape(rnet_from_cyclestreets) +
tm_lines(lwd = "All", palette = "viridis", scale = 20) +
tm_layout(legend.outside = TRUE)
tmap_arrange(m1, m2)
```

# Large example
Expand All @@ -82,6 +86,7 @@ A large example plus benchmark is shown below:

```{r}
#| eval: false
#| echo: false
# list.files()
cycle_routes_london = pct::get_pct_routes_fast("london")
sf::write_sf(cycle_routes_london, "cycle_routes_london.geojson")
Expand Down
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-5-6.png
Binary file not shown.
Loading

0 comments on commit 1b0cd7e

Please sign in to comment.