process-LCzip.sh 1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash

set -u
set -e

WMSUPLOAD=/home/eodn/eodn2realearth/src/wmsupload
SCENE=$1

YEAR=${SCENE:9:4}
DOY=${SCENE:13:3}
YMD=`date -d "Jan 1 $YEAR + $DOY days - 1 day" "+%Y%m%d"`
PART=${SCENE:2:7}

BASE=${SCENE##*/} # filename w/ extension
STRIP=${BASE%%.zip} # filename w/o extension

TMP=tmp
mkdir -p $TMP
unzip $SCENE -d $TMP
cd $TMP

sed -i s:\&quot\;:\":g *.aux.xml # swap " for actual quotes

for REF in "" _QB _TIR; do
  case $REF in
    _QB )
      IMG=${STRIP}${REF}.png
      TAG=QB
      ;;
    _TIR )
      IMG=${STRIP}${REF}.jpg
      TAG=TIR
      ;;
    "" )
      IMG=${STRIP}${REF}.jpg
      TAG=FC
      ;;
  esac

  if [ ! -f $IMG ]; then  # some zips don't have all the image types - skip any that don't exist
    continue
  fi

  grep SRS ${IMG}.aux.xml > WKT # extract the WKT line from XML
  sed -i s:\ \ \<SRS\>::g WKT # remove XML tags from WKT
  sed -i s:\<\/SRS\>::g WKT

  TIF=EODN-${TAG}_${YMD}_120000.part${PART}.tif

  gdal_translate -of GTiff -a_srs WKT $IMG $TIF
  $WMSUPLOAD $TIF
done