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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 9 12:07:30 PST 2019


Author: mmetz
Date: 2019-03-09 12:07:30 -0800 (Sat, 09 Mar 2019)
New Revision: 74212

Modified:
   grass/trunk/raster/r.watershed/ram/do_cum.c
   grass/trunk/raster/r.watershed/seg/do_cum.c
Log:
r.watershed: prepare for multiple flow direction output

Modified: grass/trunk/raster/r.watershed/ram/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/do_cum.c	2019-03-09 20:05:24 UTC (rev 74211)
+++ grass/trunk/raster/r.watershed/ram/do_cum.c	2019-03-09 20:07:30 UTC (rev 74212)
@@ -271,7 +271,7 @@
     /* MFD */
     int mfd_cells, stream_cells, swale_cells, astar_not_set, is_null;
     double *dist_to_nbr, *contour, *weight, sum_weight, max_weight;
-    int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
+    int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side, max_side;
     CELL ele, ele_nbr, aspect, is_worked;
     double prop, max_val;
     int workedon, edge, flat;
@@ -339,7 +339,6 @@
 	    ele = alt[this_index];
 	    is_null = 0;
 	    edge = 0;
-	    mfdir = 0;
 	    /* this loop is needed to get the sum of weights */
 	    for (ct_dir = 0; ct_dir < sides; ct_dir++) {
 		/* get r, c (r_nbr, c_nbr) for neighbours */
@@ -429,8 +428,6 @@
 			is_worked = FLAG_GET(worked, r_nbr, c_nbr);
 			if (is_worked == 0) {
 
-			    mfdir |= (1 << nextmfd[ct_dir]);
-
 			    nbr_index = SEG_INDEX(wat_seg, r_nbr, c_nbr);
 
 			    weight[ct_dir] = weight[ct_dir] / sum_weight;
@@ -532,6 +529,9 @@
 
 	    /* get max flow accumulation */
 	    max_val = -1;
+	    max_side = 0;
+	    mfd_cells = 0;
+	    mfdir = 0;
 	    stream_cells = 0;
 	    swale_cells = 0;
 	    ele = alt[this_index];
@@ -570,7 +570,12 @@
 			    max_val = ABS(valued);
 			    r_max = r_nbr;
 			    c_max = c_nbr;
+			    max_side = ct_dir;
 			}
+			if (!is_null && ele_nbr <= ele) {
+			    mfdir |= (1 << nextmfd[ct_dir]);
+			    mfd_cells++;
+			}
 		    }
 		}
 		else
@@ -595,6 +600,9 @@
 		    aspect = -aspect;
 		asp[this_index] = aspect;
 	    }
+	    if (mfd_cells == 1)
+		mfdir = (1 << nextmfd[max_side]);
+
 	    is_swale = FLAG_GET(swale, r, c);
 	    /* start new stream */
 	    value = ABS(value) + 0.5;

Modified: grass/trunk/raster/r.watershed/seg/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_cum.c	2019-03-09 20:05:24 UTC (rev 74211)
+++ grass/trunk/raster/r.watershed/seg/do_cum.c	2019-03-09 20:07:30 UTC (rev 74212)
@@ -290,7 +290,7 @@
     /* MFD */
     int mfd_cells, stream_cells, swale_cells, astar_not_set, is_null;
     double *dist_to_nbr, *contour, *weight, sum_weight, max_weight;
-    int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
+    int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side, max_side;
     CELL ele, *ele_nbr;
     double prop, max_val;
     int workedon, edge, is_swale, flat;
@@ -466,9 +466,6 @@
 			c_nbr < ncols && weight[ct_dir] > -0.5) {
 
 			if (FLAG_GET(flag_nbr[ct_dir], WORKEDFLAG)) {
-
-			    mfdir |= (1 << nextmfd[ct_dir]);
-
 			    weight[ct_dir] = weight[ct_dir] / sum_weight;
 			    /* check everything adds up to 1.0 */
 			    prop += weight[ct_dir];
@@ -588,6 +585,9 @@
 
 	    /* get max flow accumulation */
 	    max_val = -1;
+	    max_side = 0;
+	    mfd_cells = 0;
+	    mfdir = 0;
 	    stream_cells = 0;
 	    swale_cells = 0;
 	    ele = wa.ele;
@@ -634,7 +634,12 @@
 			    max_val = ABS(wa.wat);
 			    r_max = r_nbr;
 			    c_max = c_nbr;
+			    max_side = ct_dir;
 			}
+			if (!is_null && ele_nbr[ct_dir] <= ele) {
+			    mfdir |= (1 << nextmfd[ct_dir]);
+			    mfd_cells++;
+			}
 		    }
 		}
 		else
@@ -659,6 +664,9 @@
 		else
 		    af.asp = drain[r - r_max + 1][c - c_max + 1];
 	    }
+	    if (mfd_cells == 1)
+		mfdir = (1 << nextmfd[max_side]);
+
 	    is_swale = FLAG_GET(af.flag, SWALEFLAG);
 	    /* start new stream */
 	    if (!is_swale && fabs(value) >= threshold && stream_cells < 1 &&



More information about the grass-commit mailing list