Skip to content

Instantly share code, notes, and snippets.

@avioli
Last active September 28, 2016 22:18
Show Gist options
  • Save avioli/a9fd976408cd5d4ef3b93a7b119a5c91 to your computer and use it in GitHub Desktop.
Save avioli/a9fd976408cd5d4ef3b93a7b119a5c91 to your computer and use it in GitHub Desktop.

Preparing a PBF file for Open Trip Planner

Osmosis

You can refer to Osmosis' installation guide.

TMPDIR=/tmp
BINDIR=/usr/local/bin
OPTDIR=/opt
OSMOSISTAR=osmosis-latest.tgz
OSMOSISDIR=$OPTDIR/osmosis
OSMOSISURL="http://bretth.dev.openstreetmap.org/osmosis-build/osmosis-latest.tgz"

curl -L "$OSMOSISURL" > $TMPDIR/$OSMOSISTAR

# check and extract
tar tzf $TMPDIR/$OSMOSISTAR &>/dev/null && \
  mkdir -p $OSMOSISDIR && \
  tar xzf $TMPDIR/$OSMOSISTAR -C $OSMOSISDIR && \
  update-alternatives --install $BINDIR/osmosis osmosis $OSMOSISDIR/bin/osmosis 100 && \
  rm $TMPDIR/$OSMOSISTAR

PBF File

In this case we fetch Australia's PBF file and produce tasmania's PBF file.

ROUTER_NAME=XYZ # adjust to suit
GRAPHS_BASE_DIR=. # adjust to suit and ensure you have write permissions

PBF_NAME=tasmania # or could be =$ROUTER_NAME
TAS_BB="top=-39.466797 left=143.720747 bottom=-43.773466 right=148.683171"

GRAPH_DIR="$GRAPHS_BASE_DIR/graphs/$ROUTER_NAME"
PBF_FILE=australia-latest.osm.pbf
URL="http://download.geofabrik.de/australia-oceania/$PBF_FILE"

TMPDIR=/tmp

curl -L "https://gist.github.com/avioli/a9fd976408cd5d4ef3b93a7b119a5c91/raw/09b15fe921de3a0800b36f7c632e5c5f94897ac6/tag-transform-rules.xml" > ./tag-transform-rules.xml
curl -L "$URL.md5" > $TMPDIR/$PBF_FILE.md5
curl -L "$URL" > $TMPDIR/$PBF_FILE

(cd $TMPDIR && md5sum -c $PBF_FILE.md5) && \
  osmosis \
    --read-pbf file=$TMPDIR/$PBF_FILE \
    --tee 1 \
    --bounding-box $TAS_BB \
    --tf reject-relations type=restriction \
    --tt ./tag-transform-rules.xml \
    --write-pbf file="$TMPDIR/$ROUTER_NAME.osm.pbf" && \
  mv "$TMPDIR/$PBF_NAME.osm.pbf" "$GRAPH_DIR/"

Notes:

  • --tee 1 points the number of --bounding-box arguments following.
  • since we will be dealing with GTFS data and ONLY transit directions, we should cleanup any restrictions.
  • see tag-transform-rules.xml below, which converts one way paths to two-ways, since walking directions actually follow this rule.
<?xml version="1.0"?>
<translations>
<!-- ref: http://wiki.openstreetmap.org/wiki/Osmosis/TagTransform -->
<translation>
<name>Remove oneway restrictions</name>
<description>Convert oneway ways into two-ways, since walking directions end up following this rule.</description>
<match type="way">
<tag k="oneway" match_id="oneway_id" v="yes"/>
</match>
<output>
<copy-unmatched/>
<tag from_match="oneway_id" v="no"/>
</output>
</translation>
</translations>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment