[GRASS-SVN] r45418 - in grass-addons/grass7/raster/r.stream: . r.stream.basins r.stream.distance r.stream.order r.stream.segment r.stream.slope r.stream.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Feb 17 14:01:36 EST 2011


Author: jarekj71
Date: 2011-02-17 11:01:36 -0800 (Thu, 17 Feb 2011)
New Revision: 45418

Modified:
   grass-addons/grass7/raster/r.stream/Makefile
   grass-addons/grass7/raster/r.stream/notes
   grass-addons/grass7/raster/r.stream/r.stream.basins/basins_inputs.c
   grass-addons/grass7/raster/r.stream/r.stream.basins/main.c
   grass-addons/grass7/raster/r.stream/r.stream.distance/distance_calc.c
   grass-addons/grass7/raster/r.stream/r.stream.distance/local_vars.h
   grass-addons/grass7/raster/r.stream/r.stream.distance/main.c
   grass-addons/grass7/raster/r.stream/r.stream.order/main.c
   grass-addons/grass7/raster/r.stream/r.stream.order/stream_init.c
   grass-addons/grass7/raster/r.stream/r.stream.order/stream_vector.c
   grass-addons/grass7/raster/r.stream/r.stream.segment/main.c
   grass-addons/grass7/raster/r.stream/r.stream.segment/stream_segment.c
   grass-addons/grass7/raster/r.stream/r.stream.segment/stream_vector.c
   grass-addons/grass7/raster/r.stream/r.stream.slope/main.c
   grass-addons/grass7/raster/r.stream/r.stream.stats/io.h
   grass-addons/grass7/raster/r.stream/r.stream.stats/local_vars.h
Log:
bug fix in r.stream files

Modified: grass-addons/grass7/raster/r.stream/Makefile
===================================================================
--- grass-addons/grass7/raster/r.stream/Makefile	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/Makefile	2011-02-17 19:01:36 UTC (rev 45418)
@@ -4,8 +4,13 @@
 	r.stream.order \
 	r.stream.baisns \
 	r.stream.distance \
-	r.stream.stats
+	r.stream.stats \
+	r.stream.slope \
+	r.stream.channel \
+	r.stream.segment \
+	r.stream.snap
 
+
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 
 default: parsubdirs

Modified: grass-addons/grass7/raster/r.stream/notes
===================================================================
--- grass-addons/grass7/raster/r.stream/notes	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/notes	2011-02-17 19:01:36 UTC (rev 45418)
@@ -1 +1 @@
-this is only a working version and backup copy of incoming r.stream version for GRASS 7. We not support it as well as do not fix bugs till release. However we are iterested in proposition of new features.
+pre-relase version

Modified: grass-addons/grass7/raster/r.stream/r.stream.basins/basins_inputs.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.basins/basins_inputs.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.basins/basins_inputs.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -46,7 +46,7 @@
     struct Map_info Map;
     struct bound_box box;
     int num_point = 0;
-    int type, i, cat;
+    int type, i,j, cat;
     int r,c;
     struct line_pnts *sites;
     struct line_cats *cats;
@@ -74,9 +74,9 @@
 
     outlets = (OUTLET *) G_malloc(num_point * sizeof(OUTLET));
 
-    for (i = 0; i < num_point; ++i) {
+    for (j = 0; j < num_point; ++j) {
 
-	type = Vect_read_line(&Map, sites, cats, i + 1);
+	type = Vect_read_line(&Map, sites, cats, j + 1);
 	if (type != GV_POINT)
 	    continue;
 
@@ -89,7 +89,8 @@
 	outlets[i].c = (int)Rast_easting_to_col(sites->x[0], &window);
 	outlets[i].val = cat;
     }
-    return num_point;
+	i++;    
+	return num_point;
 }
 
 int ram_process_streams(char** cat_list, CELL** streams, int number_of_streams, CELL** dirs, int lasts, int cats)
