Created
November 5, 2017 17:46
-
-
Save sudokai/29d07578132fbb5dc6d55a49c970dd0f to your computer and use it in GitHub Desktop.
Convert a directory of .bil files to .hgt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function gdal_pixel_count() { | |
if [ -z "$1" ]; then | |
echo "Missing arguments. Syntax:" | |
echo " gdal_extent <input_raster>" | |
return | |
fi | |
EXTENT=$(gdalinfo $1 |\ | |
grep "Size is" |\ | |
sed "s/Size is //g;s/,//;s/\n//") | |
echo -n "$EXTENT" | |
} | |
TARGET_SIZE="3601 3601" | |
for i in *.bil; do | |
SOURCE_NAME=`echo $i | cut -d _ -f 1,2 | sed 's/_//' | tr '[:lower:]' '[:upper:]'` | |
DEST_FILE=$SOURCE_NAME.hgt | |
echo $url $DEST_FILE | |
if [ -e $DEST_FILE ]; then | |
echo $DEST_FILE exists, skipping | |
continue | |
fi | |
PIXEL_COUNT=`gdal_pixel_count $i` | |
if [ "$PIXEL_COUNT" != "$TARGET_SIZE" ]; then | |
echo bad size $PIXEL_COUNT | |
fi | |
gdal_translate -outsize $TARGET_SIZE -of SRTMHGT $i $DEST_FILE | |
if [ -e $DEST_FILE.aux.xml ] | |
then | |
rm $DEST_FILE.aux.xml | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment