bvarick / route_analysis

GNU General Public License v3.0
0 stars 1 forks source link

OSRM run with local docker container #2

Closed syounkin closed 1 week ago

syounkin commented 3 weeks ago

Ben,

I thought I would turn my questions about osrm into an issue on Github. I have lots of questions about the docker container setup. Maybe here is a good place to sort them out?

Thanks,

Sam

bvarick commented 3 weeks ago

Hey Sam, I run the docker container on the same computer I'm running the script on, it just needs to have the docker engine installed on it. You could run it on a separate machine either on your LAN or available over the WAN. Doing it on the same machine improves the latency.

Here's a step by step of what I did: (these are very similar to OSRM's documentation)

  1. Download the relevant OpenStreetMap (OSM) data. I downloaded all of Wisconsin (the .osm.pbf file) from here: https://download.geofabrik.de/north-america/us.html a. I saved the OpenStreetmap data in the folder /home/ben/docker/osrm/data. Change that part of the following commands to wherever you saved it. This file is ~262MB.

  2. I prepossessed the data, with these commands. You only need to do this once (or whenever you update the underlying OSM data). This generates ~2.2GB of files for Wisconsin. a. docker run -t -v "/home/ben/docker/osrm/data:/data" osrm/osrm-backend osrm-extract -p /opt/foot.lua /data/wisconsin-latest.osm.pbf b. docker run -t -v "/home/ben/docker/osrm/data:/data" osrm/osrm-backend osrm-partition /data/wisconsin-latest.osrm c. docker run -t -v "/home/ben/docker/osrm/data:/data" osrm/osrm-backend osrm-customize /data/wisconsin-latest.osrm

  3. Then I spin up a couple of docker containers with the following docker-compose.yml file:

    ---
    services:
    osrm-backend:
        ports:
            - 5000:5000
        volumes:
            - /home/ben/docker/osrm/data:/data
        image: osrm/osrm-backend
        command: osrm-routed --algorithm mld /data/wisconsin-latest.osrm
    osrm-frontend:
        ports:
            - 9966:9966
        image: osrm/osrm-frontend

    a. I saved that file as docker-compose.yml which defines the containers. Then I start the containers by running docker compose up -d

  4. now I can access a webgui at http://127.0.0.1:9966 to visualize individual routes (and double check that everything is working). And I can query the routing engine through its API at http://127.0.0.1:5000/ within the R script.

syounkin commented 3 weeks ago

Thank you for the detailed instructions. I will work my way through them today.

syounkin commented 3 weeks ago

I have now run _routeanalysis.Rmd without error. Thanks for these instructions. They were very helpful.

bvarick commented 2 weeks ago

I think we need to make some adjustments for bicycling. I think that OSRM can only be set up to do one mode of travel in the preprocessing step (defined by the /opt/foot.lua) per instance. We can set up a seperate backend for cycling in a seperate docker container, with a seperate data directory and expose it on port 5001 for cycling. And then query backend at port 5000 for walking and 5001 for cycling. Or we could assume (especially for kids), that they bike where they would walk, so walking directions are fine for cycling.

bvarick commented 2 weeks ago

So I got something up and running. I made three subdirectories in my docker directory:

These are my pre-processing commands

pre-processing for walking

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

pre-processing for bicycling

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

docker-compose.yml

And this is the docker-compose.yml that creates two containers, one accessing the foot routing data exposed on port 5000, one accessing the bicycle routing data exposed on port 5001.

---
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
bvarick commented 2 weeks ago

Here's a docker-compose.yml with frontends to compare the walking and bicycling routes:

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

Walking frontend: http://127.0.0.1:9966/ Biking frontend: http://127.0.0.1:9967/

syounkin commented 2 weeks ago

I'll take a look at this on Monday.

syounkin commented 2 weeks ago

The instructions look very clear. I will work through them today and let you know how it goes. Thanks again for providing this info.

syounkin commented 2 weeks ago

Everything ran without error. Thanks. It looks like cyclists are still being routed down Northport, Packers, and Washington Avenues. Those are not the best places for high school kids to ride their bikes.

bvarick commented 2 weeks ago

I totally agree those aren't good cycling routes. Which is kind of the point of the map. My goal is not to figure out what is the best route for a kid to ride to school, but to figure out the best road for the city/county/state to improve in increase how many kids are biking to school.

The map suggests that if we want it to be safer and more convenient for high school kids to bike to school, we should improve Northport, Packers, and E Washington so that they are safe for a high schooler. While those roads might take a while to change, hopefully the map also shows more short term attainable streets to improve. Does that make sense?

Separately, brouter.de has the best safe bike routing engine I've seen. I'm trying to figure out how to incorporate that. Perhaps then we can compare currently safe routes, with most efficient routes to see how much more convenient improving a given street will be for students. I'm trying to avoid this problem: parallel_bike_route_panel_color_400

bvarick commented 2 weeks ago

Here's brouter's github: https://github.com/abrensch/brouter

bvarick commented 2 weeks ago

I got brouter running on my computer in docker! Now I just have to figure out how to query it from R

bvarick commented 2 weeks ago

I figured it out, and made a duplicate cycling_route_analysis_brouter.Rmd. The code is pretty messy, I'll clean it up tomorrow. Here's a comparison East High School Routes - Traffic Stress_cycling-brouter.pdf East High School Routes - Traffic Stress_cycling-osrm.pdf

Brouter definitely does a better job than OSRM at making good bike routes. It shows that E Wash can be avoided. I'm not sure why it's still routing onto Pennsylvania instead of the bike path in Demetral Park

syounkin commented 2 weeks ago

Outstanding. I'll have a look tomorrow.