[GRASS-SVN] r52031 - in grass-addons/grass6/vector/v.strahler: . v.mainchannel v.strahler
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jun 11 02:01:11 PDT 2012
Author: neteler
Date: 2012-06-11 02:01:11 -0700 (Mon, 11 Jun 2012)
New Revision: 52031
Added:
grass-addons/grass6/vector/v.strahler/v.mainchannel/
grass-addons/grass6/vector/v.strahler/v.mainchannel/Makefile
grass-addons/grass6/vector/v.strahler/v.mainchannel/description.html
grass-addons/grass6/vector/v.strahler/v.mainchannel/v.mainchannel
grass-addons/grass6/vector/v.strahler/v.strahler/
grass-addons/grass6/vector/v.strahler/v.strahler/Makefile
grass-addons/grass6/vector/v.strahler/v.strahler/description.html
grass-addons/grass6/vector/v.strahler/v.strahler/forest2tree.c
grass-addons/grass6/vector/v.strahler/v.strahler/helper.c
grass-addons/grass6/vector/v.strahler/v.strahler/main.c
grass-addons/grass6/vector/v.strahler/v.strahler/strahler.c
grass-addons/grass6/vector/v.strahler/v.strahler/strahler.h
grass-addons/grass6/vector/v.strahler/v.strahler/write.c
Removed:
grass-addons/grass6/vector/v.strahler/description.html
grass-addons/grass6/vector/v.strahler/forest2tree.c
grass-addons/grass6/vector/v.strahler/helper.c
grass-addons/grass6/vector/v.strahler/main.c
grass-addons/grass6/vector/v.strahler/strahler.c
grass-addons/grass6/vector/v.strahler/strahler.h
grass-addons/grass6/vector/v.strahler/v.mainchannel.html
grass-addons/grass6/vector/v.strahler/v.mainchannel.sh
grass-addons/grass6/vector/v.strahler/write.c
Modified:
grass-addons/grass6/vector/v.strahler/Makefile
Log:
cleanup part 2
Modified: grass-addons/grass6/vector/v.strahler/Makefile
===================================================================
--- grass-addons/grass6/vector/v.strahler/Makefile 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/Makefile 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,23 +1,11 @@
MODULE_TOPDIR = ../..
-PROGRAMS = v.mainchannel r.strahler.sh r.broscoe.sh
+SUBDIRS = \
+ v.mainchannel \
+ r.strahler \
+ r.broscoe \
+ v.strahler
-LIBES = $(DISPLAYLIB) $(RASTERLIB) $(VECTLIB) $(GRAPHLIB) $(DBMILIB) $(GISLIB)
-DEPENDENCIES = $(DISPLAYDEP) $(RASTERDEP) $(VECTDEP) $(GISDEP)
-EXTRA_INC = $(VECT_INC)
-EXTRA_CFLAGS = $(VECT_CFLAGS)
+include $(MODULE_TOPDIR)/include/Make/Dir.make
-include $(MODULE_TOPDIR)/include/Make/Script.make
-
-default: script
-
-PGM = v.strahler
-
-LIBES = $(DISPLAYLIB) $(RASTERLIB) $(VECTLIB) $(GRAPHLIB) $(DBMILIB) $(GISLIB)
-DEPENDENCIES = $(DISPLAYDEP) $(RASTERDEP) $(VECTDEP) $(GISDEP)
-EXTRA_INC = $(VECT_INC)
-EXTRA_CFLAGS = $(VECT_CFLAGS)
-
-include $(MODULE_TOPDIR)/include/Make/Module.make
-
-default: cmd
+default: parsubdirs
Deleted: grass-addons/grass6/vector/v.strahler/description.html
===================================================================
--- grass-addons/grass6/vector/v.strahler/description.html 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/description.html 2012-06-11 09:01:11 UTC (rev 52031)
@@ -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>
Deleted: grass-addons/grass6/vector/v.strahler/forest2tree.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/forest2tree.c 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/forest2tree.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,114 +0,0 @@
-#include "strahler.h"
-
-/* helper functions for ForestToTrees:
- push_line: push number of adjacent line on stack
- pop_line: return number of top line on stack
- we could do this with some Vect_list but we don't need
- to handle entire lines, only their identifiers */
-
-#define STACK_SIZE 65535
-int sp = 0; /* stack position */
-int stack[STACK_SIZE]; /* generous stack size */
-
-void push_line(int line)
-{
- if (sp < STACK_SIZE) {
- stack[sp++] = line;
- }
- else {
- G_fatal_error("ForestToTrees: stack full");
- }
-}
-
-int pop_line(void)
-{
- if (sp > 0) {
- return stack[--sp];
- }
- else {
- G_debug(3, "ForestToTrees: stack empty, tree finished");
- return 0;
- }
-}
-
-
-/* or write our own lfind: nexttree() */
-/* start at offset, walk array up until bsnid == 0 and return that offset */
-
-int nexttree(DBBUF * dbbuf, int offset, int upper)
-{
- while ((dbbuf[offset].bsnid != 0) && (offset < upper)) {
- ++offset;
- G_debug(4, "bsnid[%d] is %d", offset, dbbuf[offset].bsnid);
- }
- return offset;
-}
-
-/* Find trees, assign basinID */
-int StrahForestToTrees(struct Map_info *In, struct Map_info *Out,
- DBBUF * dbbuf)
-{
- int tree, tree_finished, forest_done; /* ID of tree (basin), processing status */
- int l, n, d, degr, node; /* iterators */
- int nlines, offset; /* number of lines, position in dbbuf */
- int cline, aline; /* currently harvested line, adjacent line */
- int lnodes[2]; /* nodes of cline */
-
-
- G_debug(1, "reached StrahForestToTrees");
-
- nlines = Vect_get_num_lines(In);
-
- forest_done = 0;
- tree = 1; /* we start with tree no. 1 */
- offset = cline = 1; /* we start at line 1 */
-
- while (forest_done == 0) {
- G_debug(3, "\nProcessing Tree %d", tree);
- tree_finished = 0; /* initialize status indicator for this tree */
- while (tree_finished == 0) {
- /* procedure to get adjacent lines and push them on the stack */
- Vect_get_line_nodes(In, cline, &lnodes[0], &lnodes[1]);
- G_debug(4, "nodes for line %d: %d %d", cline, lnodes[0],
- lnodes[1]);
-
- for (n = 0; n <= 1; n++) { /* loop through array[2] of fnode and tnode */
- node = lnodes[n];
- /*degr = Vect_get_node_n_lines( In, node ); */
- degr = StrahGetDegr(In, node);
- G_debug(4, "degr %d for node %d", degr, node);
- for (d = 0; d < degr; d++) {
- /*aline = abs( Vect_get_node_line( In, node, d ) ); */
- aline = abs(StrahGetNodeLine(In, node, d));
- if (dbbuf[aline].bsnid == 0) { /* push line on stack only if not done yet */
- G_debug(4, "pushing line %d on sp %d", aline, sp);
- push_line(aline);
- G_debug(4, "pushed, sp is now %d", sp);
- dbbuf[aline].bsnid = tree; /* line is done when pushed on stack */
- dbbuf[aline].line = aline;
- }
- }
- }
-
- /* pop a line from stack */
- cline = (int)pop_line();
- G_debug(4, "popped line %d", cline);
- /* tree is finished when pop_line returned 0 */
- if (cline == 0) {
- tree_finished = 1;
- }
- }
-
- /* get first cline of next tree */
- offset = cline = nexttree(dbbuf, ++offset, nlines);
- G_debug(3, "cline/offset for tree %d is %d", tree, cline);
- if (offset == nlines) {
- forest_done = 1; /* what if last line still is 0 - it is a tree consisting of this line only - it shall keep bsnid 0 */
- }
- else {
- tree++; /* continue with next tree */
- }
- }
-
- return tree;
-}
Deleted: grass-addons/grass6/vector/v.strahler/helper.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/helper.c 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/helper.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -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;
-}
Deleted: grass-addons/grass6/vector/v.strahler/main.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/main.c 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/main.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -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);
-}
Deleted: grass-addons/grass6/vector/v.strahler/strahler.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/strahler.c 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/strahler.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,223 +0,0 @@
-#include "strahler.h"
-
-/* Find Leaves of tree and distinguish outlet from sources */
-int StrahFindLeaves(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev,
- int ntrees, int fdrast)
-{
- int nnodes, degr, aline, node, unode, dnode, tree, outlet;
- double x, y, z, z_init;
-
- int n;
-
- struct Cell_head window;
- INTERP_TYPE method = NEAREST;
-
- OUTLETS *outlets;
-
- nnodes = Vect_get_num_nodes(In);
-
- z = z_init = 27000000.0; /* is it safe to initialize lowest z with the height of Olympus Mons above Martian Datum in millimeters? */
-
- outlets = (OUTLETS *) G_malloc((ntrees + 1) * ((int)sizeof(OUTLETS)));
-
- /* initialize outlet table properly */
- for (n = 1; n <= ntrees; n++) {
- outlets[n].z = z_init;
- outlets[n].leaf = 0;
- }
-
- G_debug(1, "Reached StrahFindLeaves with %d trees", ntrees);
-
- G_get_window(&window);
- G_debug(2, "window: N %f S %f W %f E %f", window.north, window.south,
- window.west, window.east);
-
- G_debug(2, "%d nodes in map", nnodes);
- for (node = 1; node <= nnodes; node++) {
- /*degr = Vect_get_node_n_lines( In, node ); */
- degr = StrahGetDegr(In, node);
- nodev[node].node = node;
- nodev[node].degree = degr;
-
- G_debug(4, "node %d: degr=%d", node, degr);
-
- if (degr == 1) {
- unode = node;
- nodev[node].visited = 1; /*set the "visited" parameter to 1... can't be less */
- /*aline = abs( Vect_get_node_line( In, unode, 0 ) ); */
- aline = abs(StrahGetNodeLine(In, unode, 0));
- /*Vect_get_line_nodes( In, aline, &unode, &dnode); */
- /* these are not necessarily up-node and down-node but we need not distinguish here... */
- dbbuf[aline].sorder = 1;
- /* no, do not visit yet
- nodev[node].visited += 1;
- */
- /*
- nodev[unode].visited += 1;
- nodev[dnode].visited += 1;
- */
- /* get z value or DEM value under node here, remember lowest */
- if (Vect_is_3d(In)) {
- Vect_get_node_coor(In, node, &x, &y, &z);
- }
- else {
- Vect_get_node_coor(In, node, &x, &y, NULL);
- z = (double)G_get_raster_sample(fdrast, &window, NULL, y, x,
- 0, method);
- }
-
- G_debug(5, "fdrast=%d node=%d y=%f x=%f z=%f", fdrast, node, y,
- x, z);
-
- tree = dbbuf[aline].bsnid;
- if (z < outlets[tree].z) {
- outlets[tree].z = z;
- outlets[tree].leaf = aline;
- }
- }
- }
- /* reset outlets to 0 */
- for (n = 1; n <= ntrees; n++) {
- G_debug(2, "outlet tree %d: line %d with %f", n, outlets[n].leaf,
- outlets[n].z);
- outlet = outlets[n].leaf;
- dbbuf[outlet].sorder = 0;
- /*
- Vect_get_line_nodes( In, outlet, &unode, &dnode);
- nodev[unode].visited = 0;
- nodev[dnode].visited = 0;
- */
- }
- return 1;
-}
-
-/* assign strahler order */
-int StrahOrder(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev)
-{
- int nlines, line;
- int fnode, tnode, unode, dnode; /* from-, to-, up-, down- node */
- int degr, d, aline, aorder; /* find adjacent lines */
- int corder, norder, dorder, dline; /* assign order */
- int cline, rfinish; /* follow one line until this stop-condition is 1 */
-
- struct dbbuf;
- struct nodev;
-
- nlines = Vect_get_num_lines(In);
-
- G_debug(1, "reached StrahOrder");
-
- for (line = 1; line <= nlines; line++) {
- if (dbbuf[line].sorder == 1) { /* get lines of order 1 */
-
- cline = line; /* and start run downwards */
- rfinish = 0;
- while (rfinish == 0) {
- G_debug(3, "reached line %d", cline);
-
- Vect_get_line_nodes(In, cline, &fnode, &tnode); /* and their nodes */
-
- /**** BAUSTELLE ****/
- /* check nodes - we do not rely on flow direction */
- if (nodev[fnode].visited == 1) {
- unode = fnode;
- dnode = tnode;
- }
- else {
- unode = tnode;
- dnode = fnode;
- }
-
- /*
- if (nodev[fnode].visited == nodev[tnode].visited) {
- printf("Line %d: both nodes are visited or not - what now?\n", line);
- } else if (nodev[fnode].visited == 0) {
- node = fnode;
- } else {
- node = tnode;
- }
- */
-
- /*
- if ( (nodev[fnode].degree - nodev[fnode].visited) < (nodev[tnode].degree - nodev[tnode].visited) ) {
- unode = fnode;
- dnode = tnode;
- } else if ( (nodev[fnode].degree - nodev[fnode].visited) > (nodev[tnode].degree - nodev[tnode].visited) ) {
- unode = tnode;
- dnode = fnode;
- } else {
- G_message("Line %d: nodes have same diff(degree,visited) - what now?\n", cline);
- */
- /* ok, what now?
- - occurs when leaf meets node with norder==0 -> visit nodes and continue
- - or: is outlet -> assign order
- */
- /* continue? */
- /*
- printf("visiting tnode %d and fnode %d for line %d and break\n\n", tnode, fnode, cline);
- nodev[tnode].visited += 1;
- nodev[fnode].visited += 1;
- break;
- }
- */
-
- G_debug(3, "unode is %d and dnode is %d", unode, dnode);
-
- /*degr = Vect_get_node_n_lines ( In, dnode ); use downward node */
- degr = StrahGetDegr(In, dnode);
-
- G_debug(4, "deg for dnode %d is %d", dnode, degr);
-
- corder = dbbuf[cline].sorder; /* current order - result won't be less than that */
- norder = dorder = 0; /* no order - how many lines have none?, highest order of others */
- for (d = 0; d < degr; d++) {
- /*aline = abs( Vect_get_node_line ( In, dnode, d ) ); */
- aline = abs(StrahGetNodeLine(In, dnode, d));
- G_debug(4, "line %d at dnode %d is %d", d, dnode, aline);
- if (aline != cline) { /* we don't need the line we come from */
- aorder = dbbuf[aline].sorder;
- if (aorder == 0) {
- norder++;
- dline = aline; /* downward line */
- }
- else if (aorder > dorder) {
- dorder = aorder; /* find highest order */
- }
- }
- }
-
- if (norder > 1 || norder == 0) { /* if (norder > 1: node indeterminate OR norder == 0 : subtree finished) */
- G_debug(3, "Finished run at line %d because norder=%d",
- cline, norder);
- G_debug(4, "visiting unode %d for line %d", unode, cline);
- nodev[unode].visited += 1; /* visit unode, for the sake of completeness */
- rfinish = 1; /* finish this run */
-
- }
- else { /* or */
- if (dorder > corder) {
- ; /* assign highest order of alines */
- }
- else if (dorder < corder) {
- dorder = corder; /* or keep order of cline */
- }
- else {
- dorder++; /* or raise order by one */
- }
-
- dbbuf[dline].sorder = dorder; /* assign order */
-
- G_debug(4, "visiting dnode %d and unode %d for line %d",
- dnode, unode, cline);
- nodev[dnode].visited += 1; /* visit dnode */
- nodev[unode].visited += 1; /* visit unode, for the sake of completeness */
-
- cline = dline; /* and continue with this line */
-
- G_debug(3, "StrahOrder for dline %d: %d", dline, dorder);
- }
- } /* while */
- }
- }
- return 1;
-}
Deleted: grass-addons/grass6/vector/v.strahler/strahler.h
===================================================================
--- grass-addons/grass6/vector/v.strahler/strahler.h 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/strahler.h 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,100 +0,0 @@
-#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"
-
-/*! \typedef DBBUF
- \brief Buffer to keep track of assigned tree and Strahler order for each line
- */
-
-/*! \typedef NODEV
- \brief Buffer to keep track of valency for each node
- */
-
-/*! \typedef OUTLETS
- \brief Buffer to determine lowest leaf of each tree
- */
-
-typedef struct
-{ /* collect lines in Strahler order */
- int category;
- int line; /* line number */
- int bsnid; /* basin ID */
- int sorder; /* Strahler order */
-} DBBUF;
-
-typedef struct
-{ /* visited nodes */
- int node; /* node number */
- int degree; /* valency */
- int visited; /* is between 0 and degr(node) */
-} NODEV;
-
-typedef struct
-{ /* keep track of lowest leaf (=outlet) of each tree */
- double z; /* z-value of leaf */
- int leaf; /* line-id of outlet leaf */
-} OUTLETS;
-
-/* in forest2tree.c */
-/*! \fn int StrahForestToTrees( struct Map_info *In, struct Map_info *Out, DBBUF *dbbuf );
- \brief Returns the number of trees in *In
- \param *In The input map
- \param *Out The output map
- \param *dbbuf The buffer table for line orders
- */
-
-
-/* in strahler.c */
-/*! \fn int StrahFindLeaves( struct Map_info *In, DBBUF *dbbuf, NODEV *nodev, int ntrees, int fdrast );
- \brief Identifies all leaves of each tree and the one that lies lowest
- \param *In The input map
- \param *dbbuf The buffer table for line orders
- \param *nodev The buffer table for node valency
- \param ntrees Number of trees in map
- \param fdrast File descriptor of DEM raster map
- */
-
-/*! \fn int StrahOrder( struct Map_info *In, DBBUF *dbbuf, NODEV *nodev );
- \brief Calculates the Strahler order of each line
- \param *In The input map
- \param *dbbuf The buffer table for line orders
- \param *nodev The buffer table for node valency
- */
-
-
-/* in write.c */
-/*! \fn int StrahWriteToFile( DBBUF *dbbuf, int nlines, FILE *txout );
- \brief Writes ASCII representation of calculated order to file
- \param *dbbuf The buffer table for line orders
- \param nlines Number of lines in *In map
- \param *txout ASCII output file name
- */
-
-
-/* in helper.c */
-/*! \fn int StrahGetDegr( struct Map_info *In, int node );
- \brief Get degree of node (for sloppy mode)
- \param *In The input map
- \param node Node number in *In
- */
-
-/*! \fn int StrahNodeLine( struct Map_info *In, int node, int d );
- \brief Get lines connected in node (for sloppy mode)
- \param *In The input map
- \param node Node number in *In
- \param d n-th line connected to node
- */
-
-int StrahForestToTrees(struct Map_info *In, struct Map_info *Out,
- DBBUF * dbbuf);
-int StrahFindLeaves(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev,
- int ntrees, int fdrast);
-int StrahOrder(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev);
-int StrahWriteToFile(DBBUF * dbbuf, int nlines, FILE * txout);
-int StrahGetDegr(struct Map_info *In, int node);
-int StrahGetNodeLine(struct Map_info *In, int node, int d);
Added: grass-addons/grass6/vector/v.strahler/v.mainchannel/Makefile
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.mainchannel/Makefile (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.mainchannel/Makefile 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.mainchannel
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Copied: grass-addons/grass6/vector/v.strahler/v.mainchannel/description.html (from rev 51972, grass-addons/grass6/vector/v.strahler/v.mainchannel.html)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.mainchannel/description.html (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.mainchannel/description.html 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,29 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.mainchannel</em> Finds the main channel of a basin starting from the vector file of the stream network.
+As first you have to visualize on the GRASS monitor the vector map wich you want to calculate the main channel for; with a scale (so you can realize the distances between the closing section and the sources) you can choose some values for the cost isolines (from the outlet); then you can individuate (by interrogating a DEM underlying the vector map) the outlet cross section coords. These coords, the selected cost values and the input/output map names have to be given in input to the program.<br />
+The program returns the main channel considering two factors:<br />
+<em>distance</em>: often the main channel is the longest track in the network<br />
+<em>height</em>: the source of the main channel is conventionally taken as the higest<br />
+This module can be used for any ordinary vector stream network, but the analisys becomes particoulary interesting if you have a vector stream network ordered by Horton-Strahler (e.g. derived from <em><a href="v.strahler.html">v.strahler</a></em> or <em><a href="r.strahler.sh.html">r.strahler.sh</a></em>) because you can see if the main channel includes the max_ordered stream, and, if not, you can consequently modify the "cost" values assigned. <br />
+
+<h2>EXAMPLE</h2>
+
+The syntax:
+
+<div class="code"><pre>
+ v.mainchannel dem=dem xcoor=483456.23 ycoor=234765.33 cost=500,1000,2500,5000,10000 input=input_map output=output_map
+</pre></div>
+
+<h2>SEE ALSO</h2>
+<em><a href="v.strahler.html">v.strahler</a></em><br>
+<em><a href="r.strahler.sh.html">r.strahler.sh</a></em><br>
+<em><a href="v.net.iso.html">v.net.iso</a></em><br>
+
+<h2>AUTHORS</h2>
+
+Ivan Marchesini and Annalisa Minelli, Univ. Perugia. <br>
+
+
+<p>
+<i>Last changed: $Date$</i>
Copied: grass-addons/grass6/vector/v.strahler/v.mainchannel/v.mainchannel (from rev 52030, grass-addons/grass6/vector/v.strahler/v.mainchannel.sh)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.mainchannel/v.mainchannel (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.mainchannel/v.mainchannel 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,154 @@
+#!/bin/sh
+#
+############################################################################
+#
+# MODULE: v.mainchannel
+# AUTHOR(S): Annalisa Minelli, Ivan Marchesini
+# PURPOSE: Find the main channel of a vector stream network (useful to compare with a network ordered by Horton-Strahler)
+# COPYRIGHT: (C) 2005 by 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: Find the main channel of a vector stream network (useful to compare with a network ordered by Horton-Strahler)
+#% keywords: strahler, main_channel, vector
+#%End
+#%option
+#% key: dem
+#% type: string
+#% key_desc: dem
+#% gisprompt: old,cell,raster
+#% description: Name of DEM raster map
+#% required : yes
+#%END
+#%option
+#% key: xcoor
+#% type: double
+#% description: x coord of outlet (read by dem in the pixel where is the vector file cross section)
+#% required : yes
+#%end
+#%option
+#% key: ycoor
+#% type: double
+#% description: y coord of outlet (read by dem in the pixel where is the vector file cross section)
+#% required : yes
+#%end
+#%option
+#% key: cost
+#% type: integer
+#% description: Distance between isolines (separated by <comma>)
+#% required : yes
+#%end
+#%option
+#% key: input
+#% type: string
+#% gisprompt: old,vector,vector
+#% description: Vector map of Strahler-ordered streams
+#% required : yes
+#%end
+#%option
+#% key: output
+#% type: string
+#% gisprompt: new,vector,vector
+#% description: Name of the main_channel vector map
+#% required : yes
+#%END
+#%flag
+#% key: d
+#% label: Display results
+#% description: Plot the result of elaboration in relation to the strahler ordered stream network
+#%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
+
+dem="$GIS_OPT_DEM"
+xcoor="$GIS_OPT_XCOOR"
+ycoor="$GIS_OPT_YCOOR"
+cost="$GIS_OPT_COST"
+input="$GIS_OPT_INPUT"
+output="$GIS_OPT_OUTPUT"
+
+### setup enviro vars ###
+eval `g.gisenv`
+: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
+
+g.remove vect=end_basin,out_1del,out_1add,out_basin,out_isodistance,out_2,out_2del,out_2points,out_2addp,out_3D,out_path
+
+echo "$xcoor|$ycoor|1" | v.in.ascii out=end_basin
+
+thr=`g.region -p | grep nsres | cut -f2 -d':' | tr -d ' '`
+thresh=`echo "$thr*1.5" | bc -l | cut -f1 -d'.'`
+
+
+#### setup temporary files
+TMP="`g.tempfile pid=$$`"
+if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
+ g.message -e "Unable to create temporary files"
+ exit 1
+fi
+
+v.category input=$input output=out_1del type=line option=del cat=1 layer=1 step=1
+v.category input=out_1del output=out_1add type=line option=add cat=1 layer=1 step=1
+v.net input=out_1add points=end_basin output=out_basin operation=connect \
+ alayer=1 nlayer=2 thresh="$thresh"
+v.net.iso input=out_basin output=out_isodistance type=line \
+ alayer=1 nlayer=2 ccats=1-99999999 costs=$cost
+
+echo "v.net.iso executed"
+
+v.category input=out_isodistance opt=report -g > "$TMP.1"
+grep 'line' "$TMP.1" | cut -f5 -d ' ' > "$TMP.2"
+
+v.extract input=out_isodistance output=out_2 type=line layer=1 new=-1 file="$TMP.2"
+v.category input=out_2 output=out_2del option=del \
+ type=point,line,boundary,centroid,area cat=1 layer=1 step=1
+v.net input=out_2del output=out_2points operation=nodes alayer=1 nlayer=2
+v.category input=out_2points output=out_2addp type=point option=add \
+ cat=1 layer=2 step=1
+
+v.drape input=out_2addp type=point,line rast=$dem method=nearest output=out_3D
+v.db.addtable map=out_3D table=tab_coord layer=2 \
+ 'columns=cat integer, x double precision, y double precision, z integer'
+v.to.db map=out_3D type=point layer=2 qlayer=1 option=coor units=meters 'column=x, y, z'
+v.univar -g map=out_3D type=point column=z layer=2 percentile=90 > "$TMP.3"
+
+max=`cat "$TMP.3" | grep max | cut -f2 -d'='`
+
+db_driver=`db.connect -p | grep driver | cut -f2 -d':'`
+db_database=`db.connect -p | grep database | cut -f2 -d':'`
+x_max=`db.select -c table=tab_coord database=$db_database driver=$db_driver 'sql=select x from tab_coord where z='$max''`
+y_max=`db.select -c table=tab_coord database=$db_databese driver=$db_driver 'sql=select y from tab_coord where z='$max''`
+
+echo "x_max e y_max valgono: $x_max e $y_max"
+
+echo "1 $x_max $y_max $xcoor $ycoor" | v.net.path input=out_isodistance \
+ output=$output type=line alayer=1 nlayer=2
+
+
+if [ "$GIS_FLAG_D" -eq 1 ] ; then
+ #plot the result of elaboration in relation to the strahler ordered stream network
+ #d.mon stop=x0
+ d.mon start=x0
+ d.vect "$input" display=shape,cat
+ d.vect map="$output" color=red lcolor=black fcolor=170:170:170 \
+ display=shape type=line icon=basic/x size=5 width=2 layer=1 lsize=8
+ d.barscale tcolor=black bcolor=white at=2,2
+fi
+
+
+#g.remove vect=end_basin,out_1del,out_1add,out_basin,out_2,out_2del,out_2points,out_2addp,out_3D
+
+\rm "$TMP" "$TMP".[1-3]
+
+#you can modify the "cost" distances in order to have main channel including the max_ordered channel
Deleted: grass-addons/grass6/vector/v.strahler/v.mainchannel.html
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.mainchannel.html 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/v.mainchannel.html 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,29 +0,0 @@
-<h2>DESCRIPTION</h2>
-
-<em>v.mainchannel</em> Finds the main channel of a basin starting from the vector file of the stream network.
-As first you have to visualize on the GRASS monitor the vector map wich you want to calculate the main channel for; with a scale (so you can realize the distances between the closing section and the sources) you can choose some values for the cost isolines (from the outlet); then you can individuate (by interrogating a DEM underlying the vector map) the outlet cross section coords. These coords, the selected cost values and the input/output map names have to be given in input to the program.<br />
-The program returns the main channel considering two factors:<br />
-<em>distance</em>: often the main channel is the longest track in the network<br />
-<em>height</em>: the source of the main channel is conventionally taken as the higest<br />
-This module can be used for any ordinary vector stream network, but the analisys becomes particoulary interesting if you have a vector stream network ordered by Horton-Strahler (e.g. derived from <em><a href="v.strahler.html">v.strahler</a></em> or <em><a href="r.strahler.sh.html">r.strahler.sh</a></em>) because you can see if the main channel includes the max_ordered stream, and, if not, you can consequently modify the "cost" values assigned. <br />
-
-<h2>EXAMPLE</h2>
-
-The syntax:
-
-<div class="code"><pre>
- v.mainchannel dem=dem xcoor=483456.23 ycoor=234765.33 cost=500,1000,2500,5000,10000 input=input_map output=output_map
-</pre></div>
-
-<h2>SEE ALSO</h2>
-<em><a href="v.strahler.html">v.strahler</a></em><br>
-<em><a href="r.strahler.sh.html">r.strahler.sh</a></em><br>
-<em><a href="v.net.iso.html">v.net.iso</a></em><br>
-
-<h2>AUTHORS</h2>
-
-Ivan Marchesini and Annalisa Minelli, Univ. Perugia. <br>
-
-
-<p>
-<i>Last changed: $Date$</i>
Deleted: grass-addons/grass6/vector/v.strahler/v.mainchannel.sh
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.mainchannel.sh 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/v.mainchannel.sh 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,154 +0,0 @@
-#!/bin/sh
-#
-############################################################################
-#
-# MODULE: v.mainchannel
-# AUTHOR(S): Annalisa Minelli, Ivan Marchesini
-# PURPOSE: Find the main channel of a vector stream network (useful to compare with a network ordered by Horton-Strahler)
-# COPYRIGHT: (C) 2005 by 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: Find the main channel of a vector stream network (useful to compare with a network ordered by Horton-Strahler)
-#% keywords: strahler, main_channel, vector
-#%End
-#%option
-#% key: dem
-#% type: string
-#% key_desc: dem
-#% gisprompt: old,cell,raster
-#% description: Name of DEM raster map
-#% required : yes
-#%END
-#%option
-#% key: xcoor
-#% type: double
-#% description: x coord of outlet (read by dem in the pixel where is the vector file cross section)
-#% required : yes
-#%end
-#%option
-#% key: ycoor
-#% type: double
-#% description: y coord of outlet (read by dem in the pixel where is the vector file cross section)
-#% required : yes
-#%end
-#%option
-#% key: cost
-#% type: integer
-#% description: Distance between isolines (separated by <comma>)
-#% required : yes
-#%end
-#%option
-#% key: input
-#% type: string
-#% gisprompt: old,vector,vector
-#% description: Vector map of Strahler-ordered streams
-#% required : yes
-#%end
-#%option
-#% key: output
-#% type: string
-#% gisprompt: new,vector,vector
-#% description: Name of the main_channel vector map
-#% required : yes
-#%END
-#%flag
-#% key: d
-#% label: Display results
-#% description: Plot the result of elaboration in relation to the strahler ordered stream network
-#%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
-
-dem="$GIS_OPT_DEM"
-xcoor="$GIS_OPT_XCOOR"
-ycoor="$GIS_OPT_YCOOR"
-cost="$GIS_OPT_COST"
-input="$GIS_OPT_INPUT"
-output="$GIS_OPT_OUTPUT"
-
-### setup enviro vars ###
-eval `g.gisenv`
-: ${GISBASE?} ${GISDBASE?} ${LOCATION_NAME?} ${MAPSET?}
-
-g.remove vect=end_basin,out_1del,out_1add,out_basin,out_isodistance,out_2,out_2del,out_2points,out_2addp,out_3D,out_path
-
-echo "$xcoor|$ycoor|1" | v.in.ascii out=end_basin
-
-thr=`g.region -p | grep nsres | cut -f2 -d':' | tr -d ' '`
-thresh=`echo "$thr*1.5" | bc -l | cut -f1 -d'.'`
-
-
-#### setup temporary files
-TMP="`g.tempfile pid=$$`"
-if [ $? -ne 0 ] || [ -z "$TMP" ] ; then
- g.message -e "Unable to create temporary files"
- exit 1
-fi
-
-v.category input=$input output=out_1del type=line option=del cat=1 layer=1 step=1
-v.category input=out_1del output=out_1add type=line option=add cat=1 layer=1 step=1
-v.net input=out_1add points=end_basin output=out_basin operation=connect \
- alayer=1 nlayer=2 thresh="$thresh"
-v.net.iso input=out_basin output=out_isodistance type=line \
- alayer=1 nlayer=2 ccats=1-99999999 costs=$cost
-
-echo "v.net.iso executed"
-
-v.category input=out_isodistance opt=report -g > "$TMP.1"
-grep 'line' "$TMP.1" | cut -f5 -d ' ' > "$TMP.2"
-
-v.extract input=out_isodistance output=out_2 type=line layer=1 new=-1 file="$TMP.2"
-v.category input=out_2 output=out_2del option=del \
- type=point,line,boundary,centroid,area cat=1 layer=1 step=1
-v.net input=out_2del output=out_2points operation=nodes alayer=1 nlayer=2
-v.category input=out_2points output=out_2addp type=point option=add \
- cat=1 layer=2 step=1
-
-v.drape input=out_2addp type=point,line rast=$dem method=nearest output=out_3D
-v.db.addtable map=out_3D table=tab_coord layer=2 \
- 'columns=cat integer, x double precision, y double precision, z integer'
-v.to.db map=out_3D type=point layer=2 qlayer=1 option=coor units=meters 'column=x, y, z'
-v.univar -g map=out_3D type=point column=z layer=2 percentile=90 > "$TMP.3"
-
-max=`cat "$TMP.3" | grep max | cut -f2 -d'='`
-
-db_driver=`db.connect -p | grep driver | cut -f2 -d':'`
-db_database=`db.connect -p | grep database | cut -f2 -d':'`
-x_max=`db.select -c table=tab_coord database=$db_database driver=$db_driver 'sql=select x from tab_coord where z='$max''`
-y_max=`db.select -c table=tab_coord database=$db_databese driver=$db_driver 'sql=select y from tab_coord where z='$max''`
-
-echo "x_max e y_max valgono: $x_max e $y_max"
-
-echo "1 $x_max $y_max $xcoor $ycoor" | v.net.path input=out_isodistance \
- output=$output type=line alayer=1 nlayer=2
-
-
-if [ "$GIS_FLAG_D" -eq 1 ] ; then
- #plot the result of elaboration in relation to the strahler ordered stream network
- #d.mon stop=x0
- d.mon start=x0
- d.vect "$input" display=shape,cat
- d.vect map="$output" color=red lcolor=black fcolor=170:170:170 \
- display=shape type=line icon=basic/x size=5 width=2 layer=1 lsize=8
- d.barscale tcolor=black bcolor=white at=2,2
-fi
-
-
-#g.remove vect=end_basin,out_1del,out_1add,out_basin,out_2,out_2del,out_2points,out_2addp,out_3D
-
-\rm "$TMP" "$TMP".[1-3]
-
-#you can modify the "cost" distances in order to have main channel including the max_ordered channel
Copied: grass-addons/grass6/vector/v.strahler/v.strahler/Makefile (from rev 51972, grass-addons/grass6/vector/v.strahler/Makefile)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/Makefile (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/Makefile 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,13 @@
+MODULE_TOPDIR = ../..
+
+PGM = v.strahler
+
+LIBES = $(VECTLIB) $(GPROJLIB) $(DBMILIB) $(GISLIB) $(GDALLIBS)
+DEPENDENCIES = $(VECTDEP) $(GPROJDEP) $(DBMIDEP) $(GISDEP)
+
+EXTRA_INC = $(VECT_INC) $(PROJINC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+default: cmd
Copied: grass-addons/grass6/vector/v.strahler/v.strahler/description.html (from rev 51972, grass-addons/grass6/vector/v.strahler/description.html)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/description.html (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/description.html 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,119 @@
+<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.strahler/v.strahler/forest2tree.c (from rev 51972, grass-addons/grass6/vector/v.strahler/forest2tree.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/forest2tree.c (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/forest2tree.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,114 @@
+#include "strahler.h"
+
+/* helper functions for ForestToTrees:
+ push_line: push number of adjacent line on stack
+ pop_line: return number of top line on stack
+ we could do this with some Vect_list but we don't need
+ to handle entire lines, only their identifiers */
+
+#define STACK_SIZE 65535
+int sp = 0; /* stack position */
+int stack[STACK_SIZE]; /* generous stack size */
+
+void push_line(int line)
+{
+ if (sp < STACK_SIZE) {
+ stack[sp++] = line;
+ }
+ else {
+ G_fatal_error("ForestToTrees: stack full");
+ }
+}
+
+int pop_line(void)
+{
+ if (sp > 0) {
+ return stack[--sp];
+ }
+ else {
+ G_debug(3, "ForestToTrees: stack empty, tree finished");
+ return 0;
+ }
+}
+
+
+/* or write our own lfind: nexttree() */
+/* start at offset, walk array up until bsnid == 0 and return that offset */
+
+int nexttree(DBBUF * dbbuf, int offset, int upper)
+{
+ while ((dbbuf[offset].bsnid != 0) && (offset < upper)) {
+ ++offset;
+ G_debug(4, "bsnid[%d] is %d", offset, dbbuf[offset].bsnid);
+ }
+ return offset;
+}
+
+/* Find trees, assign basinID */
+int StrahForestToTrees(struct Map_info *In, struct Map_info *Out,
+ DBBUF * dbbuf)
+{
+ int tree, tree_finished, forest_done; /* ID of tree (basin), processing status */
+ int l, n, d, degr, node; /* iterators */
+ int nlines, offset; /* number of lines, position in dbbuf */
+ int cline, aline; /* currently harvested line, adjacent line */
+ int lnodes[2]; /* nodes of cline */
+
+
+ G_debug(1, "reached StrahForestToTrees");
+
+ nlines = Vect_get_num_lines(In);
+
+ forest_done = 0;
+ tree = 1; /* we start with tree no. 1 */
+ offset = cline = 1; /* we start at line 1 */
+
+ while (forest_done == 0) {
+ G_debug(3, "\nProcessing Tree %d", tree);
+ tree_finished = 0; /* initialize status indicator for this tree */
+ while (tree_finished == 0) {
+ /* procedure to get adjacent lines and push them on the stack */
+ Vect_get_line_nodes(In, cline, &lnodes[0], &lnodes[1]);
+ G_debug(4, "nodes for line %d: %d %d", cline, lnodes[0],
+ lnodes[1]);
+
+ for (n = 0; n <= 1; n++) { /* loop through array[2] of fnode and tnode */
+ node = lnodes[n];
+ /*degr = Vect_get_node_n_lines( In, node ); */
+ degr = StrahGetDegr(In, node);
+ G_debug(4, "degr %d for node %d", degr, node);
+ for (d = 0; d < degr; d++) {
+ /*aline = abs( Vect_get_node_line( In, node, d ) ); */
+ aline = abs(StrahGetNodeLine(In, node, d));
+ if (dbbuf[aline].bsnid == 0) { /* push line on stack only if not done yet */
+ G_debug(4, "pushing line %d on sp %d", aline, sp);
+ push_line(aline);
+ G_debug(4, "pushed, sp is now %d", sp);
+ dbbuf[aline].bsnid = tree; /* line is done when pushed on stack */
+ dbbuf[aline].line = aline;
+ }
+ }
+ }
+
+ /* pop a line from stack */
+ cline = (int)pop_line();
+ G_debug(4, "popped line %d", cline);
+ /* tree is finished when pop_line returned 0 */
+ if (cline == 0) {
+ tree_finished = 1;
+ }
+ }
+
+ /* get first cline of next tree */
+ offset = cline = nexttree(dbbuf, ++offset, nlines);
+ G_debug(3, "cline/offset for tree %d is %d", tree, cline);
+ if (offset == nlines) {
+ forest_done = 1; /* what if last line still is 0 - it is a tree consisting of this line only - it shall keep bsnid 0 */
+ }
+ else {
+ tree++; /* continue with next tree */
+ }
+ }
+
+ return tree;
+}
Copied: grass-addons/grass6/vector/v.strahler/v.strahler/helper.c (from rev 51972, grass-addons/grass6/vector/v.strahler/helper.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/helper.c (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/helper.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,80 @@
+#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.strahler/v.strahler/main.c (from rev 51972, grass-addons/grass6/vector/v.strahler/main.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/main.c (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/main.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -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.strahler/v.strahler/strahler.c (from rev 51972, grass-addons/grass6/vector/v.strahler/strahler.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/strahler.c (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/strahler.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,223 @@
+#include "strahler.h"
+
+/* Find Leaves of tree and distinguish outlet from sources */
+int StrahFindLeaves(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev,
+ int ntrees, int fdrast)
+{
+ int nnodes, degr, aline, node, unode, dnode, tree, outlet;
+ double x, y, z, z_init;
+
+ int n;
+
+ struct Cell_head window;
+ INTERP_TYPE method = NEAREST;
+
+ OUTLETS *outlets;
+
+ nnodes = Vect_get_num_nodes(In);
+
+ z = z_init = 27000000.0; /* is it safe to initialize lowest z with the height of Olympus Mons above Martian Datum in millimeters? */
+
+ outlets = (OUTLETS *) G_malloc((ntrees + 1) * ((int)sizeof(OUTLETS)));
+
+ /* initialize outlet table properly */
+ for (n = 1; n <= ntrees; n++) {
+ outlets[n].z = z_init;
+ outlets[n].leaf = 0;
+ }
+
+ G_debug(1, "Reached StrahFindLeaves with %d trees", ntrees);
+
+ G_get_window(&window);
+ G_debug(2, "window: N %f S %f W %f E %f", window.north, window.south,
+ window.west, window.east);
+
+ G_debug(2, "%d nodes in map", nnodes);
+ for (node = 1; node <= nnodes; node++) {
+ /*degr = Vect_get_node_n_lines( In, node ); */
+ degr = StrahGetDegr(In, node);
+ nodev[node].node = node;
+ nodev[node].degree = degr;
+
+ G_debug(4, "node %d: degr=%d", node, degr);
+
+ if (degr == 1) {
+ unode = node;
+ nodev[node].visited = 1; /*set the "visited" parameter to 1... can't be less */
+ /*aline = abs( Vect_get_node_line( In, unode, 0 ) ); */
+ aline = abs(StrahGetNodeLine(In, unode, 0));
+ /*Vect_get_line_nodes( In, aline, &unode, &dnode); */
+ /* these are not necessarily up-node and down-node but we need not distinguish here... */
+ dbbuf[aline].sorder = 1;
+ /* no, do not visit yet
+ nodev[node].visited += 1;
+ */
+ /*
+ nodev[unode].visited += 1;
+ nodev[dnode].visited += 1;
+ */
+ /* get z value or DEM value under node here, remember lowest */
+ if (Vect_is_3d(In)) {
+ Vect_get_node_coor(In, node, &x, &y, &z);
+ }
+ else {
+ Vect_get_node_coor(In, node, &x, &y, NULL);
+ z = (double)G_get_raster_sample(fdrast, &window, NULL, y, x,
+ 0, method);
+ }
+
+ G_debug(5, "fdrast=%d node=%d y=%f x=%f z=%f", fdrast, node, y,
+ x, z);
+
+ tree = dbbuf[aline].bsnid;
+ if (z < outlets[tree].z) {
+ outlets[tree].z = z;
+ outlets[tree].leaf = aline;
+ }
+ }
+ }
+ /* reset outlets to 0 */
+ for (n = 1; n <= ntrees; n++) {
+ G_debug(2, "outlet tree %d: line %d with %f", n, outlets[n].leaf,
+ outlets[n].z);
+ outlet = outlets[n].leaf;
+ dbbuf[outlet].sorder = 0;
+ /*
+ Vect_get_line_nodes( In, outlet, &unode, &dnode);
+ nodev[unode].visited = 0;
+ nodev[dnode].visited = 0;
+ */
+ }
+ return 1;
+}
+
+/* assign strahler order */
+int StrahOrder(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev)
+{
+ int nlines, line;
+ int fnode, tnode, unode, dnode; /* from-, to-, up-, down- node */
+ int degr, d, aline, aorder; /* find adjacent lines */
+ int corder, norder, dorder, dline; /* assign order */
+ int cline, rfinish; /* follow one line until this stop-condition is 1 */
+
+ struct dbbuf;
+ struct nodev;
+
+ nlines = Vect_get_num_lines(In);
+
+ G_debug(1, "reached StrahOrder");
+
+ for (line = 1; line <= nlines; line++) {
+ if (dbbuf[line].sorder == 1) { /* get lines of order 1 */
+
+ cline = line; /* and start run downwards */
+ rfinish = 0;
+ while (rfinish == 0) {
+ G_debug(3, "reached line %d", cline);
+
+ Vect_get_line_nodes(In, cline, &fnode, &tnode); /* and their nodes */
+
+ /**** BAUSTELLE ****/
+ /* check nodes - we do not rely on flow direction */
+ if (nodev[fnode].visited == 1) {
+ unode = fnode;
+ dnode = tnode;
+ }
+ else {
+ unode = tnode;
+ dnode = fnode;
+ }
+
+ /*
+ if (nodev[fnode].visited == nodev[tnode].visited) {
+ printf("Line %d: both nodes are visited or not - what now?\n", line);
+ } else if (nodev[fnode].visited == 0) {
+ node = fnode;
+ } else {
+ node = tnode;
+ }
+ */
+
+ /*
+ if ( (nodev[fnode].degree - nodev[fnode].visited) < (nodev[tnode].degree - nodev[tnode].visited) ) {
+ unode = fnode;
+ dnode = tnode;
+ } else if ( (nodev[fnode].degree - nodev[fnode].visited) > (nodev[tnode].degree - nodev[tnode].visited) ) {
+ unode = tnode;
+ dnode = fnode;
+ } else {
+ G_message("Line %d: nodes have same diff(degree,visited) - what now?\n", cline);
+ */
+ /* ok, what now?
+ - occurs when leaf meets node with norder==0 -> visit nodes and continue
+ - or: is outlet -> assign order
+ */
+ /* continue? */
+ /*
+ printf("visiting tnode %d and fnode %d for line %d and break\n\n", tnode, fnode, cline);
+ nodev[tnode].visited += 1;
+ nodev[fnode].visited += 1;
+ break;
+ }
+ */
+
+ G_debug(3, "unode is %d and dnode is %d", unode, dnode);
+
+ /*degr = Vect_get_node_n_lines ( In, dnode ); use downward node */
+ degr = StrahGetDegr(In, dnode);
+
+ G_debug(4, "deg for dnode %d is %d", dnode, degr);
+
+ corder = dbbuf[cline].sorder; /* current order - result won't be less than that */
+ norder = dorder = 0; /* no order - how many lines have none?, highest order of others */
+ for (d = 0; d < degr; d++) {
+ /*aline = abs( Vect_get_node_line ( In, dnode, d ) ); */
+ aline = abs(StrahGetNodeLine(In, dnode, d));
+ G_debug(4, "line %d at dnode %d is %d", d, dnode, aline);
+ if (aline != cline) { /* we don't need the line we come from */
+ aorder = dbbuf[aline].sorder;
+ if (aorder == 0) {
+ norder++;
+ dline = aline; /* downward line */
+ }
+ else if (aorder > dorder) {
+ dorder = aorder; /* find highest order */
+ }
+ }
+ }
+
+ if (norder > 1 || norder == 0) { /* if (norder > 1: node indeterminate OR norder == 0 : subtree finished) */
+ G_debug(3, "Finished run at line %d because norder=%d",
+ cline, norder);
+ G_debug(4, "visiting unode %d for line %d", unode, cline);
+ nodev[unode].visited += 1; /* visit unode, for the sake of completeness */
+ rfinish = 1; /* finish this run */
+
+ }
+ else { /* or */
+ if (dorder > corder) {
+ ; /* assign highest order of alines */
+ }
+ else if (dorder < corder) {
+ dorder = corder; /* or keep order of cline */
+ }
+ else {
+ dorder++; /* or raise order by one */
+ }
+
+ dbbuf[dline].sorder = dorder; /* assign order */
+
+ G_debug(4, "visiting dnode %d and unode %d for line %d",
+ dnode, unode, cline);
+ nodev[dnode].visited += 1; /* visit dnode */
+ nodev[unode].visited += 1; /* visit unode, for the sake of completeness */
+
+ cline = dline; /* and continue with this line */
+
+ G_debug(3, "StrahOrder for dline %d: %d", dline, dorder);
+ }
+ } /* while */
+ }
+ }
+ return 1;
+}
Copied: grass-addons/grass6/vector/v.strahler/v.strahler/strahler.h (from rev 51972, grass-addons/grass6/vector/v.strahler/strahler.h)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/strahler.h (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/strahler.h 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,100 @@
+#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"
+
+/*! \typedef DBBUF
+ \brief Buffer to keep track of assigned tree and Strahler order for each line
+ */
+
+/*! \typedef NODEV
+ \brief Buffer to keep track of valency for each node
+ */
+
+/*! \typedef OUTLETS
+ \brief Buffer to determine lowest leaf of each tree
+ */
+
+typedef struct
+{ /* collect lines in Strahler order */
+ int category;
+ int line; /* line number */
+ int bsnid; /* basin ID */
+ int sorder; /* Strahler order */
+} DBBUF;
+
+typedef struct
+{ /* visited nodes */
+ int node; /* node number */
+ int degree; /* valency */
+ int visited; /* is between 0 and degr(node) */
+} NODEV;
+
+typedef struct
+{ /* keep track of lowest leaf (=outlet) of each tree */
+ double z; /* z-value of leaf */
+ int leaf; /* line-id of outlet leaf */
+} OUTLETS;
+
+/* in forest2tree.c */
+/*! \fn int StrahForestToTrees( struct Map_info *In, struct Map_info *Out, DBBUF *dbbuf );
+ \brief Returns the number of trees in *In
+ \param *In The input map
+ \param *Out The output map
+ \param *dbbuf The buffer table for line orders
+ */
+
+
+/* in strahler.c */
+/*! \fn int StrahFindLeaves( struct Map_info *In, DBBUF *dbbuf, NODEV *nodev, int ntrees, int fdrast );
+ \brief Identifies all leaves of each tree and the one that lies lowest
+ \param *In The input map
+ \param *dbbuf The buffer table for line orders
+ \param *nodev The buffer table for node valency
+ \param ntrees Number of trees in map
+ \param fdrast File descriptor of DEM raster map
+ */
+
+/*! \fn int StrahOrder( struct Map_info *In, DBBUF *dbbuf, NODEV *nodev );
+ \brief Calculates the Strahler order of each line
+ \param *In The input map
+ \param *dbbuf The buffer table for line orders
+ \param *nodev The buffer table for node valency
+ */
+
+
+/* in write.c */
+/*! \fn int StrahWriteToFile( DBBUF *dbbuf, int nlines, FILE *txout );
+ \brief Writes ASCII representation of calculated order to file
+ \param *dbbuf The buffer table for line orders
+ \param nlines Number of lines in *In map
+ \param *txout ASCII output file name
+ */
+
+
+/* in helper.c */
+/*! \fn int StrahGetDegr( struct Map_info *In, int node );
+ \brief Get degree of node (for sloppy mode)
+ \param *In The input map
+ \param node Node number in *In
+ */
+
+/*! \fn int StrahNodeLine( struct Map_info *In, int node, int d );
+ \brief Get lines connected in node (for sloppy mode)
+ \param *In The input map
+ \param node Node number in *In
+ \param d n-th line connected to node
+ */
+
+int StrahForestToTrees(struct Map_info *In, struct Map_info *Out,
+ DBBUF * dbbuf);
+int StrahFindLeaves(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev,
+ int ntrees, int fdrast);
+int StrahOrder(struct Map_info *In, DBBUF * dbbuf, NODEV * nodev);
+int StrahWriteToFile(DBBUF * dbbuf, int nlines, FILE * txout);
+int StrahGetDegr(struct Map_info *In, int node);
+int StrahGetNodeLine(struct Map_info *In, int node, int d);
Copied: grass-addons/grass6/vector/v.strahler/v.strahler/write.c (from rev 51972, grass-addons/grass6/vector/v.strahler/write.c)
===================================================================
--- grass-addons/grass6/vector/v.strahler/v.strahler/write.c (rev 0)
+++ grass-addons/grass6/vector/v.strahler/v.strahler/write.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -0,0 +1,15 @@
+#include "strahler.h"
+
+int StrahWriteToFile(DBBUF * dbbuf, int nlines, FILE * txout)
+{
+ int line;
+
+ G_debug(1, "Reached WriteToFile - writing %d lines", nlines);
+ fprintf(txout, "== Result of Strahler Order ==\n");
+ fprintf(txout, " Category: Line: Basin: Order:\n"); /*added cat column */
+ for (line = 1; line <= nlines; line++) {
+ fprintf(txout, "%9d%8d%8d%8d\n", dbbuf[line].category,
+ dbbuf[line].line, dbbuf[line].bsnid, dbbuf[line].sorder);
+ }
+ return 1;
+}
Deleted: grass-addons/grass6/vector/v.strahler/write.c
===================================================================
--- grass-addons/grass6/vector/v.strahler/write.c 2012-06-11 08:33:16 UTC (rev 52030)
+++ grass-addons/grass6/vector/v.strahler/write.c 2012-06-11 09:01:11 UTC (rev 52031)
@@ -1,15 +0,0 @@
-#include "strahler.h"
-
-int StrahWriteToFile(DBBUF * dbbuf, int nlines, FILE * txout)
-{
- int line;
-
- G_debug(1, "Reached WriteToFile - writing %d lines", nlines);
- fprintf(txout, "== Result of Strahler Order ==\n");
- fprintf(txout, " Category: Line: Basin: Order:\n"); /*added cat column */
- for (line = 1; line <= nlines; line++) {
- fprintf(txout, "%9d%8d%8d%8d\n", dbbuf[line].category,
- dbbuf[line].line, dbbuf[line].bsnid, dbbuf[line].sorder);
- }
- return 1;
-}
More information about the grass-commit
mailing list