[GRASS-SVN] r34882 - in grass/trunk/scripts: . v.to.3d

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Dec 14 15:29:50 EST 2008


Author: martinl
Date: 2008-12-14 15:29:50 -0500 (Sun, 14 Dec 2008)
New Revision: 34882

Added:
   grass/trunk/scripts/v.to.3d/
   grass/trunk/scripts/v.to.3d/v.to.3d.html
   grass/trunk/scripts/v.to.3d/v.to.3d.py
Removed:
   grass/trunk/scripts/v.to.3d/description.html
   grass/trunk/scripts/v.to.3d/v.to.3d
Modified:
   grass/trunk/scripts/Makefile
   grass/trunk/scripts/v.to.3d/Makefile
Log:
very initial version of v.to.3d

Modified: grass/trunk/scripts/Makefile
===================================================================
--- grass/trunk/scripts/Makefile	2008-12-14 19:53:45 UTC (rev 34881)
+++ grass/trunk/scripts/Makefile	2008-12-14 20:29:50 UTC (rev 34882)
@@ -60,6 +60,7 @@
 	v.out.gps \
 	v.rast.stats \
 	v.report \
+	v.to.3d \
 	v.what.vect
 
 #	d.vect.thematic \

Copied: grass/trunk/scripts/v.to.3d (from rev 34879, grass/branches/develbranch_6/scripts/v.to.3d)


Property changes on: grass/trunk/scripts/v.to.3d/Makefile
___________________________________________________________________
Name: svn:mime-type
   + text/x-sh
Name: svn:keywords
   + Author Date Id
Name: svn:eol-style
   + native

Deleted: grass/trunk/scripts/v.to.3d/description.html
===================================================================
--- grass/branches/develbranch_6/scripts/v.to.3d/description.html	2008-12-14 19:32:54 UTC (rev 34879)
+++ grass/trunk/scripts/v.to.3d/description.html	2008-12-14 20:29:50 UTC (rev 34882)
@@ -1,28 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-The <em>v.to.3d</em> module is used to transform 2D vector features
-to 3D. Height (z-coordinate) of 3D vector features can be specified
-by <b>height</b> parameter as fixed value or by <b>column</b>
-parameter.
-
-<h2>TODO</h2>
-
-<ul>
-  <li>Implement reverse transformation</li>
-  <li>Some examples</li>
-</ul>
-
-<h2>SEE ALSO</h2>
-
-<em>
-<a href="v.transform.html">v.transform</a>,
-<a href="v.extrude.html">v.extrude</a>,
-<a href="v.drape.html">v.drape</a>
-</em>
-
-<h2>AUTHORS</h2>
-
-Martin Landa, CTU in Prague, Czech Republic
-
-<p>
-<i>Last changed: $Date: 2008-11-12 02:39:48 +0100 (Wed, 12 Nov 2008) $</i>

