Browse Source

r.stream.extract: add network id to vector output

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@71599 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 7 years ago
parent
commit
7a97f750a1
2 changed files with 19 additions and 11 deletions
  1. 10 3
      raster/r.stream.extract/close.c
  2. 9 8
      raster/r.stream.extract/r.stream.extract.html

+ 10 - 3
raster/r.stream.extract/close.c

@@ -30,6 +30,7 @@ int close_streamvect(char *stream_vect)
     struct Cell_head window;
     double north_offset, west_offset, ns_res, ew_res;
     int next_cat;
+    int *network_id;
 
     G_message(_("Writing vector map <%s>..."), stream_vect);
 
@@ -37,6 +38,9 @@ int close_streamvect(char *stream_vect)
 	G_fatal_error(_("Unable to create vector map <%s>"), stream_vect);
     
     nodestack = (struct sstack *)G_malloc(stack_step * sizeof(struct sstack));
+    network_id = G_malloc((n_stream_nodes + 1) * sizeof(int));
+    for (i = 0; i <= n_stream_nodes; i++)
+	network_id[i] = 0;
 
     Points = Vect_new_line_struct();
     Cats = Vect_new_cats_struct();
@@ -58,6 +62,7 @@ int close_streamvect(char *stream_vect)
 	if (!stream_id)
 	    continue;
 
+	network_id[stream_id] = i + 1;
 	Vect_reset_line(Points);
 	Vect_reset_cats(Cats);
 
@@ -106,6 +111,7 @@ int close_streamvect(char *stream_vect)
 	    if (done) {
 		G_debug(3, "write stream segment");
 
+		network_id[stream_id] = i + 1;
 		Vect_reset_line(Points);
 		Vect_reset_cats(Cats);
 
@@ -178,7 +184,7 @@ int close_streamvect(char *stream_vect)
     G_debug(1, "database: %s", Fi->database);
 
     sprintf(buf,
-	    "create table %s (%s integer, stream_type varchar(20), type_code integer)",
+	    "create table %s (%s integer, stream_type varchar(20), type_code integer, network integer)",
 	    Fi->table, cat_col_name);
     db_set_string(&dbsql, buf);
 
@@ -200,10 +206,10 @@ int close_streamvect(char *stream_vect)
     /* stream nodes */
     for (i = 1; i <= n_stream_nodes; i++) {
 
-	sprintf(buf, "insert into %s values ( %lld, \'%s\', %d )",
+	sprintf(buf, "insert into %s values ( %lld, \'%s\', %d, %d )",
 		Fi->table, i,
 		(stream_node[i].n_trib > 0 ? "intermediate" : "start"),
-		(stream_node[i].n_trib > 0));
+		(stream_node[i].n_trib > 0), network_id[i]);
 
 	db_set_string(&dbsql, buf);
 
@@ -228,6 +234,7 @@ int close_streamvect(char *stream_vect)
     Vect_close(&Out);
 
     G_free(nodestack);
+    G_free(network_id);
 
     return 1;
 }

+ 9 - 8
raster/r.stream.extract/r.stream.extract.html

@@ -148,14 +148,15 @@ Output <b>stream_vector</b> vector map stores extracted stream segments
 and points. Points are written at the start location of each stream
 segment and at the outlet of a stream network. In layer 1, categories
 are unique IDs, identical to the cell value of the raster output. The
-attribute table for layer 1 holds information about the type of stream
-segment: start segment, or intermediate segment with
-tributaries. Columns are <tt>cat int, stream_type varchar(), type_code
-int</tt>. The encoding for type_code is 0 = start, 1 =
-intermediate. In layer 2, categories are identical to type_code in
-layer 1 with additional category 2 = outlet for outlet points. Points
-with category 1 = intermediate in layer 2 are at the location of
-confluences.
+attribute table for layer 1 holds information about the type of stream 
+segment: start segment, or intermediate segment with tributaries, and 
+about the stream network this stream or node belongs to. Columns are 
+<tt>cat int,stream_type varchar(),type_code int,network int</tt>. The 
+network attribute is the network ID of the stream/node. The encoding 
+for type_code is 0 = start, 1 = intermediate. In layer 2, categories 
+are identical to type_code in layer 1 with additional category 2 = 
+outlet for outlet points. Points with category 1 = intermediate in 
+layer 2 are at the location of confluences.
 
 <h2>EXAMPLE</h2>