-
Notifications
You must be signed in to change notification settings - Fork 4
Extended get-datafiles.sh to download high-res data #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| #!/bin/sh | ||
| #!/bin/bash | ||
|
|
||
| # get the SRTM data files and convert them for splat use | ||
|
|
||
|
|
@@ -18,23 +18,30 @@ TOPOFILEDIR=splat-datafiles/sdf/ | |
| # local hgt file archive | ||
| HGTFILEDIR=splat-datafiles/hgtzip/ | ||
|
|
||
| CONTINENT=$1 | ||
| case $CONTINENT in | ||
| North_America|South_America|Africa|Eurasia|Australia|Islands) | ||
| echo $CONTINENT | ||
| ;; | ||
| *) | ||
| echo "Invalid continent: $CONTINENT" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| SRTM2SDF_HD=srtm2sdf-hd | ||
| SRTM2SDF=srtm2sdf | ||
|
|
||
| INDEXFILE=`mktemp` | ||
| FILELIST=`mktemp` | ||
|
|
||
| INDEXURL="http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/${CONTINENT}/" | ||
| #URLs from where to fetch the tiles | ||
| SRTM3URL="http://dds.cr.usgs.gov/srtm/version2_1/SRTM3/" | ||
| SRTM1URL="http://e4ftl01.cr.usgs.gov/SRTM/SRTMGL1.003/2000.02.11/" | ||
|
|
||
| INDEXFILE=`mktemp` | ||
|
|
||
| if [ ! -x `which srtm2sdf` ]; then | ||
| #Default options: | ||
| USE_HIGHRES=false | ||
| SRTM2SDF_CMD=$SRTM2SDF | ||
|
|
||
| DIRECT_CONVERSION=false | ||
| CONTINENT=unknown | ||
| USE_LONRANGE=false | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two are unused?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, i forgot to delete them |
||
| USE_LATRANGE=false | ||
|
|
||
|
|
||
| # Check if all prerequisites are installed | ||
|
|
||
| if [ ! -x `which $SRTM2SDF` ]; then | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should check srtm2sdf-hd as well |
||
| echo "error: not found in path: srtm2sdf splat conversion utility" | ||
| exit 1 | ||
| fi | ||
|
|
@@ -59,36 +66,191 @@ if [ ! -x `which bzip2` ]; then | |
| exit 1 | ||
| fi | ||
|
|
||
| echo "getting index.." | ||
| wget -q -O - $INDEXURL | \ | ||
|
|
||
|
|
||
| function helptext { | ||
| cat <<EOF | ||
|
|
||
| Usage: $0 -c CONTINENT [-x XMIN-XMAX] [-d] [-r] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. -x doesn't appear anywhere below -c is only necessary if -r is unspecified. |
||
|
|
||
| -h display this helptext | ||
|
|
||
| -c CONTINENT | ||
| specify the continent to download | ||
| Valid options are: | ||
| North_America, South_America, Africa, | ||
| Eurasia, Australia, Islands | ||
|
|
||
| -r Download High Resolution SRTM data for use | ||
| with splat-hd. | ||
| The whole world will be downloaded, no | ||
| separation between continents! | ||
|
|
||
| -d Direct mode, do not store downloaded files, | ||
| this greatly reduces diskspace. | ||
| This continously converts the downloaded .hgt.zip files | ||
| to sdf files and delete all files exept the | ||
| resulting sdf file. | ||
| No resume possible if download process interrupted! | ||
|
|
||
|
|
||
| EOF | ||
| } | ||
|
|
||
| #Extract commandline options, see helptext for explanation | ||
| while getopts ":dc:rhx:y:" opt; do | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bashism |
||
| case $opt in | ||
| h) | ||
| helptext | ||
| exit 1 | ||
| ;; | ||
|
|
||
| d) | ||
| echo "DIRECT MODE: Directly converting *.hgt files, deleting zips" | ||
| DIRECT_CONVERSION=true | ||
| ;; | ||
| c) | ||
| CONTINENT=$OPTARG | ||
| echo "Continent set to $CONTINENT" | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Validation should be moved up here? |
||
| ;; | ||
| r) | ||
| USE_HIGHRES=true | ||
| echo "HIGH RESOLUTION: Using $SRTM2SDF_CMD instead of srtm2sdf" | ||
| ;; | ||
| \?) | ||
| echo "Invalid option: -$OPTARG" >&2 | ||
| helptext | ||
| exit 1 | ||
| ;; | ||
| :) | ||
| echo "Option -$OPTARG requires an argument." >&2 | ||
| helptext | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| #set url to download tiles from: | ||
| if [ "$USE_HIGHRES" = true ] | ||
| then | ||
| SRTM2SDF_CMD=$SRTM2SDF_HD | ||
|
|
||
| #unfortunately there is no listing per continent | ||
| INDEXURL=$SRTM1URL | ||
|
|
||
| else | ||
| case $CONTINENT in | ||
| North_America|South_America|Africa|Eurasia|Australia|Islands) | ||
| echo $CONTINENT | ||
| ;; | ||
| *) | ||
| echo "Invalid continent: $CONTINENT" | ||
| helptext | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| INDEXURL=${SRTM3URL}${CONTINENT}/ | ||
| fi | ||
|
|
||
|
|
||
|
|
||
| # Start to download tiles: | ||
| echo "getting index.. from $INDEXURL" | ||
| wget -q -O - $INDEXURL > $INDEXFILE | ||
|
|
||
| if [ "$USE_HIGHRES" = true ] | ||
| then | ||
| #random magic stolen from the internet | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this portable to posix sed? |
||
| grep -F '.hgt.zip<' $INDEXFILE | sed -e 's@.*href="@@g' -e 's/">.*//g' > $FILELIST | ||
| else | ||
| wget -q -O - $INDEXURL | \ | ||
| sed -r -e '/hgt.zip/!d; s/.* ([NSWE0-9]+\.?hgt\.zip).*$/\1/;' \ | ||
| > $INDEXFILE | ||
| > $FILELIST | ||
| fi | ||
|
|
||
| #cp $FILELIST ./filelist | ||
|
|
||
| mkdir -p $HGTFILEDIR | ||
| mkdir -p $TOPOFILEDIR | ||
|
|
||
| echo "retrieving files.." | ||
| cd $HGTFILEDIR | ||
| wget -nv -N -B $INDEXURL -i $INDEXFILE | ||
| cd - | ||
|
|
||
| rm $INDEXFILE | ||
|
|
||
| # to minimize disk space required, run srtm2sdf on each file as it is unzipped. | ||
| echo "retrieving files..." | ||
| FILECOUNT=`wc -l $FILELIST` | ||
| echo "Starting processing of ${FILECOUNT} Files" | ||
|
|
||
| #convert to absolute path because srtm2sdf does not accept output path arguments | ||
| HGTREALPATH=`readlink -f $HGTFILEDIR` | ||
| TOPOREALPATH=`readlink -f $TOPOFILEDIR` | ||
| PWD=`pwd` | ||
|
|
||
| for FILE in $(cat $FILELIST); do | ||
| echo "Downloading: ${FILE}" | ||
| if [ "$USE_HIGHRES" = true ]; then | ||
| HGTFILE=${FILE%SRTMGL1.hgt.zip}hgt | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bashism |
||
| else | ||
| HGTFILE=${FILE%.zip} | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bashism |
||
| fi | ||
|
|
||
| #download the tile | ||
| wget -P $HGTFILEDIR -nv -N $INDEXURL$FILE | ||
|
|
||
| #in direct conversion mode, directly make an sdf.bz2 and delete all downloaded files | ||
| if [ "$DIRECT_CONVERSION" = true ] ; then | ||
| echo "Unzip $FILE and then delete zip" | ||
| nice unzip -o $HGTFILEDIR/$FILE -d $TOPOFILEDIR | ||
| rm $HGTFILEDIR/$FILE | ||
|
|
||
|
|
||
| #only execute if file exists: | ||
| if [ -r $TOPOFILEDIR/$HGTFILE ]; then | ||
| echo "Convert $HGTFILE to SDF" | ||
| cd $TOPOFILEDIR | ||
| nice $SRTM2SDF_CMD -d /dev/null $HGTFILE | ||
| cd - | ||
| echo "compressing.." | ||
| #sadly i am too lazy to figure out srtm2sdf naming schemes | ||
| for SDF in $TOPOFILEDIR/*.sdf ; do | ||
| if test -f "$SDF" ; then | ||
| echo "Compress $SDF" | ||
| nice bzip2 -f -- $SDF | ||
| fi | ||
| done | ||
| echo "deleting hgt file $TOPOFILEDIR/$HGTFILE" | ||
| rm $TOPOFILEDIR/$HGTFILE | ||
| fi | ||
| fi | ||
|
|
||
| # TODO comment for prod: | ||
| #break; | ||
| done | ||
|
|
||
| #delete tempfiles | ||
| rm $INDEXFILE | ||
| rm $FILELIST | ||
|
|
||
|
|
||
|
|
||
| # Exit in direct conversion mode, because everything is done | ||
| if [ "$DIRECT_CONVERSION" = true ]; then | ||
| echo "Downloading finished, have fun!" | ||
| exit 0; | ||
| fi | ||
|
|
||
|
|
||
| #Conventional processing after all tiles are downloaded | ||
| # to minimize disk space required, run srtm2sdf on each file as it is unzipped. | ||
| echo "unpacking hgt files.." | ||
| cd $HGTFILEDIR | ||
| for e in *.zip ; do | ||
| echo $e | ||
| nice unzip -o $e | ||
| HGTFILE=`echo $e | sed -r -e 's/\.?hgt.zip/.hgt/'` | ||
| if [ "$USE_HIGHRES" = true ]; then | ||
| HGTFILE=${FILE%SRTMGL1.hgt.zip}hgt | ||
| else | ||
| HGTFILE=${FILE%.zip} | ||
| fi | ||
| if [ -r $HGTFILE ]; then | ||
| cd $TOPOREALPATH | ||
| nice srtm2sdf -d /dev/null $HGTREALPATH/$HGTFILE | ||
| nice $SRTM2SDF_CMD -d /dev/null $HGTREALPATH/$HGTFILE | ||
| echo "compressing.." | ||
| nice bzip2 -f -- *.sdf | ||
| echo "deleting hgt file.." | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been target bourne shell for portability to the BSDs and OSX as well.