From 6455542eac015515bac589c999343d170fe59317 Mon Sep 17 00:00:00 2001 From: syounkin Date: Mon, 4 Nov 2024 18:50:21 -0600 Subject: [PATCH 1/9] Added docker commands to Makefile make data and make container can be used to pre-process the data and spawn the docker containers. --- Makefile | 13 +++++++++++++ docker/.gitignore | 10 ++++++++++ docker/data-bicycle/.gitignore | 4 ++++ docker/data-foot/.gitignore | 4 ++++ docker/data-raw/.gitignore | 4 ++++ docker/docker-compose.yml | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 67 insertions(+) create mode 100644 docker/.gitignore create mode 100644 docker/data-bicycle/.gitignore create mode 100644 docker/data-foot/.gitignore create mode 100644 docker/data-raw/.gitignore create mode 100644 docker/docker-compose.yml diff --git a/Makefile b/Makefile index 541b474..83efc12 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,18 @@ walk: route_analysis.Rmd cycle: 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")' +container: ./docker/docker-compose.yml + cd ./docker/; docker compose up -d + +data: + cd ./docker/; 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/; 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/; 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/; 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/; 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/; 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 + + clean: clean-data clean-figure clean-script clean-data: @@ -16,3 +28,4 @@ clean-figure: rm -rvf ./figure/ .PHONY: data + diff --git a/docker/.gitignore b/docker/.gitignore new file mode 100644 index 0000000..5044ea6 --- /dev/null +++ b/docker/.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/data-bicycle/.gitignore b/docker/data-bicycle/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/data-bicycle/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/data-foot/.gitignore b/docker/data-foot/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/data-foot/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/data-raw/.gitignore b/docker/data-raw/.gitignore new file mode 100644 index 0000000..5e7d273 --- /dev/null +++ b/docker/data-raw/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml new file mode 100644 index 0000000..cf2f40a --- /dev/null +++ b/docker/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 From 14b8a1428482206f1b046b3b55cf7c383610dcf1 Mon Sep 17 00:00:00 2001 From: syounkin Date: Mon, 4 Nov 2024 18:50:47 -0600 Subject: [PATCH 2/9] Added link to OSM data to README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 9471dc2..3a2179c 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,6 @@ is an R markdown file containing the original R script *route_analysis.R* ## 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) From 7993621f9fc3e57ec735b87a211ba3b0bc2935aa Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 07:29:34 -0600 Subject: [PATCH 3/9] changed docker directory structure, added brouter --- Makefile | 28 +++++++++++++++-------- docker/brouter/.gitignore | 7 ++++++ docker/brouter/segments.csv | 4 ++++ docker/{ => osrm}/.gitignore | 0 docker/{ => osrm}/data-bicycle/.gitignore | 0 docker/{ => osrm}/data-foot/.gitignore | 0 docker/{ => osrm}/data-raw/.gitignore | 0 docker/{ => osrm}/docker-compose.yml | 0 8 files changed, 30 insertions(+), 9 deletions(-) create mode 100644 docker/brouter/.gitignore create mode 100644 docker/brouter/segments.csv rename docker/{ => osrm}/.gitignore (100%) rename docker/{ => osrm}/data-bicycle/.gitignore (100%) rename docker/{ => osrm}/data-foot/.gitignore (100%) rename docker/{ => osrm}/data-raw/.gitignore (100%) rename docker/{ => osrm}/docker-compose.yml (100%) diff --git a/Makefile b/Makefile index 83efc12..512ad73 100644 --- a/Makefile +++ b/Makefile @@ -4,17 +4,27 @@ walk: route_analysis.Rmd cycle: 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")' -container: ./docker/docker-compose.yml - cd ./docker/; docker compose up -d +osrm-container: ./docker/osrm/docker-compose.yml + cd ./docker/osrm/; docker compose up -d -data: - cd ./docker/; 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/; 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/; 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/; 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/; 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/; 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 +osrm-data: + 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 diff --git a/docker/brouter/.gitignore b/docker/brouter/.gitignore new file mode 100644 index 0000000..ed90703 --- /dev/null +++ b/docker/brouter/.gitignore @@ -0,0 +1,7 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore + +# Except the list of relevant segments +!segments.csv 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/.gitignore b/docker/osrm/.gitignore similarity index 100% rename from docker/.gitignore rename to docker/osrm/.gitignore diff --git a/docker/data-bicycle/.gitignore b/docker/osrm/data-bicycle/.gitignore similarity index 100% rename from docker/data-bicycle/.gitignore rename to docker/osrm/data-bicycle/.gitignore diff --git a/docker/data-foot/.gitignore b/docker/osrm/data-foot/.gitignore similarity index 100% rename from docker/data-foot/.gitignore rename to docker/osrm/data-foot/.gitignore diff --git a/docker/data-raw/.gitignore b/docker/osrm/data-raw/.gitignore similarity index 100% rename from docker/data-raw/.gitignore rename to docker/osrm/data-raw/.gitignore diff --git a/docker/docker-compose.yml b/docker/osrm/docker-compose.yml similarity index 100% rename from docker/docker-compose.yml rename to docker/osrm/docker-compose.yml From 24dacb5e6bf40598b1954796e308230a3c7eae0b Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 07:43:32 -0600 Subject: [PATCH 4/9] added download wisconsin-latest.osm.pbf to makefile --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 512ad73..325bd9e 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,7 @@ 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 From 104f215a0eff50ed4f1fbb7ea34805f6bc210a98 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 07:52:14 -0600 Subject: [PATCH 5/9] Edited .gitignore, edited README, edited Makefile to include new brouter make commands --- Makefile | 5 ++++- README.md | 10 ++++++++-- docker/brouter/.gitignore | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 325bd9e..025afa9 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ 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 diff --git a/README.md b/README.md index 3a2179c..9ab8fdc 100644 --- a/README.md +++ b/README.md @@ -22,8 +22,14 @@ 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/) diff --git a/docker/brouter/.gitignore b/docker/brouter/.gitignore index ed90703..43905bb 100644 --- a/docker/brouter/.gitignore +++ b/docker/brouter/.gitignore @@ -5,3 +5,6 @@ # Except the list of relevant segments !segments.csv + +# Except docker-compose.yml +!docker-compose.yml From 378c991c6d8bcd5d41776b204ca157f78d9a5974 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 07:53:23 -0600 Subject: [PATCH 6/9] added docker-compose to brouter docker directory --- docker/brouter/docker-compose.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 docker/brouter/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 From fe88172a3b1283caef89d74dee22e304da6bccc0 Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 07:59:38 -0600 Subject: [PATCH 7/9] edited typo in Makefile --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ab8fdc..f158124 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ This script will generate a few figures: - `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. +- `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/) From dd36d8b9570aa4a1ba8f2ac0dd1dd06520c4d27f Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 08:15:00 -0600 Subject: [PATCH 8/9] added top level .html files to .gitignore and edited a note in cycling_route_analysis_brouter.Rmd --- .gitignore | 2 ++ cycling_route_analysis_brouter.Rmd | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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/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 From ef51272a69c549e99fda8f6cd404ff4afa753f9d Mon Sep 17 00:00:00 2001 From: Ben Varick Date: Tue, 5 Nov 2024 08:27:07 -0600 Subject: [PATCH 9/9] added brouter to readme intro --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f158124..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