[GRASS-SVN] r54775 - in grass-addons/grass6/vector: . r.broscoe v.strahler2

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 26 09:22:08 PST 2013


Author: neteler
Date: 2013-01-26 09:22:08 -0800 (Sat, 26 Jan 2013)
New Revision: 54775

Added:
   grass-addons/grass6/vector/r.broscoe/
   grass-addons/grass6/vector/r.broscoe/r.broscoe_flowchart.dia
   grass-addons/grass6/vector/r.broscoe/r.broscoe_flowchart.jpeg
   grass-addons/grass6/vector/r.strahler/
   grass-addons/grass6/vector/v.mainchannel/
   grass-addons/grass6/vector/v.strahler2/
   grass-addons/grass6/vector/v.strahler2/Qgisout_vstrahler.jpg
   grass-addons/grass6/vector/v.strahler2/at_rbroscoe.jpg
   grass-addons/grass6/vector/v.strahler2/description.html
   grass-addons/grass6/vector/v.strahler2/helper.c
   grass-addons/grass6/vector/v.strahler2/input_vstrahler.jpg
   grass-addons/grass6/vector/v.strahler2/lr_rbroscoe.jpg
   grass-addons/grass6/vector/v.strahler2/main.c
   grass-addons/grass6/vector/v.strahler2/menotre.jpg
   grass-addons/grass6/vector/v.strahler2/output_vstrahler.jpg
   grass-addons/grass6/vector/v.strahler2/thrVScell.jpg
   grass-addons/grass6/vector/v.strahler2/v.strahler_flowchart.dia
   grass-addons/grass6/vector/v.strahler2/v.strahler_flowchart.jpeg
   grass-addons/grass6/vector/v.strahler2/wt_rbroscoe.jpg
Removed:
   grass-addons/grass6/vector/v.strahler2/description.html
   grass-addons/grass6/vector/v.strahler2/helper.c
   grass-addons/grass6/vector/v.strahler2/main.c
Log:
avoid hierarchical code structure for g.extension

Copied: grass-addons/grass6/vector/r.broscoe/r.broscoe_flowchart.dia (from rev 54774, grass-addons/grass6/vector/v.strahler/r.broscoe/r.broscoe_flowchart.dia)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/r.broscoe/r.broscoe_flowchart.jpeg (from rev 54774, grass-addons/grass6/vector/v.strahler/r.broscoe/r.broscoe_flowchart.jpeg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/Qgisout_vstrahler.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/Qgisout_vstrahler.jpg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/at_rbroscoe.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/at_rbroscoe.jpg)
===================================================================
(Binary files differ)

Deleted: grass-addons/grass6/vector/v.strahler2/description.html
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/description.html	2013-01-26 13:13:23 UTC (rev 54771)
+++ grass-addons/grass6/vector/v.strahler2/description.html	2013-01-26 17:22:08 UTC (rev 54775)
@@ -1,119 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.strahler</em> calculates the Strahler Order for all lines of a given
-dendritic network. The input vector map must be free of cycles. For the
-elaboration a new imported network or a network extracted from DEM by
-using <em><a href="r.watershed.html">r.watershed</a></em> can be used
-(in this case the topology has to be cleaned manually). More than one
-tree in the input data is allowed. No given flow direction is needed.
-To find the outlet of each tree, a DEM must be given.
-
-There are two additional scripts distributed with v.strahler:<br />
-- <em>r.strahler.sh</em> extracts streams from a DEM and call v.strahler
-  on the result. <br />
-- <em>r.broscoe.sh</em> computes further statistical values for a given
-  basin. <br />
-
-<h2>NOTES</h2>
-
-<h3>Problems</h3>
-
-This program is in beta status. It has the following shortcomings: <br />
-- The input data has to be topologically clean. Use <em>sloppy</em>=0.0 <br />
-- Source code comments are not doxydized. <br />
-
-
-<h3>How the algorithm works</h3>
-
-In a first step, <em>v.strahler</em> identifies all separate networks in
-the input dataset. That means, all connected lines are assigned a common
-<em>Basin ID</em>.<br />
-Consequently, the lowest leaf of each tree is identified as outlet.
-An auxiliary DEM is needed at this point. <br />
-Strahler ordering begins at each leaf of the tree with order N=1
-(excluding the outlet). At a confluence, the order N(r) of the resulting
-stream is equal to the highest order N(max) of the joining streams or is
-raised by one if there are two or more joining streams of order N(max).<br />
-The algorithm returns an ASCII text file with columns: <em>Category</em>
-(from input map), <em>Line</em> (topology), <em>Basin</em>, <em>Order</em>;
-and the output map has the Strahler Order value instead of "category"
-for each line, and no connection with the database.
-
-See the also the diagrams in the documentation/ directory.
-
-
-<h2>EXAMPLE</h2>
-
-The input map (vector on DEM): <br />
-<br />
-<img src="images/input_vstrahler.jpg"> <br />
-<br />
-<br />
-An example of the sintax in GRASS shell: <br />
-<br />
-<div class="code"><pre>
-GRASS> v.strahler input=esp_1 at mapset output=esp_1 dem=dem_20 at mapset \
-          txout=/home/mapset/esp_1 sloppy=0 layer=1
-</pre></div>
-
-<br />
-<br />
-An extract from the resultant text file: <br />
-<br />
-<div class="code"><pre>
-== Result of Strahler Order ==
- Category:   Line:   Basin:    Order:
-       22       1       1       4
-       73       2       1       1
-       25       3       1       4
-       27       4       1       4
-       39       5       1       1
-       48       6       1       1
-       56       7       1       4
-       55       8       1       2
-       88       9       1       4
-       59      10       1       1
-       60      11       1       1
-       61      12       1       2
-       83      13       1       2
-       82      14       1       1
-       91      15       1       1
-       87      16       1       4
-       95      17       1       2
-       96      18       1       1
-      106      19       1       1
-      102      20       1       1
-      104      21       1       4
-      111      22       1       1
-      112      23       1       3
-      121      24       1       3
-      126      25       1       1
-      128      26       1       3
-      137      27       1       3
-</pre></div>
-<br />
-<br />
-The output map (vector on DEM) form a snapshot of GRASS display: <br />
-<br />
-<img src="images/output_vstrahler.jpg"> <br />
-<br />
-<br />
-The output map (vector only) from Qgis (different colors for different orders): <br />
-<br />
-<img src="images/Qgisout_vstrahler.jpg"> <br />
-<br />
-<br />
-
-<h2>SEE ALSO</h2>
-
-<em><a href="r.watershed.html">r.watershed</a></em><br>
-
-
-<h2>AUTHOR</h2>
-
-Florian Kindl, Univ. Innsbruck.<br />
-<br />
-Modified by: Ivan Marchesini and Annalisa Minelli, Univ. Perugia.<br />
-
-<p>
-<i>Last changed: $Date$</i>

