+#!/bin/bash
+
+# Tool for downloading Vicmap Basemap aerial photography (provided as tiles)
+# and combine into a single file. View maps and determine desired coordinates
+# here - https://services.land.vic.gov.au/DELWPmaps/historical-photomaps/
+# (turn on "Vicmap Basemap - Aerial")
+
+# Andrew Lorimer - April 2021
+
+usagelong="\e[1mUSAGE:\e[0m
+ $(basename "$0") LONGMIN LONGMAX LATMIN LATMAX [OUTPUT]
+
+\e[1mOPTIONS:\e[0m
+ LONGMIN
+ Minimum longitude
+
+ LONGMAX
+ Maximum longitude
+
+ LATMIN
+ Minimum latitude
+
+ LATMAX
+ Maximum latitude
+
+ OUTPUT
+ Name of file to output to (relative to current directory). Default: vicmap.png
+
+ Inspect Element on map, then find the <div> with the satellite images (element
+ id varies). The second last number in each image URL corresponds to the longitude
+ (E-W) and the last number corresponds to the latitude (N-S). Find the maximum
+ latitude and longitude in the range shown.\n"
+
+longmin=473737
+longmax=473741
+latmin=321805
+latmax=321808
+output="vicmap.png"
+
+if (( $# < 4 || $# > 5)); then
+ printf "$usagelong"
+ exit
+fi
+longmin=$1
+longmax=$2
+latmin=$3
+latmax=$4
+if (( $# == 5 )); then
+ output=$5
+fi
+
+x=$(( $longmax - $longmin + 1))
+y=$(( $latmax - $latmin + 1))
+
+mkdir -p .vicmap-tmp
+cd .vicmap-tmp
+
+i=$longmin
+# Iterate through longitudes (columns)
+for ((i=$longmin; i<=$longmax; i++)); do
+ mkdir -p $i
+ # Iterate through latitudes (individual tiles N to S)
+ for ((j=$latmin; j<=$latmax; j++)); do
+ curl -s -C - https://base.maps.vic.gov.au/wmts/AERIAL_WM/EPSG:3857/20/$i/$j.png -o $i/$j.png
+ done
+ montage $i/* -tile 1x"$y" -geometry +0+0 $i.png
+done
+
+montage *.png -tile "$x"x1 -geometry +0+0 ../$output
+
+
+rm -rf .vicmap-tmp