[GRASS-SVN] r31848 - in grass-addons/vector: . v.out.ascii.mat

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jun 26 02:36:52 EDT 2008


Author: hamish
Date: 2008-06-26 02:36:51 -0400 (Thu, 26 Jun 2008)
New Revision: 31848

Added:
   grass-addons/vector/v.out.ascii.mat/
   grass-addons/vector/v.out.ascii.mat/v.out.ascii.mat
Log:
new script to output boundaries and lines in a Matlab compatible ASCII format

Added: grass-addons/vector/v.out.ascii.mat/v.out.ascii.mat
===================================================================
--- grass-addons/vector/v.out.ascii.mat/v.out.ascii.mat	                        (rev 0)
+++ grass-addons/vector/v.out.ascii.mat/v.out.ascii.mat	2008-06-26 06:36:51 UTC (rev 31848)
@@ -0,0 +1,136 @@
+#!/bin/sh
+############################################################################
+#
+# MODULE:       v.out.ascii.mat
+#
+# AUTHOR(S):    Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE:      Export vector data to plain ASCII suitable for Matlab
+#
+# 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.
+#############################################################################
+#   see also v.in.mapgen for opposite process
+#   basic format is tab separated columns of x y[ z] with breaks in polylines
+#     "NaN NaN[ NaN]"
+#
+# REQUIREMENTS:  awk
+#
+#%Module
+#%  description: Export vector polygon and polyline data to plain ASCII suitable for Matlab.
+#%  keywords: vector, export
+#%End
+#%option
+#%  key: input
+#%  type: string
+#%  gisprompt: old,vector,vector
+#%  description: Name of input vector map
+#%  required : yes
+#%end
+#%option
+#%  key: output
+#%  type: string
+#%  gisprompt: new_file,file,output
+#%  description: Name for output map (omit for display to stdout)
+#%  required : no
+#%end
+
+##%option
+##%  key: type
+##%  type: string
+##%  description: Feature type
+##%  required : no
+##%  multiple: no
+##%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
+    g.message -e  "awk required, please install awk or gawk first"
+    exit 1
+fi
+
+# set environment so that awk works properly in all languages
+unset LC_ALL
+LC_NUMERIC=C
+export LC_NUMERIC
+
+#### setup temporary file
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+    g.message -e "Unable to create temporary files"
+    exit 1
+fi
+
+cleanup()
+{
+  rm -f "${TMP}"
+}
+
+#### trap ctrl-c so that we can clean up tmp
+trap 'cleanup' 2 3 15
+
+
+
+MAP_IS_3D=`v.info "$GIS_OPT_INPUT" | grep "Map is 3D" | cut -f2 -d: | awk '{print $1}'`
+
+if [ "$MAP_IS_3D" -eq 0 ] ; then
+   NAN_STR="NaN\tNaN"
+else
+   NAN_STR="NaN\tNaN\tNaN"
+fi
+
+
+v.out.ascii in="$GIS_OPT_INPUT" format=standard | tail -n +11 | \
+  awk -v NAN_STR="$NAN_STR" -v IS_3D="$MAP_IS_3D" \
+   'BEGIN { print NAN_STR; VERT=0 }
+    {
+     if ($1 ~ /^B/ || $1 ~ /^L/) {
+        VERT=$2
+     } else {
+        VERT=0
+     }
+     if ($3 ~ /[0-9]*/) {
+        ATTR=$3
+     } else {
+        ATTR=0
+     }
+     for(N=0; N<VERT; N++) {
+       getline
+       if(IS_3D) {
+          print $1 "\t" $2 "\t" $3
+       } else {
+          print $1 "\t" $2
+       }
+     }
+     if ( VERT > 0 ) {
+       print NAN_STR
+     }
+     for(N=0; N<ATTR; N++) {
+       getline
+     }
+    }' > "$TMP"
+
+
+if [ -z "$GIS_OPT_OUTPUT" ] || [ "$GIS_OPT_OUTPUT" = "-" ] ; then
+    cat "$TMP"
+else
+    mv "$TMP" "$GIS_OPT_OUTPUT"
+fi
+
+cleanup
+
+exit 0


Property changes on: grass-addons/vector/v.out.ascii.mat/v.out.ascii.mat
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/x-sh



More information about the grass-commit mailing list