@@ -121,12 +122,12 @@
 		   for (r = 0; r < nrows; ++r) 
 		for (c = 0; c < ncols; ++c)
 	if (streams[r][c]>0) {
-
-			if (outlets_num > 2 * (out_max - 1))
+			if (outlets_num > 6 * (out_max - 1))
 		G_fatal_error(_
 				("Stream and direction maps probably do not match"));
+
 			if (outlets_num > (out_max - 1))
-		outlets = (OUTLET *)G_realloc(outlets,out_max*2*sizeof(OUTLET));
+		outlets = (OUTLET *)G_realloc(outlets,out_max*6*sizeof(OUTLET));
 
 		d = abs(dirs[r][c]);	/* r.watershed */
 
@@ -206,12 +207,12 @@
 
 	segment_get(streams,&streams_cell,r,c);
 	if (streams_cell>0) {
-
-			if (outlets_num > 2 * (out_max - 1))
+			if (outlets_num > 6 * (out_max - 1))
 		G_fatal_error
 				("Stream and direction maps probably do not match");
+
 			if (outlets_num > (out_max - 1))
-		outlets = (OUTLET *)G_realloc(outlets,out_max*2*sizeof(OUTLET));
+		outlets = (OUTLET *)G_realloc(outlets,out_max*6*sizeof(OUTLET));
 
 		segment_get(dirs,&dirs_cell,r,c);
 		d = abs(dirs_cell);	/* abs */

Modified: grass-addons/grass7/raster/r.stream/r.stream.basins/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.basins/main.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.basins/main.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -124,7 +124,7 @@
 	G_fatal_error(_("One basin's outlet definition is required"));
 
 	  if (in_stm_cat_opt->answers && !in_stm_opt->answer)
-	G_fatal_error(_("With cats, stream file is required"));
+	G_fatal_error(_("If cats stream file is required"));
 
 		if (in_coor_opt->answers)
 	b_test += 1;

Modified: grass-addons/grass7/raster/r.stream/r.stream.distance/distance_calc.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.distance/distance_calc.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.distance/distance_calc.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -324,7 +324,7 @@
 	struct Cell_head window;
 	
 	Rast_get_window(&window);
-	
+		
 				if(elevation) {
 		elevation_data_size=Rast_cell_size(FCELL_TYPE);			
 		  for (r = 0; r < nrows; ++r) 
@@ -333,7 +333,7 @@
 				
     for (r = 0; r < nrows; ++r) 
 	for (c = 0; c < ncols; ++c) {
-
+	
 	    for (i = 1; i < 9; ++i) {
 		if (NOT_IN_REGION(i)) 
 		    continue;	/* out of border */
@@ -341,9 +341,9 @@
 		j = DIAG(i);
 		next_r=NR(i);
 		next_c=NC(i);
-				if (dirs[next_r][next_c] == j && distance[r][c] != 0) {	/* is contributing cell */
-		  distance[r][c] = -1;
-		  break;
+			if (dirs[next_r][next_c] == j && distance[r][c] != 0) {	/* is contributing cell */
+			distance[r][c] = -1;
+			break;
 				}
 	    }
 	  if (distance[r][c] == 1 && dirs[r][c] > 0)
@@ -360,7 +360,7 @@
 
 	    if (distance[r][c] == 1) {
 		
-		distance[r][c] = 0;
+		distance[r][c] =  0;
 			if (elevation)
 		elevation[r][c] = 0;
 
@@ -372,6 +372,7 @@
 		d_inits[k].r = r;
 		d_inits[k].c = c;
 		d_inits[k].cur_dist = 0;
+		
 
 			if (elevation)
 		d_inits[k].target_elev = tmp_elevation[r][c];
@@ -381,7 +382,7 @@
 	}
 
     counter = n_inits = k;
-
+	//return 0; // do usunięcia
 	G_message("Calculate upstream parameters...");		
     while (n_inits > 0) {
 	k = 0;
@@ -405,7 +406,6 @@
 	  cur_dist =	tmp_dist + 
 			G_distance(easting, northing, cell_easting, cell_northing);
 		
-		
 	    if (near)
 		done = (distance[next_r][next_c] > cur_dist ||
 			distance[next_r][next_c] <=0) ? 1 : 0;

Modified: grass-addons/grass7/raster/r.stream/r.stream.distance/local_vars.h
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.distance/local_vars.h	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.distance/local_vars.h	2011-02-17 19:01:36 UTC (rev 45418)
@@ -33,6 +33,7 @@
 GLOBAL int nrows, ncols;
 GLOBAL int fifo_max;
 GLOBAL POINT* fifo_points;
+GLOBAL int accum;
 
 
 

Modified: grass-addons/grass7/raster/r.stream/r.stream.distance/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.distance/main.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.distance/main.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -91,7 +91,7 @@
   out_dist_opt = G_define_standard_option(G_OPT_R_OUTPUT);
   out_dist_opt->key = "distance";
   out_dist_opt->required=NO;
-  out_dist_opt->description = "Output distance map";
+  out_dist_opt->description = "Output distance/accumulation map";
 
   out_diff_opt = G_define_standard_option(G_OPT_R_OUTPUT);
   out_diff_opt->key = "difference";
@@ -112,7 +112,7 @@
   flag_near->key = 'n';
   flag_near->description =
 	_("Calculate nearest local maximum (ignored in downstream calculation)");
-	
+
 	flag_segmentation = G_define_flag();
   flag_segmentation->key = 'm';
   flag_segmentation->description = _("Use memory swap (operation is slow)");
@@ -142,7 +142,7 @@
   subs = (flag_sub->answer != 0);
   near = (flag_near->answer != 0);
   segmentation = (flag_segmentation->answer != 0);
-		
+
 	nrows = Rast_window_rows();
   ncols = Rast_window_cols();
 	G_begin_distance_calculations();

Modified: grass-addons/grass7/raster/r.stream/r.stream.order/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.order/main.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.order/main.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -219,7 +219,6 @@
 		
 	seg_create_map(&map_streams,SROWS, SCOLS, number_of_segs, CELL_TYPE);
 	seg_read_map(&map_streams,in_streams,1,CELL_TYPE);
-	seg_write_map(&map_streams,"test_streams",CELL_TYPE,0,0);
 	seg_create_map(&map_dirs,SROWS, SCOLS, number_of_segs, CELL_TYPE);
 	seg_read_map(&map_dirs,in_dirs,1,CELL_TYPE);
 	stream_init((int)map_streams.min,(int)map_streams.max);

Modified: grass-addons/grass7/raster/r.stream/r.stream.order/stream_init.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.order/stream_init.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.order/stream_init.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -35,7 +35,7 @@
 	all_orders[i]=(int*)G_malloc((number_of_streams+1)*sizeof(int));
 
 			for(i=0;i<orders_size;++i)
-		for(j=0;j<number_of_streams;++j)
+		for(j=0;j<number_of_streams+1;++j)
 	all_orders[i][j]=-1;
 
     return 0;

Modified: grass-addons/grass7/raster/r.stream/r.stream.order/stream_vector.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.order/stream_vector.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.order/stream_vector.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -164,8 +164,8 @@
 	}
 
 /* build vector after adding table */
-//	if(0<stream_add_table(number_of_streams))
-//G_warning(_("Cannot add table to vector %s"),out_vector);
+	if(0<stream_add_table(number_of_streams))
+G_warning(_("Cannot add table to vector %s"),out_vector);
 Vect_hist_command(&Out);
 Vect_build(&Out);
 Vect_close(&Out);
@@ -207,7 +207,7 @@
 	int scheidegger, drwal_old=-1;
 	double sinusoid=1, elev_drop, out_drop=0, gradient=-1;
 	double flow_accum;
-	char insert_orders[20]; /* must have to be increased if new orders are added */
+	char insert_orders[60]; /* must have to be increased if new orders are added */
 
 	db_init_string(&db_sql);
 	db_init_string(&val_string);
@@ -230,10 +230,10 @@
 	tab_prev_streams="prev_str01 integer, prev_str02 integer, prev_str03 integer";
 	break;
 		case 4:
-	tab_prev_streams="prev_str01 integer, prev_str02 integer, prev_str03 integer prev_str04 integer";
+	tab_prev_streams="prev_str01 integer, prev_str02 integer, prev_str03 integer, prev_str04 integer";
 	break;
 		case 5:
-	tab_prev_streams="prev_str01 integer, prev_str02 integer, prev_str03 integer prev_str04 integer, prev_str05 integer";
+	tab_prev_streams="prev_str01 integer, prev_str02 integer, prev_str03 integer, prev_str04 integer, prev_str05 integer";
 	break;
 		default:
 	G_fatal_error("Error with number of tributuaries");

Modified: grass-addons/grass7/raster/r.stream/r.stream.segment/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.segment/main.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.segment/main.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -223,14 +223,14 @@
 
 
 
-/*	
-		int i;
+	
+
 		for(i=1;i<number_of_streams;++i)
 	G_message("%d %d %d",stream_attributes[i].stream,
 		stream_attributes[i].next_stream, 
 		stream_attributes[i].last_cell_dir); 
-*/
 
+
 /*
 		for(i=1;i<number_of_streams;++i)
 			printf("STREAM %d NEXT_STREAM %d POINT %d \n",
@@ -240,6 +240,7 @@
 
 */		
 	G_message("Creating sectors and calculating attributes...");
+		
 		for(i=1;i<number_of_streams;++i) {
 	create_sectors(&stream_attributes[i],seg_length, seg_skip,seg_treshold);
 	calc_tangents(&stream_attributes[i],seg_length,seg_skip,number_of_streams);

Modified: grass-addons/grass7/raster/r.stream/r.stream.segment/stream_segment.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.segment/stream_segment.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.segment/stream_segment.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -223,8 +223,8 @@
 	cur_stream->length=calc_length(cur_stream->distance,1,last_cell);
 	cur_stream->stright=calc_stright(r_up,c_up,r_down,c_down);
 	cur_stream->drop=calc_drop(cur_stream->elevation,1,last_cell);
-	
-		if(next_stream==-1) {
+
+		if(next_stream<1) {
 	cur_stream->tangent=-1;
 	cur_stream->continuation=-1;	
 	return 0;
@@ -251,12 +251,12 @@
 	cell_down = i >= (SA[next_stream].number_of_cells-seg_length) ?
 		SA[next_stream].number_of_cells-seg_length-1 : seg_length;
 	
-	r=(int)P[i]/ncols;
-	c=(int)P[i]%ncols;
-	r_up=(int)P[i-cell_up]/ncols;
-	c_up=(int)P[i-cell_up]%ncols;
-	r_down=(int)P[i+cell_down]/ncols;
-	c_down=(int)P[i+cell_down]%ncols;
+	r=(int)SA[next_stream].points[i]/ncols;
+	c=(int)SA[next_stream].points[i]%ncols;
+	r_up=(int)SA[next_stream].points[i-cell_up]/ncols;
+	c_up=(int)SA[next_stream].points[i-cell_up]%ncols;
+	r_down=(int)SA[next_stream].points[i+cell_down]/ncols;
+	c_down=(int)SA[next_stream].points[i+cell_down]%ncols;
 	
 	cur_stream->continuation=calc_dir(r,c,r_down,c_down);
 	cur_stream->tangent = i==1 ? -1 :

Modified: grass-addons/grass7/raster/r.stream/r.stream.segment/stream_vector.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.segment/stream_vector.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.segment/stream_vector.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -32,7 +32,8 @@
 	stop=1;
 			for(j=0;j<SA[i].number_of_sectors;++j) {
 		start=stop;
-		stop=SA[i].sector_breakpoints[j];
+		stop= (j==SA[i].number_of_sectors-1) ?
+				SA[i].sector_breakpoints[j]+1 : SA[i].sector_breakpoints[j]+1;
 		Vect_cat_set(Cats, 1, SA[i].sector_cats[j]);
 				for(k=start;k<=stop;++k) {
 					if(SA[i].points[k]==-1) {
@@ -307,12 +308,14 @@
 		if(!radians) {
 	direction=RAD2DEG(direction);
 	azimuth=RAD2DEG(azimuth);
-	out_direction=RAD2DEG(direction);
-	out_azimuth=RAD2DEG(azimuth);		
-	next_direction=RAD2DEG(direction);
-	next_azimuth=RAD2DEG(azimuth);	
+	out_direction=RAD2DEG(out_direction);
+	out_azimuth=RAD2DEG(out_azimuth);		
+	tangent_dir=RAD2DEG(tangent_dir);
+	tangent_azimuth=RAD2DEG(tangent_azimuth);	
+	next_direction=RAD2DEG(next_direction);
+	next_azimuth=RAD2DEG(next_azimuth);	
 		}
-	
+
 	sprintf(buf,"insert into %s values( %d, %d, %d, %d, %d, \
 																			%f, %f, %f, %f, %f, \
 																			%f, %f, %f, %f,			\

Modified: grass-addons/grass7/raster/r.stream/r.stream.slope/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.slope/main.c	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.slope/main.c	2011-02-17 19:01:36 UTC (rev 45418)
@@ -312,7 +312,8 @@
 			j=i;
 				}
 		}	
-		
+		if(elev_max==-1000)
+	elev_max=elev_rows[r][c];	
 	diff_up=elev_max-elev_rows[r][c];
 	diff_down=elev_rows[r][c] - elev_rows[NR(d)][NC(d)];
 	diff_elev = elev_max-elev_rows[NR(d)][NC(d)];
@@ -361,6 +362,8 @@
 		}	
 
 		
+		if(elev_min==9999)
+	elev_min=elev_rows[r][c];	
 	diff_up=elev_min-elev_rows[r][c];
 	diff_down=elev_rows[r][c] - elev_rows[NR(d)][NC(d)];
 	diff_elev = elev_min-elev_rows[NR(d)][NC(d)];

Modified: grass-addons/grass7/raster/r.stream/r.stream.stats/io.h
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.stats/io.h	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.stats/io.h	2011-02-17 19:01:36 UTC (rev 45418)
@@ -6,8 +6,6 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/segment.h>
-#include <grass/vector.h>
-#include <grass/dbmi.h>
 
 #define NOT_IN_REGION(x) (r+nextr[(x)] < 0 || r+nextr[(x)] > (nrows-1) || c+nextc[(x)] < 0 || c+nextc[(x)] > (ncols-1))
 #define NR(x) r + nextr[(x)]

Modified: grass-addons/grass7/raster/r.stream/r.stream.stats/local_vars.h
===================================================================
--- grass-addons/grass7/raster/r.stream/r.stream.stats/local_vars.h	2011-02-17 13:14:09 UTC (rev 45417)
+++ grass-addons/grass7/raster/r.stream/r.stream.stats/local_vars.h	2011-02-17 19:01:36 UTC (rev 45418)
@@ -5,8 +5,6 @@
 #include <grass/glocale.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
-#include <grass/vector.h>
-#include <grass/dbmi.h>
 
 #define SQRT2 1.414214
 	



More information about the grass-commit mailing list