#!/bin/bash
# usage:
#   map-merge "*.png" reference.pgw output.tif
#
# merge map tiles into one big output
# take one worldfile as reference (for output image resolution)
# not limited to PNG input, also TIF, JPG etc.
#
# frank, 5.2.2007

if [ $# -ne 3 ]; then
  echo "map-merge \"*.png\" referenceworldfile output.tif"
  exit
fi

rx=`cat "$2" | tr '\n\r' ' ' | cut -d ' ' -f 1`
ry=`cat "$2" | tr '\n\r' ' ' | cut -d ' ' -f 4`

gdalwarp -tr $rx $ry $1 $3