Copied: grass-addons/grass6/vector/v.strahler2/description.html (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/description.html)
===================================================================
--- grass-addons/grass6/vector/v.strahler2/description.html	                        (rev 0)
+++ grass-addons/grass6/vector/v.strahler2/description.html	2013-01-26 17:22:08 UTC (rev 54775)
@@ -0,0 +1,125 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.strahler</em> calculates the Strahler Order for all lines of a given
+dendritic network. The input vector map must be free of cycles. For the
+elaboration a new imported network or a network extracted from DEM by
+using <em><a href="r.watershed.html">r.watershed</a></em> can be used
+(in this case the topology has to be cleaned manually). More than one
+tree in the input data is allowed. No given flow direction is needed.
+To find the outlet of each tree, a DEM must be given.
+
+There are two additional scripts distributed with v.strahler:<br>
+- <em>r.strahler.sh</em> extracts streams from a DEM and call v.strahler
+  on the result. <br>
+- <em>r.broscoe.sh</em> computes further statistical values for a given
+  basin.
+
+<h2>NOTES</h2>
+
+<h3>Problems</h3>
+
+This program is in beta status. It has the following shortcomings: <br />
+- The input data has to be topologically clean. Use <em>sloppy</em>=0.0 <br />
+- Source code comments are not doxygenized (not a real problem). <br />
+
+
+<h3>How the algorithm works</h3>
+
+In a first step, <em>v.strahler</em> identifies all separate networks in
+the input dataset. That means, all connected lines are assigned a common
+<em>Basin ID</em>.
+<p>
+Consequently, the lowest leaf of each tree is identified as outlet.
+An auxiliary DEM is needed at this point.
+<p>
+Strahler ordering begins at each leaf of the tree with order N=1
+(excluding the outlet). At a confluence, the order N(r) of the resulting
+stream is equal to the highest order N(max) of the joining streams or is
+raised by one if there are two or more joining streams of order N(max).
+<p>
+The algorithm returns an ASCII text file with columns: <em>Category</em>
+(from input map), <em>Line</em> (topology), <em>Basin</em>, <em>Order</em>;
+and the output map has the Strahler Order value instead of "category"
+for each line, and no connection with the database.
+
+See the also the diagrams in the documentation/ directory.
+
+
+<h2>EXAMPLE</h2>
+
+The input map (vector on DEM):
+<p>
+<center>
+<img src="input_vstrahler.jpg">
+</center>
+<p>
+An example of the syntax in GRASS command line:
+<p>
+<div class="code"><pre>
+v.strahler input=esp_1 at mapset output=esp_1 dem=dem_20 at mapset \
+          txout=/home/mapset/esp_1 sloppy=0 layer=1
+</pre></div>
+
+<p>
+An extract from the resultant text file:
+<p>
+<div class="code"><pre>
+== Result of Strahler Order ==
+ Category:   Line:   Basin:    Order:
+       22       1       1       4
+       73       2       1       1
+       25       3       1       4
+       27       4       1       4
+       39       5       1       1
+       48       6       1       1
+       56       7       1       4
+       55       8       1       2
+       88       9       1       4
+       59      10       1       1
+       60      11       1       1
+       61      12       1       2
+       83      13       1       2
+       82      14       1       1
+       91      15       1       1
+       87      16       1       4
+       95      17       1       2
+       96      18       1       1
+      106      19       1       1
+      102      20       1       1
+      104      21       1       4
+      111      22       1       1
+      112      23       1       3
+      121      24       1       3
+      126      25       1       1
+      128      26       1       3
+      137      27       1       3
+</pre></div>
+<p>
+
+The output map (vector on DEM) form a snapshot of GRASS display:
+<p>
+<center>
+<img src="output_vstrahler.jpg">
+</center>
+
+The output map (vector only) from Qgis (different colors for different orders):
+<p>
+<center>
+<img src="Qgisout_vstrahler.jpg">
+</center>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.watershed.html">r.watershed</a>
+</em>
+
+
+<h2>AUTHOR</h2>
+
+Florian Kindl, Univ. Innsbruck.<br />
+<br />
+Modified by: Ivan Marchesini and Annalisa Minelli, Univ. Perugia.<br />
+
+<p>
+<i>Last changed: $Date$</i>

