vicmap-montage.shon commit add vicmap-montage.sh (ee9dc99)
   1#!/bin/bash
   2
   3# Tool for downloading Vicmap Basemap aerial photography (provided as tiles)
   4# and combine into a single file. View maps and determine desired coordinates
   5# here - https://services.land.vic.gov.au/DELWPmaps/historical-photomaps/
   6# (turn on "Vicmap Basemap - Aerial")
   7
   8# Andrew Lorimer - April 2021
   9
  10usagelong="\e[1mUSAGE:\e[0m
  11  $(basename "$0") LONGMIN LONGMAX LATMIN LATMAX [OUTPUT]
  12
  13\e[1mOPTIONS:\e[0m
  14  LONGMIN
  15    Minimum longitude
  16
  17  LONGMAX
  18    Maximum longitude
  19
  20  LATMIN
  21    Minimum latitude
  22
  23  LATMAX
  24    Maximum latitude
  25
  26  OUTPUT
  27    Name of file to output to (relative to current directory). Default: vicmap.png
  28 
  29  Inspect Element on map, then find the <div> with the satellite images (element 
  30  id varies). The second last number in each image URL corresponds to the longitude 
  31  (E-W) and the last number corresponds to the latitude (N-S). Find the maximum 
  32  latitude and longitude in the range shown.\n"
  33
  34longmin=473737
  35longmax=473741
  36latmin=321805
  37latmax=321808
  38output="vicmap.png"
  39
  40if (( $# < 4 || $# > 5)); then
  41  printf "$usagelong"
  42  exit
  43fi
  44longmin=$1
  45longmax=$2
  46latmin=$3
  47latmax=$4
  48if (( $# == 5 )); then
  49  output=$5
  50fi
  51
  52x=$(( $longmax - $longmin + 1))
  53y=$(( $latmax - $latmin + 1))
  54
  55mkdir -p .vicmap-tmp
  56cd .vicmap-tmp
  57
  58i=$longmin
  59# Iterate through longitudes (columns)
  60for ((i=$longmin; i<=$longmax; i++)); do
  61  mkdir -p $i
  62  # Iterate through latitudes (individual tiles N to S)
  63  for ((j=$latmin; j<=$latmax; j++)); do
  64    curl -s -C - https://base.maps.vic.gov.au/wmts/AERIAL_WM/EPSG:3857/20/$i/$j.png -o $i/$j.png
  65  done
  66  montage $i/* -tile 1x"$y" -geometry +0+0 $i.png
  67done
  68
  69montage *.png -tile "$x"x1 -geometry +0+0 ../$output
  70
  71
  72rm -rf .vicmap-tmp