Browse Source

r.watershed: fix correction for diagonal flow bias

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@67301 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 9 years ago
parent
commit
806c52a3af

+ 5 - 5
raster/r.watershed/ram/do_astar.c

@@ -133,8 +133,8 @@ int do_astar(void)
 			get_slope2(alt_val, alt_nbr[ct_dir],
 				   dist_to_nbr[ct_dir]);
 		}
-		if (!is_worked) {
-		    if (ct_dir > 3 && slope[ct_dir] >= 0) {
+		if (!is_in_list || (!is_worked && asp[index_up] < 0)) {
+		    if (ct_dir > 3 && slope[ct_dir] > 0) {
 			if (slope[nbr_ew[ct_dir]] >= 0) {
 			    /* slope to ew nbr > slope to center */
 			    if (slope[ct_dir] <
@@ -154,14 +154,14 @@ int do_astar(void)
 
 		if (!skip_diag) {
 		    /* add neighbour as new point if not in the list */
-		    if (is_in_list == 0) {
+		    if (!is_in_list) {
 			add_pt(upr, upc, alt_nbr[ct_dir]);
 			/* set flow direction */
 			asp[index_up] = drain[upr - r + 1][upc - c + 1];
 		    }
-		    else if (is_in_list && is_worked == 0 && slope[ct_dir] > 0) {
+		    else if (!is_worked) {
 			/* neighbour is edge in list, not yet worked */
-			if (asp[index_up] < 0) {
+			if (asp[index_up] < 0 && slope[ct_dir] > 0) {
 			    /* adjust flow direction for edge cell */
 			    asp[index_up] = drain[upr - r + 1][upc - c + 1];
 

+ 4 - 0
raster/r.watershed/ram/do_cum.c

@@ -173,6 +173,8 @@ int do_cum(void)
 		    aspect = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
 		    asp[this_index] = aspect;
 		}
+		if (valued > 0)
+		    wat[down_index] = -valued;
 		continue;
 	    }
 
@@ -357,6 +359,8 @@ int do_cum_mfd(void)
 			    if (dr == r_nbr && dc == c_nbr) {
 				astar_not_set = 0;
 			    }
+			    if (value < 0 && valued > 0)
+				wat[nbr_index] = -valued;
 			}
 		    }
 		}

+ 5 - 5
raster/r.watershed/seg/do_astar.c

@@ -86,8 +86,8 @@ int do_astar(void)
 			get_slope2(alt_val, alt_nbr[ct_dir],
 				   dist_to_nbr[ct_dir]);
 		}
-		if (!is_worked) {
-		    if (ct_dir > 3 && slope[ct_dir] >= 0) {
+		if (!is_in_list || (!is_worked && af.asp < 0)) {
+		    if (ct_dir > 3 && slope[ct_dir] > 0) {
 			if (slope[nbr_ew[ct_dir]] >= 0) {
 			    /* slope to ew nbr > slope to center */
 			    if (slope[ct_dir] <
@@ -107,16 +107,16 @@ int do_astar(void)
 
 		if (!skip_diag) {
 		    /* add neighbour as new point if not in the list */
-		    if (is_in_list == 0) {
+		    if (!is_in_list) {
 			/* set flow direction */
 			af.asp = drain[upr - r + 1][upc - c + 1];
 			add_pt(upr, upc, alt_nbr[ct_dir]);
 			FLAG_SET(af.flag, INLISTFLAG);
 			seg_put(&aspflag, (char *)&af, upr, upc);
 		    }
-		    else if (is_in_list && is_worked == 0 && slope[ct_dir] > 0) {
+		    else if (!is_worked) {
 			/* neighbour is edge in list, not yet worked */
-			if (af.asp < 0) {
+			if (af.asp < 0 && slope[ct_dir] > 0) {
 			    /* adjust flow direction for edge cell */
 			    af.asp = drain[upr - r + 1][upc - c + 1];
 			    seg_put(&aspflag, (char *)&af, upr, upc);

+ 10 - 0
raster/r.watershed/seg/do_cum.c

@@ -162,6 +162,12 @@ int do_cum(void)
 		    af.asp = -1 * drain[r - dr + 1][c - dc + 1];
 		}
 		seg_put(&aspflag, (char *)&af, r, c);
+		seg_get(&watalt, (char *)&wadown, dr, dc);
+		valued = wadown.wat;
+		if (valued > 0) {
+		    wadown.wat = -valued;
+		    seg_put(&watalt, (char *)&wadown, dr, dc);
+		}
 		continue;
 	    }
 
@@ -384,6 +390,10 @@ int do_cum_mfd(void)
 			    if (dr == r_nbr && dc == c_nbr) {
 				astar_not_set = 0;
 			    }
+			    if (value < 0 && wat_nbr[ct_dir] > 0) {
+				wa.wat = -wat_nbr[ct_dir];
+				seg_put(&watalt, (char *)&wa, r_nbr, c_nbr);
+			    }
 			}
 		    }
 		}