[GRASS-SVN] r51607 - in grass/trunk/raster/r.watershed: ram seg

svn_grass at osgeo.org svn_grass at osgeo.org
Wed May 9 06:22:40 EDT 2012


Author: mmetz
Date: 2012-05-09 03:22:39 -0700 (Wed, 09 May 2012)
New Revision: 51607

Modified:
   grass/trunk/raster/r.watershed/ram/def_basin.c
   grass/trunk/raster/r.watershed/ram/do_cum.c
   grass/trunk/raster/r.watershed/seg/def_basin.c
   grass/trunk/raster/r.watershed/seg/do_cum.c
Log:
r.watershed: fix drainage directions

Modified: grass/trunk/raster/r.watershed/ram/def_basin.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/def_basin.c	2012-05-09 10:18:57 UTC (rev 51606)
+++ grass/trunk/raster/r.watershed/ram/def_basin.c	2012-05-09 10:22:39 UTC (rev 51607)
@@ -17,7 +17,7 @@
 		    if (r == row && c == col)
 			continue;
 		    value = asp[SEG_INDEX(asp_seg, r, c)];
-		    if (value < -1)
+		    if (value < 0)
 			value = -value;
 		    if (value == drain[rr][cc]) {
 			value = FLAG_GET(swale, r, c);
@@ -52,7 +52,7 @@
 		    if (direction == drain[rr][cc]) {
 			thisdir = updrain[rr][cc];
 			switch (haf_basin_side
-				(oldupdir, (int) downdir, thisdir)) {
+				(oldupdir, downdir, thisdir)) {
 			case LEFT:
 			    overland_cells(r, c, basin_num, basin_num - 1,
 					   &new_elev);

Modified: grass/trunk/raster/r.watershed/ram/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/do_cum.c	2012-05-09 10:18:57 UTC (rev 51606)
+++ grass/trunk/raster/r.watershed/ram/do_cum.c	2012-05-09 10:22:39 UTC (rev 51607)
@@ -263,7 +263,7 @@
     double *dist_to_nbr, *contour, *weight, sum_weight, max_weight;
     int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
     CELL ele, ele_nbr, aspect, is_worked;
-    double prop, max_acc;
+    double prop, max_val;
     int workedon, edge, flat;
     int asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
@@ -405,7 +405,7 @@
 	    }
 
 	    /* set flow accumulation for neighbours */
-	    max_acc = -1;
+	    max_val = -1;
 	    tci_div = sum_contour = 0.;
 
 	    if (mfd_cells > 1) {
@@ -429,6 +429,13 @@
 					   weight[ct_dir];
 			    }
 
+			    /* get main drainage direction */
+			    if (weight[ct_dir] > max_val) {
+				max_val = weight[ct_dir];
+				r_max = r_nbr;
+				c_max = c_nbr;
+			    }
+
 			    weight[ct_dir] = weight[ct_dir] / sum_weight;
 			    /* check everything adds up to 1.0 */
 			    prop += weight[ct_dir];
@@ -447,13 +454,6 @@
 				    valued = value * weight[ct_dir] - valued;
 			    }
 			    wat[nbr_index] = valued;
-			    
-			    /* get main drainage direction */
-			    if (ABS(valued) >= max_acc) {
-				max_acc = ABS(valued);
-				r_max = r_nbr;
-				c_max = c_nbr;
-			    }
 			}
 			else if (ct_dir == np_side) {
 			    /* check for consistency with A * path */

Modified: grass/trunk/raster/r.watershed/seg/def_basin.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/def_basin.c	2012-05-09 10:18:57 UTC (rev 51606)
+++ grass/trunk/raster/r.watershed/seg/def_basin.c	2012-05-09 10:22:39 UTC (rev 51607)
@@ -20,7 +20,7 @@
 			continue;
 		    seg_get(&aspflag, (char *)&af, r, c);
 		    asp_value = af.asp;
-		    if (asp_value < -1)
+		    if (asp_value < 0)
 			asp_value = -asp_value;
 		    if (asp_value == drain[rr][cc]) {
 			if (FLAG_GET(af.flag, SWALEFLAG)) {

Modified: grass/trunk/raster/r.watershed/seg/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_cum.c	2012-05-09 10:18:57 UTC (rev 51606)
+++ grass/trunk/raster/r.watershed/seg/do_cum.c	2012-05-09 10:22:39 UTC (rev 51607)
@@ -281,7 +281,7 @@
     double *dist_to_nbr, *contour, *weight, sum_weight, max_weight;
     int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
     CELL ele, *ele_nbr;
-    double prop, max_acc;
+    double prop, max_val;
     int workedon, edge, is_swale, flat;
     char *flag_nbr;
     int asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
@@ -437,7 +437,7 @@
 	    }
 
 	    /* set flow accumulation for neighbours */
-	    max_acc = -1;
+	    max_val = -1;
 	    tci_div = sum_contour = 0.;
 
 	    if (mfd_cells > 1) {
@@ -459,6 +459,13 @@
 					   weight[ct_dir];
 			    }
 
+			    /* get main drainage direction */
+			    if (weight[ct_dir] > max_val) {
+				max_val = weight[ct_dir];
+				r_max = r_nbr;
+				c_max = c_nbr;
+			    }
+
 			    weight[ct_dir] = weight[ct_dir] / sum_weight;
 			    /* check everything adds up to 1.0 */
 			    prop += weight[ct_dir];
@@ -479,13 +486,6 @@
 			    wa.wat = valued;
 			    wa.ele = ele_nbr[ct_dir];
 			    seg_put(&watalt, (char *)&wa, r_nbr, c_nbr);
-
-			    /* get main drainage direction */
-			    if (fabs(wat_nbr[ct_dir]) >= max_acc) {
-				max_acc = ABS(wat_nbr[ct_dir]);
-				r_max = r_nbr;
-				c_max = c_nbr;
-			    }
 			}
 			else if (ct_dir == np_side) {
 			    /* check for consistency with A * path */



More information about the grass-commit mailing list