3 GDALCOPYPROJ="/usr/share/doc/python-gdal/examples/gdalcopyproj.py"
 
   5 # Expected directory names: 2010-04, 2010-11, ... 2016-04
 
   6 OSSV_EDITIONS=($(ls -d 201*|sort -n))
 
   7 OSSV_EDITIONS_LENGTH=${#OSSV_EDITIONS[@]}
 
   9 OSSV_EDITIONS_TMP=$(mktemp -d --suffix=osstvw_edit)
 
  11   rm -rf "${OSSV_EDITIONS_TMP}"
 
  15 # Create OSSTVW ocean blue to compare new files against
 
  16 convert -size 5000x5000 xc:'#e6f6ff' -depth 8 ${OSSV_EDITIONS_TMP}/blue.png
 
  18 # Outer loop (compare from)
 
  19 for (( i=0; i<${OSSV_EDITIONS_LENGTH}; i++ )); do
 
  20   # Inner loop (compare to)
 
  21   for (( o=${i}; o<${OSSV_EDITIONS_LENGTH}; o++ )); do
 
  22     # Skip when outer == inner edition
 
  23     if [ "$i" != "$o" ]; then
 
  24       OSSV_DIFF_NAME="diff-${OSSV_EDITIONS[$i]}-${OSSV_EDITIONS[$o]}"
 
  25       mkdir -p "${OSSV_DIFF_NAME}"
 
  26       # TIF file loop for edition - see end of loop for find
 
  27       while IFS= read -r -d $'\0' FILE; do
 
  28         FILE_1="${OSSV_EDITIONS[$i]}/${FILE}"
 
  29         FILE_2="${OSSV_EDITIONS[$o]}/${FILE}"
 
  30         if [ ! -f "${FILE_1}" ]; then
 
  31           FILE_1="${OSSV_EDITIONS_TMP}/blue.png"
 
  33         # Skip existing files or excluded files
 
  34         if [ ! -f "${OSSV_DIFF_NAME}/${FILE}" ] && [ ! -f "${OSSV_DIFF_NAME}/${FILE}.skip" ]; then
 
  35           echo Creating diff ${OSSV_EDITIONS[$i]} ${OSSV_EDITIONS[$o]} "${FILE_1}" "${OSSV_DIFF_NAME}/${FILE}"
 
  36           # Background compare + gdalcopyproj
 
  37           ((compare -quiet "${FILE_1}" "${FILE_2}" -compose Src -highlight-color Red -lowlight-color 'rgba(255,255,255,0)' -define tiff:tile-geometry=512x512 "${OSSV_DIFF_NAME}/${FILE}" || true) && python ${GDALCOPYPROJ} "${FILE_2}" "${OSSV_DIFF_NAME}/${FILE}" ) &
 
  39           # Check how many background processes and wait if exceed
 
  41           while [ ${#running[@]} -ge 16 ] ; do
 
  42             sleep 1   # this is not optimal, but you can't use wait here
 
  46       done < <(find "${OSSV_EDITIONS[$o]}" -maxdepth 1 -name '*.tif' -printf '%f\0')
 
  48       # Wait for background jobs to finish
 
  51       echo "Removing empty diffs"
 
  52       # TIF cleanup loop for images which have no diff
 
  53       while IFS= read -r -d $'\0' FILE; do
 
  54         ( FILE_COLOURS=$(identify -quiet -format '%k' "${OSSV_DIFF_NAME}/${FILE}")
 
  55         if [ "$FILE_COLOURS" -lt "2" ]; then
 
  56           rm -f "${OSSV_DIFF_NAME}/${FILE}"
 
  57           touch "${OSSV_DIFF_NAME}/${FILE}.skip"
 
  60         # Check how many background processes and wait if exceed
 
  62         while [ ${#running[@]} -ge 16 ] ; do
 
  63           sleep 1   # this is not optimal, but you can't use wait here
 
  66       done < <(find "${OSSV_DIFF_NAME}" -maxdepth 1 -name '*.tif' -size -180000c -printf '%f\0')
 
  67       # Wait for background jobs to finish
 
  69       if [ ! -f "ossv-${OSSV_DIFF_NAME}-combined.vrt" ]; then
 
  70         gdalbuildvrt -resolution highest -hidenodata "ossv-${OSSV_DIFF_NAME}-combined.vrt" ${OSSV_DIFF_NAME}/*.tif
 
  75 echo Now create external overview layers
 
  76 echo eg: gdaladdo --config GDAL_CACHEMAX=16000 -ro --config COMPRESS DEFLATE --config COMPRESS_OVERVIEW DEFLATE --config ZLEVEL 9 --config BIGTIFF_OVERVIEW IF_SAFER --config GDAL_TIFF_OVR_BLOCKSIZE 512 -r average ossv-2016-04-combined.vrt 4 16 64 256 1024 4096