[GRASS-SVN] r31389 - in grass-addons/display: . d.region
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat May 17 11:53:49 EDT 2008
Author: jachym
Date: 2008-05-17 11:53:48 -0400 (Sat, 17 May 2008)
New Revision: 31389
Added:
grass-addons/display/d.region/
grass-addons/display/d.region/d.region
Log:
New addon added: d.region
Added: grass-addons/display/d.region/d.region
===================================================================
--- grass-addons/display/d.region/d.region (rev 0)
+++ grass-addons/display/d.region/d.region 2008-05-17 15:53:48 UTC (rev 31389)
@@ -0,0 +1,282 @@
+#!/bin/sh
+
+############################################################################
+#
+# MODULE: d.region
+# AUTHOR(S): Hamish Bowman, Jachym Cepicky
+# PURPOSE: Draw selected region into current display
+# COPYRIGHT: (C) 2007 by the GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+############################################################################
+
+#%Module
+#% description: Draw desired region into current display
+#% keywords: display, region
+#%End
+#%flag
+#% key: d
+#% description: Draw default region
+#%END
+#%flag
+#% key: c
+#% description: Draw current region
+#%END
+#%flag
+#% key: f
+#% description: Non-persistant box (doesn't survive redraw or zoom)
+#%END
+#%option
+#% key: name
+#% type: string
+#% description: Region name
+#% required : no
+#%end
+#%option
+#% key: color
+#% type: string
+#% description: Color to draw with, either a standard GRASS color or R:G:B triplet
+#% answer: black
+#% required : no
+#%end
+#%option
+#% key: width
+#% type: integer
+#% description: Line width
+#% answer: 1
+#% required : no
+#%end
+#%option
+#% key: rast
+#% type: string
+#% description: Draw region to match this raster map
+#% required : no
+#%end
+#%option
+#% key: rast3d
+#% type: string
+#% description: Draw region to match this 3D raster map
+#% required : no
+#%end
+#%option
+#% key: vect
+#% type: string
+#% description: Draw region to match this vector map
+#% required : no
+#%end
+#%option
+#% key: 3dview
+#% type: string
+#% description: Draw region to match this 3dview file
+#% required : no
+#%end
+#%option
+#% key: n
+#% type: double
+#% description: Value for the northern edge
+#% required : no
+#%end
+#%option
+#% key: s
+#% type: double
+#% description: Value for the southern edge
+#% required : no
+#%end
+#%option
+#% key: e
+#% type: double
+#% description: Value for the eastern edge
+#% required : no
+#%end
+#%option
+#% key: w
+#% type: double
+#% description: Value for the western edge
+#% required : no
+#%end
+
+if test "$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
+
+
+# set defaults
+originalRegionName="d_region"$$
+g.region save=$originalRegionName
+
+
+
+#####################
+# name: clean
+# purpose: clean region settings
+clean () {
+ g.region region=$originalRegionName;
+ g.remove --q region=$originalRegionName;
+}
+
+#####################
+# name: default
+# purpose: displays default region
+default () {
+ g.region -d
+ eval `g.region -g`
+}
+
+#####################
+# name: current
+# purpose: displays default region
+current () {
+ eval `g.region -g`
+}
+
+#####################
+# name: raster
+# purpose: displays raster region
+raster () {
+ g.region rast=$GIS_OPT_RAST
+ eval `g.region -g`
+}
+
+#####################
+# name: vector
+# purpose: displays vect region
+vector () {
+ g.region vect=$GIS_OPT_VECT
+ eval `g.region -g`
+}
+#####################
+# name: rast3d
+# purpose: displays rast3d region
+rast3d () {
+ g.region rast3d=$GIS_OPT_RAST3D
+ eval `g.region -g`
+}
+
+#####################
+# name: 3dview
+# purpose: displays 3dview region
+view3d () {
+ g.region rast3d=$GIS_OPT_3DVIEW
+ eval `g.region -g`
+}
+
+#####################
+# name: region
+# purpose: displays region
+region () {
+ error=''
+ if [ -z "$GIS_OPT_N" ]; then
+ g.message -e "parameter <n> not set"
+ error=1
+ fi
+ if [ -z "$GIS_OPT_S" ]; then
+ g.message -e "parameter <s> not set"
+ error=1
+ fi
+ if [ -z "$GIS_OPT_E" ]; then
+ g.message -e "parameter <e> not set"
+ error=1
+ fi
+ if [ -z "$GIS_OPT_W" ]; then
+ g.message -e "parameter <w> not set"
+ error=1
+ fi
+
+ if [ -n "$error" ]; then
+ clean
+ exit 1
+ fi
+
+ g.region w=$GIS_OPT_W s=$GIS_OPT_S e=$GIS_OPT_E n=$GIS_OPT_N
+ eval `g.region -g`
+}
+
+
+
+#####################
+# name: draw
+# purpose: displays region
+draw () {
+
+ # setup temporary file
+ TMP="`g.tempfile pid=$$`"
+ if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+ g.message -e "unable to create temporary files"
+ exit 1
+ fi
+
+ cat << EOF >> "$TMP"
+width $GIS_OPT_WIDTH
+polyline
+$w $s
+$w $n
+$e $n
+$e $s
+$w $s
+EOF
+
+ echo $TMP
+
+ if [ $GIS_FLAG_F -eq 1 ]; then
+ cat $TMP|d.graph -m color=$GIS_OPT_COLOR
+ else
+ d.graph -m color=$GIS_OPT_COLOR input=$TMP
+ fi
+
+}
+
+# in case of problems or user break:
+trap 'clean ; exit 1' 2 3 15
+
+# main code
+
+regionFunction=""
+
+if [ $GIS_FLAG_C -eq 1 ] ; then
+ regionFunction="current"
+
+fi
+if [ $GIS_FLAG_D -eq 1 ] ; then
+ regionFunction="default"
+
+fi
+
+if [ -n "$GIS_OPT_RAST" ] ; then
+ regionFunction="raster"
+
+fi
+
+if [ -n "$GIS_OPT_VECT" ] ; then
+ regionFunction="vector"
+
+fi
+
+if [ -n "$GIS_OPT_RAST3D" ] ; then
+ regionFunction="rast3d"
+
+fi
+
+if [ -n "$GIS_OPT_3DVIEW" ] ; then
+ regionFunction="view3d"
+
+fi
+
+if [ -n "$GIS_OPT_N" ] ; then
+ regionFunction="region"
+
+fi
+
+$regionFunction
+draw
+
+# end clean up
+clean
+exit 0
More information about the grass-commit
mailing list