Deleted: grass/trunk/scripts/v.to.3d/v.to.3d
===================================================================
--- grass/branches/develbranch_6/scripts/v.to.3d/v.to.3d	2008-12-14 19:32:54 UTC (rev 34879)
+++ grass/trunk/scripts/v.to.3d/v.to.3d	2008-12-14 20:29:50 UTC (rev 34882)
@@ -1,117 +0,0 @@
-#!/bin/sh
-############################################################################
-#
-# MODULE:       v.to.3d
-#
-# AUTHOR:       Martin Landa, CTU in Prague, Czech Republic
-#
-# PURPOSE:      Transform 2D vectors to 3D vectors
-#                 (frontend to v.transform)
-#
-# COPYRIGHT:    (c) 2008 Martin Landa, 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: Performs transformation of 2D vector features to 3D.
-#% keywords: vector, transformation, 3D
-#%End
-
-#%Option
-#% key: input
-#% type: string
-#% required: yes
-#% multiple: no
-#% key_desc: name
-#% description: Name of input vector map
-#% gisprompt: old,vector,vector
-#%End
-
-#%Option
-#% key: output
-#% type: string
-#% required: yes
-#% multiple: no
-#% key_desc: name
-#% description: Name for output vector map
-#% gisprompt: new,vector,vector
-#%End
-
-#%Option
-#% key: height
-#% type: double
-#% required: no
-#% multiple: no
-#% description: Fixed height for 3D vector features
-#%End
-
-#%Option
-#% key: layer
-#% type: integer
-#% required: no
-#% multiple: no
-#% label: Layer number
-#% description: A single vector map can be connected to multiple database tables. This number determines which table to use.
-#% answer: 1
-#% gisprompt: old_layer,layer,layer
-#%End
-
-#%Option
-#% key: column
-#% type: string
-#% required: no
-#% multiple: no
-#% key_desc: name
-#% description: Name of attribute column used for height
-#% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
-#%End
-
-if  [ -z "$GISBASE" ] ; then
-    echo "You must be in GRASS GIS to run this program." 1>&2
-    exit 1
-fi
-
-# save command line
-if [ "$1" != "@ARGS_PARSED@" ] ; then
-  exec g.parser "$0" "$@"
-fi
-
-map3d=` v.info "$GIS_OPT_INPUT" -t | grep map3d | cut -d'=' -f2`
-
-if [ "$map3d" -eq "1" ] ; then
-    g.message -e "Vector map <$GIS_OPT_INPUT> is 3D"
-    exit 1
-fi
-
-if [ -n "$GIS_OPT_HEIGHT" ] ; then
-   if [ -n "$GIS_OPT_COLUMN" ] ; then
-      g.message -e "Either 'height' or 'column' parameter have to be used"
-      exit 1
-   fi
-   # fixed height
-   v.transform input="$GIS_OPT_INPUT" output="$GIS_OPT_OUTPUT" zshift="$GIS_OPT_HEIGHT"
-else
-   if [ -z "$GIS_OPT_COLUMN" ] ; then
-      g.message -e "Either 'height' or 'column' parameter have to be used"
-      exit 1
-   fi
-
-   # attribute height, check column type
-   coltype=`v.info -c map="$GIS_OPT_INPUT" layer="$GIS_OPT_LAYER" --quiet | grep -w "$GIS_OPT_COLUMN" | cut -d'|' -f1`
-   if [ "$coltype" = "INTEGER" -o "$coltype" = "DOUBLE PRECISION" ] ; then
-       table=`v.db.connect map="$GIS_OPT_INPUT" -g fs=',' | grep ^"$GIS_OPT_LAYER" | cut -d',' -f2`
-       v.transform input="$GIS_OPT_INPUT" output="$GIS_OPT_OUTPUT" layer="$GIS_OPT_LAYER" columns="zshift:${GIS_OPT_COLUMN}" table="$table"
-   else
-       if [ -z "$coltype" ] ; then
-	   g.message -e "Column <$GIS_OPT_COLUMN> not found"
-       else
-	   g.message -e "Column type must be numeric"
-       fi
-       exit 1
-   fi
-fi
-
-exit 0

Copied: grass/trunk/scripts/v.to.3d/v.to.3d.html (from rev 34879, grass/branches/develbranch_6/scripts/v.to.3d/description.html)
===================================================================
--- grass/trunk/scripts/v.to.3d/v.to.3d.html	                        (rev 0)
+++ grass/trunk/scripts/v.to.3d/v.to.3d.html	2008-12-14 20:29:50 UTC (rev 34882)
@@ -0,0 +1,28 @@
+<h2>DESCRIPTION</h2>
+
+The <em>v.to.3d</em> module is used to transform 2D vector features
+to 3D. Height (z-coordinate) of 3D vector features can be specified
+by <b>height</b> parameter as fixed value or by <b>column</b>
+parameter.
+
+<h2>TODO</h2>
+
+<ul>
+  <li>Implement reverse transformation</li>
+  <li>Some examples</li>
+</ul>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.transform.html">v.transform</a>,
+<a href="v.extrude.html">v.extrude</a>,
+<a href="v.drape.html">v.drape</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Martin Landa, CTU in Prague, Czech Republic
+
+<p>
+<i>Last changed: $Date$</i>


Property changes on: grass/trunk/scripts/v.to.3d/v.to.3d.html
___________________________________________________________________
Name: svn:mime-type
   + text/html
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native

Copied: grass/trunk/scripts/v.to.3d/v.to.3d.py (from rev 34879, grass/branches/develbranch_6/scripts/v.to.3d/v.to.3d)
===================================================================
--- grass/trunk/scripts/v.to.3d/v.to.3d.py	                        (rev 0)
+++ grass/trunk/scripts/v.to.3d/v.to.3d.py	2008-12-14 20:29:50 UTC (rev 34882)
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+############################################################################
+#
+# MODULE:       v.to.3d
+#
+# AUTHOR:       Martin Landa, CTU in Prague, Czech Republic
+#
+# PURPOSE:      Transform 2D vectors to 3D vectors
+#                 (frontend to v.transform)
+#
+# COPYRIGHT:    (c) 2008 Martin Landa, 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: Performs transformation of 2D vector features to 3D.
+#% keywords: vector, transformation, 3D
+#%End
+
+#%Option
+#% key: input
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name of input vector map
+#% gisprompt: old,vector,vector
+#%End
+
+#%Option
+#% key: output
+#% type: string
+#% required: yes
+#% multiple: no
+#% key_desc: name
+#% description: Name for output vector map
+#% gisprompt: new,vector,vector
+#%End
+
+#%Option
+#% key: height
+#% type: double
+#% required: no
+#% multiple: no
+#% description: Fixed height for 3D vector features
+#%End
+
+#%Option
+#% key: layer
+#% type: integer
+#% required: no
+#% multiple: no
+#% label: Layer number
+#% description: A single vector map can be connected to multiple database tables. This number determines which table to use.
+#% answer: 1
+#% gisprompt: old_layer,layer,layer
+#%End
+
+#%Option
+#% key: column
+#% type: string
+#% required: no
+#% multiple: no
+#% key_desc: name
+#% description: Name of attribute column used for height
+#% gisprompt: old_dbcolumn,dbcolumn,dbcolumn
+#%End
+
+import sys
+import os
+import grass
+
+def main():
+    input = options['input']
+    output = options['output']
+    layer = options['layer']
+    column = options['column']
+    height = options['height']
+    
+    map3d = int(grass.parse_key_val(grass.read_command('v.info', map = input, flags = 't'))['map3d'])
+    
+    if map3d == 1:
+        grass.fatal("Vector map <%s> is 3D" % input)
+        
+    if height:
+        if column:
+            grass.fatal("Either 'height' or 'column' parameter have to be used")
+        # fixed height
+        grass.run_command('v.transform', input = input, output = output,
+                          zshift = height)
+    else:
+        if not column:
+            grass.fatal("Either 'height' or 'column' parameter have to be used")
+        # attribute height, check column type
+        try:
+            coltype = grass.vector_columns2(map = input, layer = layer)[column]
+        except KeyError:
+            grass.fatal("Column <%s> not found" % column)
+    
+        if coltype not in ('INTEGER',
+                           'DOUBLE PRECISION'):
+            grass.fatal("Column type must be numeric")
+        
+        table = grass.vector_db(map = input, layer = layer)[1]
+        
+        columns = "zshift:%s" % column
+        grass.run_command('v.transform', input = input, output = output,
+                          layer = layer, columns = columns,
+                          table = table)
+    
+    return 0
+                             
+if __name__ == "__main__":
+    options, flags = grass.parser()
+    sys.exit(main())


Property changes on: grass/trunk/scripts/v.to.3d/v.to.3d.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:keywords
   + Author Date Id
Name: svn:mergeinfo
   + 
Name: svn:eol-style
   + native



More information about the grass-commit mailing list