[GRASS-SVN] r31813 - in grass-addons/general: . g.region.site

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 23 04:46:23 EDT 2008


Author: hamish
Date: 2008-06-23 04:46:23 -0400 (Mon, 23 Jun 2008)
New Revision: 31813

Added:
   grass-addons/general/g.region.site/
   grass-addons/general/g.region.site/Makefile
   grass-addons/general/g.region.site/description.html
   grass-addons/general/g.region.site/g.region.point
Removed:
   grass-addons/general/g.region.site/
Log:
cleanup dir mess

Added: grass-addons/general/g.region.site/Makefile
===================================================================
--- grass-addons/general/g.region.site/Makefile	                        (rev 0)
+++ grass-addons/general/g.region.site/Makefile	2008-06-23 08:46:23 UTC (rev 31813)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = g.region.point
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/general/g.region.site/description.html
===================================================================
--- grass-addons/general/g.region.site/description.html	                        (rev 0)
+++ grass-addons/general/g.region.site/description.html	2008-06-23 08:46:23 UTC (rev 31813)
@@ -0,0 +1,72 @@
+<H2>DESCRIPTION</H2>
+
+<EM>g.region.point</EM> resets the computational region to a square box
+around a given coordinate at the current resolution. It is intended for
+use within GRASS scripts to speed up processing by focusing expensive
+raster calculations onto a small area of interest.
+
+
+<H2>NOTES</H2>
+
+To preserve the original region settings this module should generally
+be used in tandem with the <tt>WIND_OVERRIDE</tt> environment variable.
+
+<P>
+If the new region bounds do not line up with a multiple of the map resolution
+the bounds will be extended outwards, preserving the region resolution.
+<P>
+If the <b>-z</b> flag is used, then in the case of a bounds/resolution
+incompatibility the resolution will be altered and the region bounds
+preserved. The <b>-z</b> flag requires that a value is given for the
+<b>resolution</b> option.
+
+
+<h2>EXAMPLE</H2>
+
+Evaluate the mean value in a 100m wide raster buffer around a series of
+vector points.
+
+<!-- it is unclear to me if the "clone current region" step is actually needed -->
+<div class="code"><pre>
+  # Spearfish dataset
+
+  # clone current region
+  g.region save="tmp_region.$$"
+
+  # set temporary region storage
+  WIND_OVERRIDE="tmp_region.$$"
+  export WIND_OVERRIDE
+
+  # create list of starting coordinates
+  POINTS=`v.out.ascii archsites | cut -f1,2 -d'|' | tr '|' ','`
+
+  # run the processing loop
+  for POINT in $POINTS ; do
+     g.region.point coord="$POINT" diam=150 res=10
+     r.circle -b coord=$POINT max=100 out=MASK --quiet
+     eval `r.univar -g elevation.10m`
+     g.remove MASK --quiet
+     echo "coord=$POINT  mean=$mean (n=$n)"
+  done
+
+  # remove the temporary region
+  unset WIND_OVERRIDE
+  g.remove region="tmp_region.$$" --quiet
+</pre></div>
+
+
+<H2>SEE ALSO</H2>
+<EM>
+<A HREF="g.region.html">g.region</A>,
+<A HREF="v.rast.stats.html">v.rast.stats</A>
+</EM><BR>
+<A HREF="variables.html">GRASS Variables</A>
+
+
+<H2>AUTHOR</H2>
+
+Hamish Bowman, Dunedin, New Zealand
+<BR>
+
+<p>
+<i>Last changed: $Date$</i>

Added: grass-addons/general/g.region.site/g.region.point
===================================================================
--- grass-addons/general/g.region.site/g.region.point	                        (rev 0)
+++ grass-addons/general/g.region.site/g.region.point	2008-06-23 08:46:23 UTC (rev 31813)
@@ -0,0 +1,98 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       g.region.point
+# AUTHOR:       Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Sets the region tightly at a fixed point (to speed up raster
+#                 calcs around fixed points)
+#
+# COPYRIGHT:    (c) 2008 Hamish Bowman, and 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: Sets the computational region at a fixed distance around a point.
+#%  keywords: region
+#%End
+#%option
+#%  key: coord
+#%  type: double
+#%  key_desc: x,y
+#%  description: Coordinate at center of region 
+#%  required: yes
+#%end
+#%option
+#%  key: diameter
+#%  type: double
+#%  description: Region box diameter
+#%  required: yes
+#%end
+#%option
+#%  key: resolution
+#%  type: double
+#%  description: New map resolution to use
+#%  required: no
+#%end
+#%flag
+#%  key: p
+#%  description: Print the new region bounds
+#%end
+#%flag
+#%  key: g
+#%  description: Print the new region bounds in shell script style
+#%end
+#%flag
+#%  key: z
+#%  label: Preserve bounds in case of bounds/resolution mismatch
+#%  description: Requires resolution option; default is to preserve resolution and grow bounds outwards.
+#%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
+
+
+COOR_E=`echo "$GIS_OPT_COORD" | cut -f1 -d,`
+COOR_N=`echo "$GIS_OPT_COORD" | cut -f2 -d,`
+DIAM="$GIS_OPT_DIAMETER"
+
+N=`awk "BEGIN {print $COOR_N + $DIAM}"`
+S=`awk "BEGIN {print $COOR_N - $DIAM}"`
+W=`awk "BEGIN {print $COOR_E - $DIAM}"`
+E=`awk "BEGIN {print $COOR_E + $DIAM}"`
+
+
+
+if [ "$GIS_FLAG_Z" -eq 1 ] ; then
+   REG_ALIGN=""
+else
+   REG_ALIGN="-a"
+fi
+if [ -n "$GIS_OPT_RESOLUTION" ] ; then
+   REG_RES="res=$GIS_OPT_RESOLUTION $REG_ALIGN"
+else
+   REG_RES=""
+fi
+
+
+if [ "$GIS_FLAG_P" -eq 1 ] ; then
+   REG_PRINT="-p"
+else
+   REG_PRINT=""
+fi
+if [ "$GIS_FLAG_G" -eq 1 ] ; then
+   REG_PRINT="-g"
+fi
+
+
+g.region n="$N" s="$S" w="$W" e="$E" $REG_RES $REG_PRINT
+



More information about the grass-commit mailing list