Deleted: grass-addons/grass6/vector/v.strahler2/helper.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/helper.c	2013-01-26 13:13:23 UTC (rev 54771)
+++ grass-addons/grass6/vector/v.strahler2/helper.c	2013-01-26 17:22:08 UTC (rev 54775)
@@ -1,80 +0,0 @@
-#include "strahler.h"
-
-/* Replacement for Vect_get_node_n_lines in sloppy mode
-   Gets adjacent lines by coordinate */
-
-int StrahGetDegr(struct Map_info *In, int node)
-{
-    extern double sloppy;
-    int degr, onode, j;
-    double x, y;
-    BOUND_BOX *Box;
-    struct ilist *list;
-
-    if (sloppy != 0.0) {
-	Vect_get_node_coor(In, node, &x, &y, NULL);
-
-	Box->N = y + sloppy;
-	Box->S = y - sloppy;
-	Box->W = x + sloppy;
-	Box->E = x - sloppy;
-
-	list = Vect_new_list();
-
-	/*
-	   printf( "N %f\n", Box->N );
-	   printf( "S %f\n", Box->S );
-	   printf( "W %f\n", Box->W );
-	   printf( "E %f\n", Box->E );
-	 */
-
-	Vect_select_nodes_by_box(In, Box, list);
-	G_debug(3, "  %d nodes selected", list->n_values);
-	/* is always 0 -why? */
-	for (j = 0; j < list->n_values; j++) {
-	    onode = abs(list->value[j]);
-	    G_debug(3, "List %d: %d\n", j, onode);
-	}
-	/*              
-	   Vect_list_append ( StArcs, line );
-	   Vect_get_line_nodes ( &Map, line, &node1, &node2);
-	   Vect_list_append ( StNodes, node1 ); 
-	   Vect_list_append ( StNodes, node2 );
-	 */
-
-    }
-    else {
-	degr = Vect_get_node_n_lines(In, node);
-    }
-
-    G_debug(4, "node %d degr %d sloppy %f\n", node, degr, sloppy);
-    return degr;
-}
-
-int StrahGetNodeLine(struct Map_info *In, int node, int d)
-{
-
-    extern double sloppy;
-    int aline;
-
-    if (sloppy != 0.0) {
-	G_debug(4, "StrahGetNodeLine at node %d", node);
-	/* 
-	   get all nodes within sloppy from node -> from table StrahGetDegr has written
-	   get all lines for each found node -> Vect_get_node_line(In, foundnode, df)
-	   for ( fn=0; fn<foundnodes.length; fn++ ) {
-	   degrf = Vect_get_node_n_lines( In, fn );
-	   for (df = 0; df < degrf; df++) {
-	   foundline = abs( Vect_get_node_line( In, fn, df ) );
-	   addtolist(foundline);
-	   }
-	   }
-	   return line d in list of foundlines;
-	 */
-    }
-    else {
-	/* method if junction is only 1 node */
-	aline = abs(Vect_get_node_line(In, node, d));
-    }
-    return aline;
-}

Copied: grass-addons/grass6/vector/v.strahler2/helper.c (from rev 54773, grass-addons/grass6/vector/v.strahler/v.strahler/helper.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler2/helper.c	                        (rev 0)
+++ grass-addons/grass6/vector/v.strahler2/helper.c	2013-01-26 17:22:08 UTC (rev 54775)
@@ -0,0 +1,81 @@
+#include "strahler.h"
+
+/* Replacement for Vect_get_node_n_lines in sloppy mode
+   Gets adjacent lines by coordinate */
+
+int StrahGetDegr(struct Map_info *In, int node)
+{
+    extern double sloppy;
+    int degr, onode, j;
+    double x, y;
+    BOUND_BOX *Box;
+    struct ilist *list;
+
+    if (sloppy != 0.0) {
+	Vect_get_node_coor(In, node, &x, &y, NULL);
+
+	Vect_get_map_box(In, Box);
+	Box->N = y + sloppy;
+	Box->S = y - sloppy;
+	Box->W = x + sloppy;
+	Box->E = x - sloppy;
+
+	list = Vect_new_list();
+
+	/*
+	   printf( "N %f\n", Box->N );
+	   printf( "S %f\n", Box->S );
+	   printf( "W %f\n", Box->W );
+	   printf( "E %f\n", Box->E );
+	 */
+
+	Vect_select_nodes_by_box(In, Box, list);
+	G_debug(3, "  %d nodes selected", list->n_values);
+	/* is always 0 -why? */
+	for (j = 0; j < list->n_values; j++) {
+	    onode = abs(list->value[j]);
+	    G_debug(3, "List %d: %d\n", j, onode);
+	}
+	/*              
+	   Vect_list_append ( StArcs, line );
+	   Vect_get_line_nodes ( &Map, line, &node1, &node2);
+	   Vect_list_append ( StNodes, node1 ); 
+	   Vect_list_append ( StNodes, node2 );
+	 */
+
+    }
+    else {
+	degr = Vect_get_node_n_lines(In, node);
+    }
+
+    G_debug(4, "node %d degr %d sloppy %f\n", node, degr, sloppy);
+    return degr;
+}
+
+int StrahGetNodeLine(struct Map_info *In, int node, int d)
+{
+
+    extern double sloppy;
+    int aline;
+
+    if (sloppy != 0.0) {
+	G_debug(4, "StrahGetNodeLine at node %d", node);
+	/* 
+	   get all nodes within sloppy from node -> from table StrahGetDegr has written
+	   get all lines for each found node -> Vect_get_node_line(In, foundnode, df)
+	   for ( fn=0; fn<foundnodes.length; fn++ ) {
+	   degrf = Vect_get_node_n_lines( In, fn );
+	   for (df = 0; df < degrf; df++) {
+	   foundline = abs( Vect_get_node_line( In, fn, df ) );
+	   addtolist(foundline);
+	   }
+	   }
+	   return line d in list of foundlines;
+	 */
+    }
+    else {
+	/* method if junction is only 1 node */
+	aline = abs(Vect_get_node_line(In, node, d));
+    }
+    return aline;
+}

Copied: grass-addons/grass6/vector/v.strahler2/input_vstrahler.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/input_vstrahler.jpg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/lr_rbroscoe.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/lr_rbroscoe.jpg)
===================================================================
(Binary files differ)

Deleted: grass-addons/grass6/vector/v.strahler2/main.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/main.c	2013-01-26 13:13:23 UTC (rev 54771)
+++ grass-addons/grass6/vector/v.strahler2/main.c	2013-01-26 17:22:08 UTC (rev 54775)
@@ -1,384 +0,0 @@
-
-/****************************************************************************
- * 
- *  MODULE:       v.strahler
- *  
- *  AUTHOR(S):    Florian Kindl, Norbert Pfeifer, The GRASS development team
- *		  Modified by: Ivan Marchesini <marchesini unipg.it> and 
-		  Annalisa Minelli <annapatri tiscali.it>
- *                
- *  PURPOSE:      Assign Strahler order to dendritic network
- *                
- *  COPYRIGHT:    (C) 2006 by the Authors
- * 
- *                This program is free software under the 
- *                GNU General Public License (v2). 
- *                Read the file COPYING that comes with GRASS
- *                for details.
- * 
- ****************************************************************************/
-
-/*! \file main.c
-   \brief Assign Strahler order to dendritic network
-   \author Florian Kindl
-
-   \todo Deal with poor topology 
-   \li implemement sloppy mode or
-   \li force clean topology
-   \todo ...
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <search.h>
-#include <time.h>
-#include <grass/gis.h>
-#include <grass/Vect.h>
-#include <grass/dgl.h>
-#include <grass/dbmi.h>
-#include <grass/glocale.h>
-#include "strahler.h"
-
-#define COPYBLAH 1
-#define DDFIELDBLAH 1
-#define BADDCOLUMNBLAH 1
-#define RITEDBLAH 1
-#define EBUG 1
-#define REATEDBLAH 1
-
-int ret, type;			/* return and type related to Vect_read_line and Vect_write_line */
-int fdrast;			/* file descriptor for raster file is int */
-int ntrees;			/* number of trees in dataset, returned by StrahForestToTrees */
-double sloppy;
-
-int main(int argc, char **argv)
-{
-    int line, node;
-    char buf[1024];
-    int nnodes, nlines, tlines;
-    DBBUF *dbbuf;
-    NODEV *nodev;
-    struct Option *input, *output, *dem_opt, *txout_opt, *sloppy_opt,
-	*field_opt;
-    struct GModule *module;
-    char *inputset, *demset;
-    struct Map_info In, Out;
-    struct Map_info Trees;
-    FILE *txout;
-    struct Cell_head window;	/* for cell sampling */
-
-    extern int ntrees;		/* number of trees calculated by StrahForestToTrees */
-    extern int fdrast;
-    extern double sloppy;
-
-    /* Attribute table (from v.net.path/path.c) */
-
-    struct line_cats *Cats;	/* introduced and initialized the structures line_cats and line_pnts */
-    static struct line_pnts *Points;
-
-    Points = Vect_new_line_struct();
-    Cats = Vect_new_cats_struct();
-    dbString sql;
-    dbDriver *driver;
-    dbColumn *column;
-
-    struct field_info *Fi;
-    int field;
-
-    /* Initialize the GIS calls */
-
-    G_gisinit(argv[0]);
-
-    input = G_define_standard_option(G_OPT_V_INPUT);
-    output = G_define_standard_option(G_OPT_V_OUTPUT);
-
-    module = G_define_module();
-    module->description = _("Strahler order");
-
-    dem_opt = G_define_standard_option(G_OPT_R_INPUT);
-    dem_opt->key = "dem";
-    dem_opt->description = _("Underlying DEM");
-
-    txout_opt = G_define_option();
-    txout_opt->key = "txout";
-    txout_opt->type = TYPE_STRING;
-    txout_opt->required = NO;
-    txout_opt->multiple = NO;
-    txout_opt->gisprompt = "new_file,file,output";
-    txout_opt->description =
-	_("Path to ASCII file where results will be written");
-
-    /* option sloppy for bad topology */
-    sloppy_opt = G_define_option();
-    sloppy_opt->key = "sloppy";
-    sloppy_opt->type = TYPE_DOUBLE;
-    sloppy_opt->required = NO;
-    sloppy_opt->answer = "0.0";
-    sloppy_opt->multiple = NO;
-    sloppy_opt->description =
-	_("Threshold for distance within different nodes are considered the same node - may not work");
-
-    field_opt = G_define_standard_option(G_OPT_V_FIELD);
-    field = atoi(field_opt->answer);
-
-    if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
-
-
-    Vect_check_input_output_name(input->answer, output->answer,
-				 GV_FATAL_EXIT);
-
-    inputset = G_find_vector2(input->answer, NULL);
-    if (inputset == NULL) {
-	G_fatal_error(_("Could not find input input <%s>"), input->answer);
-    }
-
-    /* open datasets at topology level 2 */
-
-    Vect_set_open_level(2);
-    Vect_open_old(&In, input->answer, inputset);
-
-    G_debug(1, "Input vector opened");
-
-    /* Open new vector, make 3D if input is 3D */
-
-    if (1 > Vect_open_new(&Out, output->answer, Vect_is_3d(&In))) {
-	Vect_close(&In);
-	G_fatal_error("Failed opening output vector file %s", output->answer);
-    }
-
-    /* Open DEM */
-
-    demset = G_find_cell2(dem_opt->answer, NULL);
-    if (demset == NULL) {
-	G_fatal_error("DEM file %s not found", dem_opt->answer);
-    }
-    if (1 > (fdrast = G_open_cell_old(dem_opt->answer, demset))) {
-	G_fatal_error("Failed opening DEM file %s", dem_opt->answer);
-    }
-
-    /* Open text file for results if given */
-
-    if (txout_opt->answer) {
-	txout = fopen(txout_opt->answer, "w");
-	if (txout == NULL)
-	    G_fatal_error(_("Cannot open file %s"), txout_opt->answer);
-    }
-
-    sloppy = atof(sloppy_opt->answer);
-    /* printf("blah %f", sloppy*2.4 ); */
-
-
-    /* write history */
-    /*Vect_copy_head_data( &In, &Out );
-       Vect_hist_copy( &In, &Out );
-       Vect_hist_command( &Out ); */
-
-#ifdef COPYBLAH
-    /* this works, we want to continue here and ADD two columns to the &Out */
-    /* Copy input to output (from v.clean/main.c) */
-    /*G_debug( 1, "Copying vector lines to Output" );
-
-       /* This works for both level 1 and 2 */
-    /*Vect_copy_map_lines ( &In, &Out );        */
-    /* 0: copy all fields, else field number */
-#endif
-
-
-#ifdef ADDFIELDBLAH		/* Create table (from v.net.path/path.c) */
-    /* or: add fields to existing table? */
-    /*                                                      *Map, field, field_name, type */
-
-    Fi = Vect_default_field_info(&Out, field, NULL, GV_1TABLE);
-    Vect_map_add_dblink(&Out, field, NULL, Fi->table, "cat", Fi->database,
-			Fi->driver);
-
-    driver = db_start_driver_open_database(Fi->driver, Fi->database);
-    driver =
-	db_start_driver_open_database(Fi->driver,
-				      Vect_subst_var(Fi->database, &Out));
-    /* from v.reclass/main.c :
-     */
-
-    if (driver == NULL) {
-	G_fatal_error("Cannot open database %s by driver %s", Fi->database,
-		      Fi->driver);
-    }
-
-
-    /* store the statement to create a table with category, basin ID and strahler order of the arc */
-    sprintf(buf,
-	    "CREATE TABLE %s ( cat integer, bsnid integer, sorder integer )",
-	    Fi->table);
-
-    /* from v.reclass/main.c : */
-    dbString stmt;
-
-    db_init_string(&stmt);
-    db_set_string(&stmt, buf);
-
-    if (db_execute_immediate(driver, &stmt) != DB_OK) {
-	Vect_close(&Out);
-	db_close_database_shutdown_driver(driver);
-	G_fatal_error("Cannot create table: %s", db_get_string(&stmt));
-    }
-
-    /*
-       sprintf ( buf, "ALTER TABLE %s ADD COLUMN cat integer", Fi->table );
-       sprintf ( buf, "ALTER TABLE %s ADD COLUMN bsnid integer", Fi->table );
-       sprintf ( buf, "ALTER TABLE %s ADD COLUMN sorder integer", Fi->table );
-     */
-#endif
-
-#ifdef DBADDCOLUMNBLAH
-    sprintf(buf, "bsnid");
-    db_set_string(&sql, buf);
-    column->columnName = sql;
-    column->sqlDataType = 1;
-    sprintf(buf, "%s", Fi->table);
-    /*db_set_string ( &sql, buf ); */
-    /* why such complicated arguments for db_add_column???
-       dbDriver, dbString, dbColumn */
-    if (db_add_column(driver, &sql, column) != DB_OK) {
-	db_close_database_shutdown_driver(driver);
-	G_fatal_error("Cannot add column column in table %s", Fi->table);
-    }
-#endif
-
-
-    /* execute statement */
-#ifdef CREATEDBLAH
-    sprintf(buf,
-	    "CREATE TABLE %s ( cat integer, bsnid integer, sorder integer )",
-	    Fi->table);
-    db_set_string(&sql, buf);
-    G_debug(2, db_get_string(&sql));
-
-    if (db_execute_immediate(driver, &sql) != DB_OK) {
-	db_close_database_shutdown_driver(driver);
-	G_fatal_error("Cannot create table: %s", db_get_string(&sql));
-    }
-    else
-	printf("table created\n");
-
-    if (db_create_index2(driver, Fi->table, "cat") != DB_OK) {
-	G_warning("Cannot create index");
-    }
-    else
-	printf("index created\n");
-
-    if (db_grant_on_table
-	(driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK) {
-	G_fatal_error("Cannot grant privileges on table %s", Fi->table);
-    }
-    else
-	printf("privileges granted\n");
-#endif
-
-    nnodes = Vect_get_num_nodes(&In);
-    nlines = Vect_get_num_lines(&In);
-    G_debug(1, "Number of lines: %d", nlines);
-    G_debug(1, "Number of nodes: %d", nnodes);
-
-    /* Create table to store ordering */
-    dbbuf = (DBBUF *) G_malloc((nlines + 1) * ((int)sizeof(DBBUF)));
-    nodev = (NODEV *) G_malloc((nnodes + 1) * ((int)sizeof(NODEV)));
-
-    /* initialize properly */
-    for (line = 1; line <= nlines; line++) {
-	dbbuf[line].category = dbbuf[line].line = dbbuf[line].bsnid =
-	    dbbuf[line].sorder = 0;
-    }
-    for (node = 1; node <= nnodes; node++) {
-	nodev[node].node = nodev[node].degree = nodev[node].visited = 0;
-    }
-
-    ntrees = (int)StrahForestToTrees(&In, &Out, dbbuf);
-    G_debug(1, "Number of trees: %d", ntrees);
-
-    StrahFindLeaves(&In, dbbuf, nodev, ntrees, fdrast);
-
-    G_debug(2, "dbbuf after FindLeaves:\nline\tbsnid\tsorder");
-    for (line = 1; line <= nlines; line++) {
-	sprintf(buf, "%d\t%d\t%d\n", dbbuf[line].line, dbbuf[line].bsnid,
-		dbbuf[line].sorder);
-	G_debug(2, "%s", buf);
-    }
-    G_debug(2, "nodev after FindLeaves:\nnode\tdegree\tvisited");
-    for (node = 1; node <= nnodes; node++) {
-	sprintf(buf, "%d\t%d\t%d\n", (int)nodev[node].node,
-		nodev[node].degree, nodev[node].visited);
-	G_debug(2, "%s", buf);
-    }
-
-    StrahOrder(&In, dbbuf, nodev);
-
-    G_debug(2, "dbbuf after StrahOrder:\nline\tbsnid\tsorder\n");
-    for (line = 1; line <= nlines; line++) {
-	sprintf(buf, "%d\t%d\t%d\n", dbbuf[line].line, dbbuf[line].bsnid,
-		dbbuf[line].sorder);
-	G_debug(2, "%s", buf);
-    }
-    G_debug(2, "nodev after StrahOrder:\nnode\tdegree\tvisited\n");
-    for (node = 1; node <= nnodes; node++) {
-	sprintf(buf, "%d\t%d\t%d\n", (int)nodev[node].node,
-		nodev[node].degree, nodev[node].visited);
-	G_debug(2, "%s", buf);
-    }
-
-#ifdef WRITEDBLAH
-    /* and write DB records */
-    db_begin_transaction(driver);
-
-    for (line = 1; line <= nlines; line++) {
-	sprintf(buf, "insert into %s values ( %d, %d, %d )", Fi->table, line,
-		dbbuf[line].bsnid, dbbuf[line].sorder);
-	db_set_string(&sql, buf);
-	/* G_debug ( 3, db_get_string ( &sql ) ); */
-	if (db_execute_immediate(driver, &sql) != DB_OK) {
-	    db_close_database_shutdown_driver(driver);
-	    G_fatal_error("Insert new row: %s", db_get_string(&sql));
-	}
-    }
-
-    db_commit_transaction(driver);
-
-    db_close_database_shutdown_driver(driver);
-#endif
-
-    /* writing StrahOrder instead of category in the output */
-
-    for (line = 1; line <= nlines; line++) {
-	type = Vect_read_line(&In, Points, Cats, line);
-	ret = Vect_cat_del(Cats, field);
-	G_debug(4, "deleted categories, ret=%d", ret);
-	Vect_cat_set(Cats, field, dbbuf[line].sorder);
-	Vect_write_line(&Out, type, Points, Cats);
-	G_debug(4, "category written for line %d", line);
-    }
-
-    /* assign category values */
-
-    for (line = 1; line <= nlines; line++) {
-	dbbuf[line].category = Vect_get_line_cat(&In, line, field);
-	G_debug(4, "added category %d for line %d", dbbuf[line].category,
-		dbbuf[line].line);
-    }
-
-    /* Write text file for results if given */
-
-    if (txout_opt->answer)
-	StrahWriteToFile(dbbuf, nlines, txout);
-
-    Vect_close(&In);
-    G_close_cell(fdrast);
-
-    Vect_build(&Out);
-    Vect_close(&Out);
-
-    if (txout_opt->answer)
-	fclose(txout);
-
-    return (EXIT_SUCCESS);
-}

Copied: grass-addons/grass6/vector/v.strahler2/main.c (from rev 54773, grass-addons/grass6/vector/v.strahler/v.strahler/main.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler2/main.c	                        (rev 0)
+++ grass-addons/grass6/vector/v.strahler2/main.c	2013-01-26 17:22:08 UTC (rev 54775)
@@ -0,0 +1,384 @@
+
+/****************************************************************************
+ * 
+ *  MODULE:       v.strahler
+ *  
+ *  AUTHOR(S):    Florian Kindl, Norbert Pfeifer, The GRASS development team
+ *		  Modified by: Ivan Marchesini <marchesini unipg.it> and 
+		  Annalisa Minelli <annapatri tiscali.it>
+ *                
+ *  PURPOSE:      Assign Strahler order to dendritic network
+ *                
+ *  COPYRIGHT:    (C) 2006 by the Authors
+ * 
+ *                This program is free software under the 
+ *                GNU General Public License (v2). 
+ *                Read the file COPYING that comes with GRASS
+ *                for details.
+ * 
+ ****************************************************************************/
+
+/*! \file main.c
+   \brief Assign Strahler order to dendritic network
+   \author Florian Kindl
+
+   \todo Deal with poor topology 
+   \li implemement sloppy mode or
+   \li force clean topology
+   \todo ...
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <search.h>
+#include <time.h>
+#include <grass/gis.h>
+#include <grass/Vect.h>
+#include <grass/dgl.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+#include "strahler.h"
+
+#define COPYBLAH 1
+#define DDFIELDBLAH 1
+#define BADDCOLUMNBLAH 1
+#define RITEDBLAH 1
+#define EBUG 1
+#define REATEDBLAH 1
+
+int ret, type;			/* return and type related to Vect_read_line and Vect_write_line */
+int fdrast;			/* file descriptor for raster file is int */
+int ntrees;			/* number of trees in dataset, returned by StrahForestToTrees */
+double sloppy;
+
+int main(int argc, char **argv)
+{
+    int line, node;
+    char buf[1024];
+    int nnodes, nlines, tlines;
+    DBBUF *dbbuf;
+    NODEV *nodev;
+    struct Option *input, *output, *dem_opt, *txout_opt, *sloppy_opt,
+	*field_opt;
+    struct GModule *module;
+    char *inputset, *demset;
+    struct Map_info In, Out;
+    struct Map_info Trees;
+    FILE *txout;
+    struct Cell_head window;	/* for cell sampling */
+
+    extern int ntrees;		/* number of trees calculated by StrahForestToTrees */
+    extern int fdrast;
+    extern double sloppy;
+
+    /* Attribute table (from v.net.path/path.c) */
+
+    struct line_cats *Cats;	/* introduced and initialized the structures line_cats and line_pnts */
+    static struct line_pnts *Points;
+
+    Points = Vect_new_line_struct();
+    Cats = Vect_new_cats_struct();
+    dbString sql;
+    dbDriver *driver;
+    dbColumn *column;
+
+    struct field_info *Fi;
+    int field;
+
+    /* Initialize the GIS calls */
+
+    G_gisinit(argv[0]);
+
+    input = G_define_standard_option(G_OPT_V_INPUT);
+    output = G_define_standard_option(G_OPT_V_OUTPUT);
+
+    module = G_define_module();
+    module->description = _("Strahler order");
+
+    dem_opt = G_define_standard_option(G_OPT_R_INPUT);
+    dem_opt->key = "dem";
+    dem_opt->description = _("Underlying DEM");
+
+    txout_opt = G_define_option();
+    txout_opt->key = "txout";
+    txout_opt->type = TYPE_STRING;
+    txout_opt->required = NO;
+    txout_opt->multiple = NO;
+    txout_opt->gisprompt = "new_file,file,output";
+    txout_opt->description =
+	_("Path to ASCII file where results will be written");
+
+    /* option sloppy for bad topology */
+    sloppy_opt = G_define_option();
+    sloppy_opt->key = "sloppy";
+    sloppy_opt->type = TYPE_DOUBLE;
+    sloppy_opt->required = NO;
+    sloppy_opt->answer = "0.0";
+    sloppy_opt->multiple = NO;
+    sloppy_opt->description =
+	_("Threshold for distance within different nodes are considered the same node - may not work");
+
+    field_opt = G_define_standard_option(G_OPT_V_FIELD);
+    field = atoi(field_opt->answer);
+
+    if (G_parser(argc, argv))
+	exit(EXIT_FAILURE);
+
+
+    Vect_check_input_output_name(input->answer, output->answer,
+				 GV_FATAL_EXIT);
+
+    inputset = G_find_vector2(input->answer, NULL);
+    if (inputset == NULL) {
+	G_fatal_error(_("Could not find input input <%s>"), input->answer);
+    }
+
+    /* open datasets at topology level 2 */
+
+    Vect_set_open_level(2);
+    Vect_open_old(&In, input->answer, inputset);
+
+    G_debug(1, "Input vector opened");
+
+    /* Open new vector, make 3D if input is 3D */
+
+    if (1 > Vect_open_new(&Out, output->answer, Vect_is_3d(&In))) {
+	Vect_close(&In);
+	G_fatal_error("Failed opening output vector file %s", output->answer);
+    }
+
+    /* Open DEM */
+
+    demset = G_find_cell2(dem_opt->answer, NULL);
+    if (demset == NULL) {
+	G_fatal_error("DEM file %s not found", dem_opt->answer);
+    }
+    if (1 > (fdrast = G_open_cell_old(dem_opt->answer, demset))) {
+	G_fatal_error("Failed opening DEM file %s", dem_opt->answer);
+    }
+
+    /* Open text file for results if given */
+
+    if (txout_opt->answer) {
+	txout = fopen(txout_opt->answer, "w");
+	if (txout == NULL)
+	    G_fatal_error(_("Cannot open file %s"), txout_opt->answer);
+    }
+
+    sloppy = atof(sloppy_opt->answer);
+    /* printf("blah %f", sloppy*2.4 ); */
+
+
+    /* write history */
+    /*Vect_copy_head_data( &In, &Out );
+       Vect_hist_copy( &In, &Out );
+       Vect_hist_command( &Out ); */
+
+#ifdef COPYBLAH
+    /* this works, we want to continue here and ADD two columns to the &Out */
+    /* Copy input to output (from v.clean/main.c) */
+    /*G_debug( 1, "Copying vector lines to Output" ); */
+
+       /* This works for both level 1 and 2 */
+    /*Vect_copy_map_lines ( &In, &Out );        */
+    /* 0: copy all fields, else field number */
+#endif
+
+
+#ifdef ADDFIELDBLAH		/* Create table (from v.net.path/path.c) */
+    /* or: add fields to existing table? */
+    /*                                                      *Map, field, field_name, type */
+
+    Fi = Vect_default_field_info(&Out, field, NULL, GV_1TABLE);
+    Vect_map_add_dblink(&Out, field, NULL, Fi->table, "cat", Fi->database,
+			Fi->driver);
+
+    driver = db_start_driver_open_database(Fi->driver, Fi->database);
+    driver =
+	db_start_driver_open_database(Fi->driver,
+				      Vect_subst_var(Fi->database, &Out));
+    /* from v.reclass/main.c :
+     */
+
+    if (driver == NULL) {
+	G_fatal_error("Cannot open database %s by driver %s", Fi->database,
+		      Fi->driver);
+    }
+
+
+    /* store the statement to create a table with category, basin ID and strahler order of the arc */
+    sprintf(buf,
+	    "CREATE TABLE %s ( cat integer, bsnid integer, sorder integer )",
+	    Fi->table);
+
+    /* from v.reclass/main.c : */
+    dbString stmt;
+
+    db_init_string(&stmt);
+    db_set_string(&stmt, buf);
+
+    if (db_execute_immediate(driver, &stmt) != DB_OK) {
+	Vect_close(&Out);
+	db_close_database_shutdown_driver(driver);
+	G_fatal_error("Cannot create table: %s", db_get_string(&stmt));
+    }
+
+    /*
+       sprintf ( buf, "ALTER TABLE %s ADD COLUMN cat integer", Fi->table );
+       sprintf ( buf, "ALTER TABLE %s ADD COLUMN bsnid integer", Fi->table );
+       sprintf ( buf, "ALTER TABLE %s ADD COLUMN sorder integer", Fi->table );
+     */
+#endif
+
+#ifdef DBADDCOLUMNBLAH
+    sprintf(buf, "bsnid");
+    db_set_string(&sql, buf);
+    column->columnName = sql;
+    column->sqlDataType = 1;
+    sprintf(buf, "%s", Fi->table);
+    /*db_set_string ( &sql, buf ); */
+    /* why such complicated arguments for db_add_column???
+       dbDriver, dbString, dbColumn */
+    if (db_add_column(driver, &sql, column) != DB_OK) {
+	db_close_database_shutdown_driver(driver);
+	G_fatal_error("Cannot add column column in table %s", Fi->table);
+    }
+#endif
+
+
+    /* execute statement */
+#ifdef CREATEDBLAH
+    sprintf(buf,
+	    "CREATE TABLE %s ( cat integer, bsnid integer, sorder integer )",
+	    Fi->table);
+    db_set_string(&sql, buf);
+    G_debug(2, db_get_string(&sql));
+
+    if (db_execute_immediate(driver, &sql) != DB_OK) {
+	db_close_database_shutdown_driver(driver);
+	G_fatal_error("Cannot create table: %s", db_get_string(&sql));
+    }
+    else
+	printf("table created\n");
+
+    if (db_create_index2(driver, Fi->table, "cat") != DB_OK) {
+	G_warning("Cannot create index");
+    }
+    else
+	printf("index created\n");
+
+    if (db_grant_on_table
+	(driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK) {
+	G_fatal_error("Cannot grant privileges on table %s", Fi->table);
+    }
+    else
+	printf("privileges granted\n");
+#endif
+
+    nnodes = Vect_get_num_nodes(&In);
+    nlines = Vect_get_num_lines(&In);
+    G_debug(1, "Number of lines: %d", nlines);
+    G_debug(1, "Number of nodes: %d", nnodes);
+
+    /* Create table to store ordering */
+    dbbuf = (DBBUF *) G_malloc((nlines + 1) * ((int)sizeof(DBBUF)));
+    nodev = (NODEV *) G_malloc((nnodes + 1) * ((int)sizeof(NODEV)));
+
+    /* initialize properly */
+    for (line = 1; line <= nlines; line++) {
+	dbbuf[line].category = dbbuf[line].line = dbbuf[line].bsnid =
+	    dbbuf[line].sorder = 0;
+    }
+    for (node = 1; node <= nnodes; node++) {
+	nodev[node].node = nodev[node].degree = nodev[node].visited = 0;
+    }
+
+    ntrees = (int)StrahForestToTrees(&In, &Out, dbbuf);
+    G_debug(1, "Number of trees: %d", ntrees);
+
+    StrahFindLeaves(&In, dbbuf, nodev, ntrees, fdrast);
+
+    G_debug(2, "dbbuf after FindLeaves:\nline\tbsnid\tsorder");
+    for (line = 1; line <= nlines; line++) {
+	sprintf(buf, "%d\t%d\t%d\n", dbbuf[line].line, dbbuf[line].bsnid,
+		dbbuf[line].sorder);
+	G_debug(2, "%s", buf);
+    }
+    G_debug(2, "nodev after FindLeaves:\nnode\tdegree\tvisited");
+    for (node = 1; node <= nnodes; node++) {
+	sprintf(buf, "%d\t%d\t%d\n", (int)nodev[node].node,
+		nodev[node].degree, nodev[node].visited);
+	G_debug(2, "%s", buf);
+    }
+
+    StrahOrder(&In, dbbuf, nodev);
+
+    G_debug(2, "dbbuf after StrahOrder:\nline\tbsnid\tsorder\n");
+    for (line = 1; line <= nlines; line++) {
+	sprintf(buf, "%d\t%d\t%d\n", dbbuf[line].line, dbbuf[line].bsnid,
+		dbbuf[line].sorder);
+	G_debug(2, "%s", buf);
+    }
+    G_debug(2, "nodev after StrahOrder:\nnode\tdegree\tvisited\n");
+    for (node = 1; node <= nnodes; node++) {
+	sprintf(buf, "%d\t%d\t%d\n", (int)nodev[node].node,
+		nodev[node].degree, nodev[node].visited);
+	G_debug(2, "%s", buf);
+    }
+
+#ifdef WRITEDBLAH
+    /* and write DB records */
+    db_begin_transaction(driver);
+
+    for (line = 1; line <= nlines; line++) {
+	sprintf(buf, "insert into %s values ( %d, %d, %d )", Fi->table, line,
+		dbbuf[line].bsnid, dbbuf[line].sorder);
+	db_set_string(&sql, buf);
+	/* G_debug ( 3, db_get_string ( &sql ) ); */
+	if (db_execute_immediate(driver, &sql) != DB_OK) {
+	    db_close_database_shutdown_driver(driver);
+	    G_fatal_error("Insert new row: %s", db_get_string(&sql));
+	}
+    }
+
+    db_commit_transaction(driver);
+
+    db_close_database_shutdown_driver(driver);
+#endif
+
+    /* writing StrahOrder instead of category in the output */
+
+    for (line = 1; line <= nlines; line++) {
+	type = Vect_read_line(&In, Points, Cats, line);
+	ret = Vect_cat_del(Cats, field);
+	G_debug(4, "deleted categories, ret=%d", ret);
+	Vect_cat_set(Cats, field, dbbuf[line].sorder);
+	Vect_write_line(&Out, type, Points, Cats);
+	G_debug(4, "category written for line %d", line);
+    }
+
+    /* assign category values */
+
+    for (line = 1; line <= nlines; line++) {
+	dbbuf[line].category = Vect_get_line_cat(&In, line, field);
+	G_debug(4, "added category %d for line %d", dbbuf[line].category,
+		dbbuf[line].line);
+    }
+
+    /* Write text file for results if given */
+
+    if (txout_opt->answer)
+	StrahWriteToFile(dbbuf, nlines, txout);
+
+    Vect_close(&In);
+    G_close_cell(fdrast);
+
+    Vect_build(&Out);
+    Vect_close(&Out);
+
+    if (txout_opt->answer)
+	fclose(txout);
+
+    return (EXIT_SUCCESS);
+}

Copied: grass-addons/grass6/vector/v.strahler2/menotre.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/menotre.jpg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/output_vstrahler.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/output_vstrahler.jpg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/thrVScell.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/thrVScell.jpg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/v.strahler_flowchart.dia (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/v.strahler_flowchart.dia)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/v.strahler_flowchart.jpeg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/v.strahler_flowchart.jpeg)
===================================================================
(Binary files differ)

Copied: grass-addons/grass6/vector/v.strahler2/wt_rbroscoe.jpg (from rev 54774, grass-addons/grass6/vector/v.strahler/v.strahler/wt_rbroscoe.jpg)
===================================================================
(Binary files differ)



More information about the grass-commit mailing list