-
-
Save palmerj/75b910ba27ba7c38c1fb2b63e87362b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
FILE_IN= | |
file_name=$( basename $FILE_IN | sed 's/.tif//' ) | |
output_dir= | |
div | |
function gdal_extent_gdalwarp_te() { | |
if [ -z "$1" ]; then | |
echo "Missing arguments. Syntax:" | |
echo " gdal_extent <input_raster>" | |
return | |
fi | |
EXTENT=$(gdalinfo "$1" |\ | |
grep "Lower Left\|Upper Right" |\ | |
sed "s/Lower Left //g;s/Upper Right //g;s/).*//g" |\ | |
#tr "\n" " " |\ | |
sed 's/ *$/ /g' |\ | |
tr -d "\n[(]'"|\ | |
sed 's/,/ /g') | |
echo -n "$EXTENT" | |
} | |
echo $FILE_IN | |
ExtractedExtent=$(gdal_extent_gdalwarp_te "${FILE_IN}") | |
echo $ExtractedExtent | |
set -- $ExtractedExtent | |
echo "flip extent (ulx uly lrx lry) = "$1 $4 $3 $2 | |
ulx_init=$1 | |
uly=$4 | |
lrx=$3 | |
lry=$2 | |
width=$( bc <<< 'scale=3; (-1*'$ulx_init')+'$lrx'' ) | |
echo $width | |
width_div=$( bc <<< 'scale=3; '$width'/6' ) | |
echo "width divided by 6 = "$width_div | |
height=$( bc <<< 'scale=3; ('$uly')+(-1*'$lry')' ) | |
echo $height | |
height_div=$( bc <<< 'scale=3; '$height'/6' ) | |
echo "height divided by 6 = "$height_div | |
for j in {1..6} | |
do | |
ulx=$ulx_init | |
echo "uly= "$uly | |
lry=$( bc <<< 'scale=3; '$uly'-('$height_div')' ) | |
echo "lry= "$lry | |
for i in {1..6} | |
do | |
echo $i | |
echo $ulx | |
lrx=$( bc <<< 'scale=3; '$ulx'+('$width_div')' ) | |
echo $ulx $lrx | |
echo $i | |
echo $uly | |
echo $uly $lry | |
extent=$(echo $ulx $uly $lrx $lry) | |
echo "Extent = "$extent | |
gdal_translate -of GTiff -projwin $extent $FILE_IN $output_dir/${file_name}_${i}${j}.tif | |
gdaldem hillshade -multidirectional -z 5 $output_dir/${file_name}_${i}${j}.tif $output_dir/hs/${file_name}_${i}${j}_HS.tif | |
ulx=$lrx | |
echo "ulx = "$ulx | |
#uly=$lry | |
#echo "uly = " $uly | |
done | |
uly=$lry | |
echo "uly= "$uly | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment