[GRASS-SVN] r30949 - in grass-addons/raster: . r.in.xyz.auto

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Apr 12 04:59:02 EDT 2008


Author: hamish
Date: 2008-04-12 04:58:57 -0400 (Sat, 12 Apr 2008)
New Revision: 30949

Added:
   grass-addons/raster/r.in.xyz.auto/
   grass-addons/raster/r.in.xyz.auto/r.in.xyz.auto
Log:
script to automatically set bounds for importing r.in.xyz data

Added: grass-addons/raster/r.in.xyz.auto/r.in.xyz.auto
===================================================================
--- grass-addons/raster/r.in.xyz.auto/r.in.xyz.auto	                        (rev 0)
+++ grass-addons/raster/r.in.xyz.auto/r.in.xyz.auto	2008-04-12 08:58:57 UTC (rev 30949)
@@ -0,0 +1,205 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       r.in.xyz.auto
+# AUTHOR:       M. Hamish Bowman, Dunedin, New Zealand
+# PURPOSE:      Automate r.in.xyz
+#
+# COPYRIGHT:    (c) 2007 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.
+#
+#		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.
+#
+#############################################################################
+
+#%Module
+#% description: Imports aggregate XYZ data using extent scanned from input file.
+#% keywords: raster, import
+#%End
+#%Option
+#% key: input
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: ASCII file containing input data
+#% gisprompt: old_file,file,input
+#%End
+#%Option
+#% key: output
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name for output raster map
+#% gisprompt: new,cell,raster
+#%End
+#%Option
+#% key: method
+#% type: string
+#% required: no
+#% multiple: no
+#% options: n,min,max,range,sum,mean,stddev,variance,coeff_var,median,percentile,skewness,trimmean
+#% description: Statistic to use for raster values
+#% answer: mean
+#% guisection: Statistic
+#%End
+#%Option
+#% key: res
+#% type: string
+#% required: no
+#% multiple: no
+#% description: Grid resolution for output map (both north-south and east-west)
+#%End
+#%Option
+#% key: type
+#% type: string
+#% required: no
+#% multiple: no
+#% options: CELL,FCELL,DCELL
+#% description: Storage type for resultant raster map
+#% answer: FCELL
+#%End
+#%Option
+#% key: fs
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: character
+#% description: Field separator
+#% answer: |
+#% guisection: Input
+#%End
+#%Option
+#% key: x
+#% type: integer
+#% required: no
+#% multiple: no
+#% description: Column number of x coordinates in input file (first column is 1)
+#% answer: 1
+#% guisection: Input
+#%End
+#%Option
+#% key: y
+#% type: integer
+#% required: no
+#% multiple: no
+#% description: Column number of y coordinates in input file
+#% answer: 2
+#% guisection: Input
+#%End
+#%Option
+#% key: z
+#% type: integer
+#% required: no
+#% multiple: no
+#% description: Column number of data values in input file
+#% answer: 3
+#% guisection: Input
+#%End
+#%Option
+#% key: zrange
+#% type: double
+#% required: no
+#% multiple: no
+#% key_desc: min,max
+#% description: Filter range for z data (min,max)
+#%End
+#%Option
+#% key: percent
+#% type: integer
+#% required: no
+#% multiple: no
+#% options: 1-100
+#% description: Percent of map to keep in memory
+#% answer: 100
+#%End
+#%Option
+#% key: pth
+#% type: integer
+#% required: no
+#% multiple: no
+#% options: 1-100
+#% description: pth percentile of the values
+#% guisection: Statistic
+#%End
+#%Option
+#% key: trim
+#% type: double
+#% required: no
+#% multiple: no
+#% options: 0-50
+#% description: Discard <trim> percent of the smallest and <trim> percent of the largest observations
+#% guisection: Statistic
+#%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
+
+
+if [ ! -e "$GIS_OPT_INPUT" ] ; then
+    echo "Input file not found." 1>&2
+    exit 1
+fi
+
+
+if [ -z "$GIS_OPT_RES" ] ; then
+    GIS_OPT_RES=`g.region -g | grep nsres | cut -f2 -d'='`
+    echo "No resolution given. Using the current N-S resolution: $GIS_OPT_RES"
+fi
+
+
+# scan bounds
+BOUNDS=`r.in.xyz -sg in="$GIS_OPT_INPUT" output=dummy fs="$GIS_OPT_FS" \
+   x="$GIS_OPT_X" y="$GIS_OPT_Y" z="$GIS_OPT_Z"`
+if  [ $? -ne 0 ] ; then
+    exit
+fi
+
+
+# clone current region
+g.region save="tmp_r.in.xyz.auto.$$"
+WIND_OVERRIDE="tmp_r.in.xyz.auto.$$"
+export WIND_OVERRIDE
+
+# temp set region to match data
+g.region -a res="$GIS_OPT_RES" $BOUNDS 
+if  [ $? -ne 0 ] ; then
+    exit
+fi
+
+# set up opts only given if there
+ADDL_OPTS=""
+if [ -n "$GIS_OPT_PTH" ] ; then
+   ADDL_OPTS="pth=\"$GIS_OPT_PTH\""
+fi
+if [ -n "$GIS_OPT_TRIM" ] ; then
+   ADDL_OPTS="$ADDL_OPTS trim=\"$GIS_OPT_TRIM\""
+fi
+if [ -n "$GIS_OPT_ZRANGE" ] ; then
+   ADDL_OPTS="$ADDL_OPTS zrange=\"$GIS_OPT_ZRANGE\""
+fi
+
+# import it
+r.in.xyz input="$GIS_OPT_INPUT" output="$GIS_OPT_OUTPUT" \
+   fs="$GIS_OPT_FS" method="$GIS_OPT_METHOD" \
+   x="$GIS_OPT_X" y="$GIS_OPT_Y" z="$GIS_OPT_Z" \
+   percent="$GIS_OPT_PERCENT" type="$GIS_OPT_TYPE" $ADDL_OPTS
+
+
+unset WIND_OVERRIDE
+g.remove region="tmp_r.in.xyz.auto.$$" --quiet


Property changes on: grass-addons/raster/r.in.xyz.auto/r.in.xyz.auto
___________________________________________________________________
Name: svn:executable
   + *



More information about the grass-commit mailing list