User:Firefishy/za-rail-script

From OpenStreetMap Wiki
Jump to navigation Jump to search

Little script I use to get the most current OSM data for a small rail project of mine. Polygon files are available from download.cloudmade.com

#!/bin/bash

#Get PBF from geofabrik (-N means only if it's updated)
wget -q -N http://download.geofabrik.de/osm/africa/south_africa_and_lesotho.osm.pbf
echo Update: $?

#Get bits of the timestamp string 24 hours ago
EX_Y=`TZ="GMT+24" date -r south_africa_and_lesotho.osm.pbf +'%Y'`
EX_m=`TZ="GMT+24" date -r south_africa_and_lesotho.osm.pbf +'%m'`
EX_d=`TZ="GMT+24" date -r south_africa_and_lesotho.osm.pbf +'%d'`

#Fetch a work state file
wget -q "http://toolserver.org/~mazder/replicate-sequences/?Y=${EX_Y}&m=${EX_m}&d=${EX_d}&H=20&i=25&s=00&stream=minute" -O work/state.txt


#Ex_diff is the interval setting needed to bring things up-to-date
#date -u -d "2011-02-20 20:25" +%s
EX_diff_string=`date -u +%s`-`TZ=GMT+0 date -u -d "${EX_Y}-${EX_m}-${EX_d} 20:25" +%s`
EX_diff=`echo ${EX_diff_string}|bc`

#Make a configuration.txt file
echo "baseUrl=https://planet.openstreetmap.org/replication/minute/" >work/configuration.txt
echo "maxInterval = ${EX_diff}" >>work/configuration.txt

#Run the osmosis replication
/home/grant/code/osmosis-0.38/bin/osmosis --read-replication-interval workingDirectory=work/ --simplify-change --read-pbf south_africa_and_lesotho.osm.pbf --apply-change --bounding-polygon file=south_africa.poly --write-pbf file=south_africa_and_lesotho-updated.osm.pbf compress=none
echo Current pbf: $?

#Tag filter for railway tagged nodes and ways
/home/grant/code/osmosis-0.38/bin/osmosis \
  --rb south_africa_and_lesotho-updated.osm.pbf \
  --tf reject-relations \
  --tf accept-nodes railway=* \
  --tf reject-ways outPipe.0=railway-poi \
  \
  --rb south_africa_and_lesotho-updated.osm.pbf \
  --tf reject-relations \
  --tf accept-ways railway=* \
  --used-node outPipe.0=railway-way \
  \
  --merge inPipe.0=railway-poi inPipe.1=railway-way \
  --wx sa-railway-updated.osm
echo Extract osm: $?