Skip to content

Instantly share code, notes, and snippets.

@palmerj
Forked from IReese/gebco_png_to_tif.sh
Created July 3, 2020 04:24
Show Gist options
  • Save palmerj/481391c5ed3dc65c92d70ed16c5078b9 to your computer and use it in GitHub Desktop.
Save palmerj/481391c5ed3dc65c92d70ed16c5078b9 to your computer and use it in GitHub Desktop.
#!/bin/bash
xmlfile=/gebco_template.xml
base_file=$1
export_dir=
export_png=
export_xml=
file_name=$( basename $base_file | sed 's/.tif//' )
echo $file_name
cat $xmlfile | sed -e "s/FILENAME/"${file_name}"/g" > $export_xml/${file_name}.xml
png_file=$export_png/${file_name}.png
echo $png_file
#png_file=$export_dir/${file_name}_NIWA_BLEND_forSENTINEL.png
nik2img.py $export_xml/${file_name}.xml $png_file --no-open -f PNG -d 9712 12840
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"
}
ExtractedExtent=$(gdal_extent_gdalwarp_te "${base_file}")
echo $ExtractedExtent
set -- $ExtractedExtent
flipextract=$( echo $1 $4 $3 $2 )
#flipextract=$( echo $1 $2 $3 $4 )
echo $flipextract
gdal_translate -of GTiff -a_srs epsg:3857 -a_ullr $flipextract $png_file $export_dir/${file_name}_fromPNG_to_tif.tif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment