Skip to content

Latest commit

 

History

History
99 lines (78 loc) · 4.76 KB

README.md

File metadata and controls

99 lines (78 loc) · 4.76 KB

Gullies

Maps of routes draining into a common sink from all over a road network.

Prints of these images are available on my society6 page: https://society6.com/krithin

US roads draining into NYC

Inspired by moovel labs' Roads to Rome and Topi Tjukanov's Roads of America.

Usage

Prerequisites

In general, you'll need an OSM snapshot to process, an OSRM instance running against that same snapshot, and some intial set of destination points to route to (such as from one of the files in inputdata/ or as generated by getlocations.py).

In more detail:

  1. Grab an OSM extract for a region you're interested in. These are available from http://download.geofabrik.de/ or other sources listed in the OSM wiki.

    curl -O http://download.geofabrik.de/north-america/us/new-york-latest.osm.pbf

    If no predefined OSM extract matches the exact region you're interested in, you can cut one out of a larger extract with osmium-tool - see the osmium docs for how to use osmium getid followed by osmium extract to get an extract for a region bounded by an existing OSM relation.

  2. Get OSRM.

    As of August 2022 the instructions to build OSRM from source do not work due to dependency issues, so you'll have to run a prebuilt OSRM Docker image. We'll use this in the next two steps.

    docker pull osrm/osrm-backend
  3. Preprocess the OSM snapshot you downloaded earlier so OSRM can route against it. Assuming you're running this in the same directory where you downloaded the OSM snapshot earlier:

    # Create a scratch directory, because OSRM will produce *lots* of processed files from the input you give it.
    
    mkdir scratch && cd scratch
    mv ../new-york-latest.osm.pbf ./ny.osm.pbf
    
    docker run -t -v "$PWD:/data" osrm/osrm-backend osrm-extract -p /opt/car.lua /data/ny.osm.pbf
    docker run -t -v "$PWD:/data" osrm/osrm-backend osrm-partition /data/ny.osrm
    docker run -t -v "$PWD:/data" osrm/osrm-backend osrm-customize /data/ny.osrm

    Warning: This step might take a lot of memory. osrm-extract for a map of the whole of the US peaked at 46 GiB of RAM used.

  4. Start the OSRM server:

    docker run -t -i -p 5000:5000 -v "$PWD:/data" osrm/osrm-backend osrm-routed --algorithm mld /data/ny.osrm

    Leave this server running; we'll send it some requests in later steps.

Generating images

Get started by cloning this repo:

git clone https://github.com/krithin/gullies.git
cd gullies
  1. Install dependencies

    python -m venv venv
    source venv/bin/activate # (or the appropriate command for your shell)
    pip install -U pip && pip install -r requirements.txt
  2. Generate a set of destination points to route to:

    python getlocations.py scratch/ny.osm.pbf 10000 > nylocations.csv

    As an alternative to using getlocations.py to generate the locations, you can instead use one of the census datasets included in inputdata/.

  3. Generate routes to those points:

    cat nylocations.csv | python getroutes.py http://localhost:5000 > nyroutes.txt
  4. Collate the resulting routes:

    cat nyroutes.txt | python collatesegments.py scratch/ny.osm.pbf > nyroutescollated.txt
  5. Simplify the collated routes:

    cat nyroutescollated.txt | python simplifysegments.py 4 > nyroutessimplified.txt

    If you're running this process on a smallish region, say a single city, you can try skipping this step and feeding routescollated.txt directly into the plotting step below.

  6. And produce a plot:

    cat nyroutessimplified.txt | python plotmatplotlib.py new-york.png

    If you run this last step on a server machine without X or some other graphical interface installed, you might encounter a known Matplotlib issue for which the solution is to explicitly specify a plotting backend

Gallery

Australia from Sydney Australia roads

Roads from all over New York state, draining into New York City: New York roads

Singapore Singapore

Roads from all over the contiguous United States, draining into the mouth of the Mississippi at New Orleans: New Orleans roads