[GRASS-SVN] r30142 - grass-addons/imagery/i.warp

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 14 01:00:53 EST 2008


Author: hamish
Date: 2008-02-14 01:00:53 -0500 (Thu, 14 Feb 2008)
New Revision: 30142

Added:
   grass-addons/imagery/i.warp/i.warp
Log:
rename i.warp addon script

Copied: grass-addons/imagery/i.warp/i.warp (from rev 30140, grass-addons/imagery/i.warp/i.warp61)
===================================================================
--- grass-addons/imagery/i.warp/i.warp	                        (rev 0)
+++ grass-addons/imagery/i.warp/i.warp	2008-02-14 06:00:53 UTC (rev 30142)
@@ -0,0 +1,130 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE:       i.warp
+#
+# AUTHOR(S):    Hamish Bowman
+#               Department of Marine Science
+#               Otago University, New Zealand
+#               3 June 2005
+#
+# PURPOSE:      Use GCPs from i.points to run gdalwarp using splines
+#
+# COPYRIGHT:    (c) Hamish Bowman
+#
+#############################################################################
+#
+# REQUIREMENTS:
+#       gdalwarp from the GDAL package.   http://www.gdal.org
+#     xx  GRASS 6.1-cvs newer than 1 June 2005
+#
+
+#%Module
+#%  description: Georectify an image using thin plate splines
+#%End
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old_file,file,input
+#% description: Name of input image (JPEG, TIFF, etc.)
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new_file,file,output
+#% description: Name for georeferenced and warped GeoTIFF
+#% required : yes
+#%end
+#%option
+#% key: group
+#% type: string
+#% gisprompt: old,group,group
+#% description: Name of imagery group containing GCPs
+#% required : yes
+#%end
+
+if [ -z "$GISBASE" ] ; then
+   echo "You must be in GRASS GIS to run this program." >&2
+   exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+   exec g.parser "$0" "$@"
+fi
+
+#### check if we have awk
+if [ ! -x "`which awk`" ] ; then
+    echo "$PROG: awk required, please install awk or gawk first" 1>&2
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+
+INFILE="$GIS_OPT_input"
+OUTFILE="`basename $GIS_OPT_output .tif`.tif"
+GROUP="$GIS_OPT_group"
+
+if [ ! -e "$INFILE" ] ; then
+    echo "ERROR: unable to read input file." 1>&2
+    exit 1
+fi
+if [ -e "$OUTFILE" ] ; then
+    echo "ERROR: output file already exists." 1>&2
+    exit 1
+fi
+
+
+eval `g.filename elem=group file=${GROUP}/POINTS`
+POINTS_FILE="$file"
+
+if [ ! -e "$POINTS_FILE" ] ; then
+    echo "ERROR: unable to read POINTS file. Run i.points first." 1>&2
+    exit 1
+fi
+
+#### setup temporary file
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    echo "ERROR: unable to create temporary files" 1>&2
+    exit 1
+fi
+
+DIMS="`gdalinfo "$INFILE" | grep '^Lower Right' | cut -f2 -d'(' | \
+    cut -f1 -d')' |  tr ',' ' '`"
+WIDTH="`echo $DIMS | cut -f1 -d' '`"
+HEIGHT="`echo $DIMS | cut -f2 -d' '`"
+
+## BUG: GCPs need to be sorted top to bottom!!  (??????)
+GDAL_GCP="`cat "$POINTS_FILE" | grep -v '^#'| grep -v '0$' | sort -n -r --key=2 | \
+    awk -v hgt=$HEIGHT -v wth=$WIDTH \
+      '{printf("-gcp %.3f %.3f %f %f ", $1, hgt - $2, $3, $4)}'`"
+
+
+echo $GDAL_GCP | sed -e 's/-gcp/\ngcp/g' -e 's/ /\t/g'
+echo
+
+echo "Adding GCPs ..."
+gdal_translate $GDAL_GCP "$INFILE" "$TMP".tif
+
+sleep 1
+echo "Rectifying ..."
+## BUG: outfile name needs to be at least 20 chars long!!
+gdalwarp -tps -rcs -co compress=lzw "$TMP".tif "$OUTFILE"_warp_warp_warp_warp
+#gdalwarp -tps -rcs -co compress=lzw -srcnodata 255 -dstnodata 255 "$TMP".tif "$OUTFILE"_warp_warp_warp_warp
+
+
+sleep 1
+mv "$OUTFILE"_warp_warp_warp_warp "$OUTFILE"
+
+rm -f "$TMP".tif "$TMP"
+
+echo "Done!"
+
+echo ""
+echo "In target location:  r.in.gdal -o input=$OUTFILE output=`basename $OUTFILE .tif`"



More information about the grass-commit mailing list