diff --git a/.gitignore b/.gitignore index b38b214..a609cd0 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ trash/ api_key R/route_analysis.html log/ +# Exclude html files generated in the top directory (from RStudio runs) +./*.html diff --git a/Makefile b/Makefile index 541b474..025afa9 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,35 @@ walk: route_analysis.Rmd R -e 'library("rmarkdown"); old_path <- Sys.getenv("PATH"); Sys.setenv(PATH = paste(old_path, "/usr/local/bin", sep = ":")); rmarkdown::render(knit_root_dir = "./", output_dir = "./html", input = "./route_analysis.Rmd", output_file = "./html/route_analysis.html")' -cycle: cycling_route_analysis.Rmd +cycle_osrm: cycling_route_analysis.Rmd R -e 'library("rmarkdown"); old_path <- Sys.getenv("PATH"); Sys.setenv(PATH = paste(old_path, "/usr/local/bin", sep = ":")); rmarkdown::render(knit_root_dir = "./", output_dir = "./html", input = "./cycling_route_analysis.Rmd", output_file = "./html/cycling_route_analysis.html")' +cycle_brouter: cycling_route_analysis_brouter.Rmd + R -e 'library("rmarkdown"); old_path <- Sys.getenv("PATH"); Sys.setenv(PATH = paste(old_path, "/usr/local/bin", sep = ":")); rmarkdown::render(knit_root_dir = "./", output_dir = "./html", input = "./cycling_route_analysis_brouter.Rmd", output_file = "./html/cycling_route_analysis.html")' + +osrm-container: ./docker/osrm/docker-compose.yml + cd ./docker/osrm/; docker compose up -d + +osrm-data: + cd ./docker/osrm/; wget https://download.geofabrik.de/north-america/us/wisconsin-latest.osm.pbf -O ./data-raw/wisconsin-latest.osm.pbf + cd ./docker/osrm/; docker run -t -v "./data-foot:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-extract -p /opt/foot.lua /data/wisconsin-latest.osm.pbf + cd ./docker/osrm/; docker run -t -v "./data-foot:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-partition /data/wisconsin-latest.osrm + cd ./docker/osrm/; docker run -t -v "./data-foot:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-customize /data/wisconsin-latest.osrm + cd ./docker/osrm/; docker run -t -v "./data-bicycle:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-extract -p /opt/bicycle.lua /data/wisconsin-latest.osm.pbf + cd ./docker/osrm/; docker run -t -v "./data-bicycle:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-partition /data/wisconsin-latest.osrm + cd ./docker/osrm/; docker run -t -v "./data-bicycle:/data" -v "./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf" osrm/osrm-backend osrm-customize /data/wisconsin-latest.osrm + +brouter-container: ./docker/brouter/docker-compose.yml + cd ./docker/brouter; docker compose up -d + +brouter-data: + cd ./docker/brouter/; git clone https://github.com/abrensch/brouter.git + cd ./docker/brouter/; wget -i segments.csv -P ./brouter/misc/segments4/ + cd ./docker/brouter/; git clone https://github.com/nrenner/brouter-web.git + cd ./docker/brouter/brouter-web; cp keys.template.js keys.js; + cd ./docker/brouter/brouter-web; cp config.template.js config.js + cd ./docker/brouter; docker compose build + clean: clean-data clean-figure clean-script clean-data: @@ -16,3 +42,4 @@ clean-figure: rm -rvf ./figure/ .PHONY: data + diff --git a/README.md b/README.md index 9471dc2..929db12 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This script generates maps to analyze the potential walking routes for students to their school. - I excluded the addresses of the students from the repository. -- The actual route generation is done with OSRM, I run it locally in a docker container. +- The actual route generation is done with OSRM and brouter, those are run locally in docker containers. - The basemap is pulled from Stadia Maps. The usage of the script is well within the free tier, you'll need an API key from them. ## Data sources @@ -22,8 +22,17 @@ This script will generate a few figures: ![example routes-lts figure](examples/example-routes-lts.png) ## Using make -The command `make route_analysis` will run *route_analysis.Rmd* which -is an R markdown file containing the original R script *route_analysis.R* +- `make osrm-data`: downloads the OpenStreetMap data for Wisconsin, and preproccesses it for use with OSRM. +- `make osrm-container`: starts the OSRM containers (backends and frontends) for walking and biking. +- `make brouter-data`: clones the repositories for brouter and brouter-web and downloads the segment data. It also builds the docker images for brouter and brouter-web. +- `make brouter-container`: starts the brouter containers (backend and frontend). +- `make walk` will run *route_analysis.Rmd* which +calculates the walking routes using OSRM. +- `make cycle-osrm` will run *cycling_route_analysis.Rmd* which calculates the biking routes using OSRM. +- `make cycle-brouter` will run *cycling_route_analysis_brouter.Rmd* which calculates the biking routes using brouter. ## Misc. - [Bike Level of Traffic Stress (LTS)](https://www.dvrpc.org/webmaps/bike-lts/analysis/) + +## OpenStreetMap Data +- [wisconsin-latest.osm.pbf](https://download.geofabrik.de/north-america/us/wisconsin-latest.osm.pbf) diff --git a/cycling_route_analysis_brouter.Rmd b/cycling_route_analysis_brouter.Rmd index 2179833..d92a9c5 100644 --- a/cycling_route_analysis_brouter.Rmd +++ b/cycling_route_analysis_brouter.Rmd @@ -155,7 +155,7 @@ routes <- bind_rows(routes) ``` Notes: -- _osrmRoute_ is the primary function used above. +- this queries the brouter server to get routes ## Combine routes with Bike LTS diff --git a/docker/brouter/.gitignore b/docker/brouter/.gitignore new file mode 100644 index 0000000..43905bb --- /dev/null +++ b/docker/brouter/.gitignore @@ -0,0 +1,10 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + +# Except the list of relevant segments +!segments.csv + +# Except docker-compose.yml +!docker-compose.yml diff --git a/docker/brouter/docker-compose.yml b/docker/brouter/docker-compose.yml new file mode 100644 index 0000000..7eb2058 --- /dev/null +++ b/docker/brouter/docker-compose.yml @@ -0,0 +1,26 @@ +--- +services: + brouter: + container_name: brouter + ports: + - 17777:17777 + volumes: + - ./brouter/misc/segments4:/segments4 + image: brouter + build: + context: ./brouter + dockerfile: Dockerfile +--- +services: + brouter-web: + container_name: brouter-web + ports: + - 127.0.0.1:8080:80 + volumes: + - ./brouter-web/config.js:/usr/share/nginx/html/config.js + - ./brouter-web/keys.js:/usr/share/nginx/html/keys.js + - ./brouter-web/profiles:/usr/share/nginx/html/profiles + image: brouter-web + build: + context: ./brouter-web + dockerfile: Dockerfile diff --git a/docker/brouter/segments.csv b/docker/brouter/segments.csv new file mode 100644 index 0000000..8bdf00c --- /dev/null +++ b/docker/brouter/segments.csv @@ -0,0 +1,4 @@ +https://brouter.de/brouter/segments4/W90_N40.rd5 +https://brouter.de/brouter/segments4/W90_N45.rd5 +https://brouter.de/brouter/segments4/W95_N40.rd5 +https://brouter.de/brouter/segments4/W95_N45.rd5 diff --git a/docker/osrm/.gitignore b/docker/osrm/.gitignore new file mode 100644 index 0000000..5044ea6 --- /dev/null +++ b/docker/osrm/.gitignore @@ -0,0 +1,10 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore +!docker-compose.yml +!docker-compose-2.yml +!preprocess.sh +!data-raw/ +!data-foot/ +!data-bicycle/ diff --git a/docker/osrm/data-bicycle/.gitignore b/docker/osrm/data-bicycle/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/osrm/data-bicycle/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/osrm/data-foot/.gitignore b/docker/osrm/data-foot/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/osrm/data-foot/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/osrm/data-raw/.gitignore b/docker/osrm/data-raw/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/osrm/data-raw/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/osrm/docker-compose.yml b/docker/osrm/docker-compose.yml new file mode 100644 index 0000000..cf2f40a --- /dev/null +++ b/docker/osrm/docker-compose.yml @@ -0,0 +1,32 @@ +--- +services: + osrm-backend-foot: + container_name: osrm-backend-foot + ports: + - 5000:5000 + volumes: + - ./data-foot:/data + - ./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf + image: osrm/osrm-backend + command: osrm-routed --algorithm mld /data/wisconsin-latest.osrm + osrm-backend-bicycle: + container_name: osrm-backend-bicycle + ports: + - 5001:5000 + volumes: + - ./data-bicycle:/data + - ./data-raw/wisconsin-latest.osm.pbf:/data/wisconsin-latest.osm.pbf + image: osrm/osrm-backend + command: osrm-routed --algorithm mld /data/wisconsin-latest.osrm + osrm-frontend-foot: + ports: + - 9966:9966 + environment: + OSRM_BACKEND: 'http://localhost:5000' + image: osrm/osrm-frontend + osrm-frontend-bicycle: + ports: + - 9967:9966 + environment: + OSRM_BACKEND: 'http://localhost:5001' + image: osrm/osrm-frontend