[GRASS-SVN] r56465 - grass-addons/grass6/raster/r.rot90

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 29 04:57:57 PDT 2013


Author: hamish
Date: 2013-05-29 04:57:57 -0700 (Wed, 29 May 2013)
New Revision: 56465

Added:
   grass-addons/grass6/raster/r.rot90/r.rot90
Log:
... and the script

Added: grass-addons/grass6/raster/r.rot90/r.rot90
===================================================================
--- grass-addons/grass6/raster/r.rot90/r.rot90	                        (rev 0)
+++ grass-addons/grass6/raster/r.rot90/r.rot90	2013-05-29 11:57:57 UTC (rev 56465)
@@ -0,0 +1,133 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.rot90
+# AUTHOR(S):    M. Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Rotate a raster map 90 degrees (transpose the array)
+#
+# COPYRIGHT:    (c) 2013 Hamish Bowman, and the GRASS Development Team
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 2 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+############################################################################
+
+# TODO: Try numpy/sci instead of Octave as it's a bit more common
+#	See also src/misc/m.rot90 in GRASS 5 for a C version (binary data)
+
+#%Module
+#% description: Rotates a GRASS raster by 90 degrees clockwise.
+#% keywords: raster
+#%End
+#%Option
+#% key: input
+#% type: string
+#% required: yes
+#% key_desc: name
+#% description: Name of input raster map
+#% gisprompt: old,cell,raster
+#%End
+#%Option
+#% key: output
+#% type: string
+#% required: no
+#% label: Name for output raster map
+#% description: If not given will be input map + ".rot90"
+#% gisprompt: new,cell,raster
+#%End
+
+
+if [ -z "$GISBASE" ] ; then
+    echo "You must be in GRASS GIS to run this program." 1>&2
+    exit 1
+fi
+
+if [ "$1" != "@ARGS_PARSED@" ] ; then
+    exec g.parser "$0" "$@"
+fi
+
+#### check if we have octave
+if [ ! -x "`which octave`" ] ; then
+    g.message -e "Octave is required, please install it first"
+    exit 1
+fi
+
+
+cleanup()
+{
+   rm -f "$TEMPFILE" "${TEMPFILE}_"*
+}
+
+# what to do in case of user break:
+exitprocedure()
+{
+   g.message -e 'User break!'
+   cleanup
+   exit 1
+}
+# shell check for user break (signal list: trap -l)
+trap "exitprocedure" 2 3 15
+
+
+TEMPFILE="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TEMPFILE" ] ; then
+    g.message -e "Unable to create temporary files"
+    exit 1
+fi
+
+INFILE="$GIS_OPT_INPUT"
+if [ -z "$GIS_OPT_OUTPUT" ] ; then
+   OUTFILE="$GIS_OPT_INPUT.rot90"
+else
+   OUTFILE="$GIS_OPT_OUTPUT"
+fi
+
+if [ -z "$GRASS_VERBOSE" ] ; then
+   GRASS_VERBOSE=1
+   export GRASS_VERBOSE
+fi
+
+r.out.mat in="$INFILE" out="${TEMPFILE}_notrot.mat"
+
+# set up the processing script
+cat << EOF > "${TEMPFILE}_rot90.m"
+% r.rot90 script to rotate a raster array
+load '${TEMPFILE}_notrot.mat' 
+map_data = fliplr(map_data');  %'
+
+% rotate bounds. N-S becomes backwards
+oldNedge = map_northern_edge;
+oldSedge = map_southern_edge;
+map_northern_edge = map_eastern_edge;
+map_southern_edge = map_western_edge;
+map_eastern_edge = oldNedge;
+map_western_edge = oldSedge;
+clear oldNedge oldSedge
+
+map_title = [map_name ' rotated 90 degrees'];
+map_name = 'tmp_rot90';
+save -mat4-binary '${TEMPFILE}_rot.mat' map_*
+EOF
+
+octave --no-init-file --quiet "${TEMPFILE}_rot90.m"
+
+if [ $? -ne 0 ] ; then
+   g.message "Octave had a problem. Aborting."
+   cleanup
+   exit 1
+fi
+
+r.in.mat in="${TEMPFILE}_rot.mat" out="$OUTFILE"
+
+if [ $? -eq 0 ] ; then
+   r.colors "$OUTFILE" rast="$INFILE" --quiet
+fi
+
+cleanup


Property changes on: grass-addons/grass6/raster/r.rot90/r.rot90
___________________________________________________________________
Added: svn:executable
   + *
Added: svn:mime-type
   + text/x-sh
Added: svn:eol-style
   + native



More information about the grass-commit mailing list