User:Bettercom/code/update osm

From OpenStreetMap Wiki
Jump to: navigation, search

A little shell-script called daily which updates the Mapnik-DB and creates new tiles if necessary.

If you use it be sure to fit the parameters (bounding-box! and zoom-levels) of osm2pgsql to your needs.

This script uses envdir from DJB's daemontools package. If you don't want to use it be sure to set the MAPNIK_*-vars in this script.


DATE=`date '+%Y%m%d'`

# 1. Load Diff from Mirror
/usr/local/bin/rsync -a --stats rsync://*-${DATE}.osc.gz ${MPATH}/osmdata

# 2. Update OSM-DB
for f in ${MPATH}/osmdata/20*-${DATE}.osc.gz; do

  # 2.a Do the main job: Run osm2pgsql
  cd ${MPATH}/osm2pgsql
  ./osm2pgsql -a -s -d osm -e 6-15 -o ${MPATH}/ex-lists/expire-${DATE}.lst \
    -b -10.0,33.0,30.0,62.0 $f
  echo $f 'done'

  mv ${MPATH}/osmdata/20*-${DATE}.osc.gz ${MPATH}/osmdata/_done/

  # 2.b Do something with the expiry-list.
  cd ${MPATH}
  echo "Working with expired-tile list ${MPATH}/ex-lists/expire-${DATE}.lst"

  # Create list with only these tiles we have:
  sort -gu ${MPATH}/ex-lists/expire-${DATE}.lst | \
  while read d; do
    [ -f ${MPATH}/tiles/$d.png ] && echo $d
  done > ${MPATH}/ex-lists/expire-${DATE}.lst.tbd

  rm ${MPATH}/ex-lists/expire-${DATE}.lst

  # Re-render tiles we have:
  /usr/local/bin/envdir ${MPATH}/env \
  /usr/local/bin/ -o \
    -f ${MPATH}/ex-lists/expire-${DATE}.lst.tbd