Skip to content

Instantly share code, notes, and snippets.

@stoermerjp
Created July 12, 2012 13:30
Show Gist options
  • Save stoermerjp/3098104 to your computer and use it in GitHub Desktop.
Save stoermerjp/3098104 to your computer and use it in GitHub Desktop.
DroneMapper.com: Basic Geo-referenced Mosaic Construction w/ GDAL (projection)
#!/bin/bash
###
### JP Stoermer
### DroneMapper.com
###
### Clean up
rm -rf ./*._tif
rm -rf ./mosaic.tif
rm -rf ./mosaic.vrt
rm -rf ./mosaic.png
ARG1=$1
WATERMARKS=$2
### Rename JPGW if needed
for FILE in ./*.JPGw ; do NEWFILE=`echo $FILE | sed 's/.JPGw$/.jpgw/'` ; mv $FILE $NEWFILE ; done
### Find UTM Zone from JPGW
UTMZONE=`cat ./*.jpgw | grep UTM | awk -F" " {'print $4'} | head -1`
### Build GeoTIF
for FILE in ./*.JPG ; do NEWFILE=`echo $FILE | sed 's/.JPG$/._tif/'` ; /usr/bin/gdalwarp -t_srs "+proj=utm +zone=$UTMZONE +datum=WGS84" -wo "SKIP_NOSOURCE=yes" -r bilinear -dstnodata 255 $FILE $NEWFILE; done
### Build VRT
/usr/bin/gdalbuildvrt -resolution $ARG1 ./mosaic.vrt ./*._tif
### Build Final Mosaic
/usr/bin/gdalwarp -t_srs "+proj=utm +zone=$UTMZONE +datum=WGS84" -wo "SKIP_NOSOURCE=yet" -dstnodata 255 -r bilinear ./mosaic.vrt ./mosaic.tif
### Scale and Convert to PNG
convert ./mosaic.tif -transparent white -scale 5% ./mosaic.png
if [ $WATERMARKS == "watermarks" ]
then
composite -gravity center -dissolve 25 /www/html/files/dm_watermark_small.png ./mosaic.png ./mosaic.png
composite -dissolve 25 -tile /www/html/files/dm_watermark.png ./mosaic.tif ./mosaic.tif
fi
rm -rf ./*._tif
rm -rf ./mosaic.vrt
@andykorth
Copy link

I think "SKIP_NOSOURCE=yet" should be "SKIP_NOSOURCE=YES"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment