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 # TIF cleanup loop for images which have no diff
52 while IFS= read -r -d $'\0' FILE; do
53 ( FILE_COLOURS=$(identify -quiet -format '%k' "${OSSV_DIFF_NAME}/${FILE}")
54 if [ "$FILE_COLOURS" -lt "2" ]; then
55 rm -f "${OSSV_DIFF_NAME}/${FILE}"
56 touch "${OSSV_DIFF_NAME}/${FILE}.skip"
59 # Check how many background processes and wait if exceed
61 while [ ${#running[@]} -ge 16 ] ; do
62 sleep 1 # this is not optimal, but you can't use wait here
65 done < <(find "${OSSV_DIFF_NAME}" -maxdepth 1 -name '*.tif' -size -180000c -printf '%f\0')
69 echo Now create the VRT and external overview layers
70 echo 1: gdalbuildvrt -resolution highest -hidenodata diffXYZ.vrt diff/*.tif
71 echo 2: 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