[GRASS-SVN] r40660 - grass-addons/raster/r.stream.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jan 26 04:59:56 EST 2010


Author: mmetz
Date: 2010-01-26 04:59:48 -0500 (Tue, 26 Jan 2010)
New Revision: 40660

Modified:
   grass-addons/raster/r.stream.extract/do_astar.c
   grass-addons/raster/r.stream.extract/streams.c
Log:
fix diagonal flow bias and make stream extraction more generic

Modified: grass-addons/raster/r.stream.extract/do_astar.c
===================================================================
--- grass-addons/raster/r.stream.extract/do_astar.c	2010-01-26 09:00:22 UTC (rev 40659)
+++ grass-addons/raster/r.stream.extract/do_astar.c	2010-01-26 09:59:48 UTC (rev 40660)
@@ -104,8 +104,8 @@
 			get_slope2(ele_val, ele_nbr[ct_dir],
 				   dist_to_nbr[ct_dir]);
 		}
+		/* avoid diagonal flow direction bias */
 		if (!is_in_list) {
-		    /* avoid diagonal flow direction bias */
 		    if (ct_dir > 3 && slope[ct_dir] > 0) {
 			if (slope[nbr_ew[ct_dir]] > 0) {
 			    /* slope to ew nbr > slope to center */
@@ -289,8 +289,8 @@
 
 double get_slope2(CELL ele, CELL up_ele, double dist)
 {
-    if (ele == up_ele)
-	return 0.5 / dist;
+    if (ele >= up_ele)
+	return 0.0;
     else
 	return (double)(up_ele - ele) / dist;
 }

Modified: grass-addons/raster/r.stream.extract/streams.c
===================================================================
--- grass-addons/raster/r.stream.extract/streams.c	2010-01-26 09:00:22 UTC (rev 40659)
+++ grass-addons/raster/r.stream.extract/streams.c	2010-01-26 09:59:48 UTC (rev 40660)
@@ -643,16 +643,8 @@
 	    continue;
 	}
 
-	/* honour A * path 
-	 * mfd_cells == 0: fine, SFD along A * path
-	 * mfd_cells == 1 && astar_not_set == 0: fine, SFD along A * path
-	 * mfd_cells > 0 && astar_not_set == 1: A * path not included, add to mfd_cells
-	 */
-
-	/* MFD, A * path not included, add to mfd_cells */
-	if (mfd_cells > 0 && astar_not_set == 1) {
-	    mfd_cells++;
-	    /* get main drainage direction */
+	/* set main drainage direction to A* path if possible */
+	if (mfd_cells > 0 && max_side != np_side) {
 	    nindex = INDEX(dr, dc);
 	    if (fabs(acc[nindex]) >= max_acc) {
 		max_acc = fabs(acc[nindex]);
@@ -661,7 +653,7 @@
 		max_side = np_side;
 	    }
 	}
-	else if (mfd_cells == 0) {
+	if (mfd_cells == 0) {
 	    flat = 0;
 	    max_side = np_side;
 	}
@@ -699,8 +691,8 @@
 	    }
 	}
 
-	if (is_swale < 1 && flat == 0 && fabs(value) >= threshold &&
-	    stream_cells < 1 && swale_cells < 1) {
+	if (is_swale < 1 && fabs(value) >= threshold && stream_cells < 1 &&
+	    swale_cells < 1 && !flat) {
 	    G_debug(2, "start new stream");
 	    is_swale = stream[thisindex] = ++stream_no;
 	    /* add stream node */



More information about the grass-commit mailing list