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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 17 00:33:04 PST 2015


Author: mmetz
Date: 2015-12-17 00:33:04 -0800 (Thu, 17 Dec 2015)
New Revision: 67189

Modified:
   grass/trunk/raster/r.watershed/ram/do_astar.c
   grass/trunk/raster/r.watershed/seg/do_astar.c
Log:
r.watershed: fix correction for diagonal flow bias

Modified: grass/trunk/raster/r.watershed/ram/do_astar.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/do_astar.c	2015-12-17 08:11:23 UTC (rev 67188)
+++ grass/trunk/raster/r.watershed/ram/do_astar.c	2015-12-17 08:33:04 UTC (rev 67189)
@@ -95,7 +95,8 @@
 	    /* get r, c (upr, upc) for this neighbour */
 	    upr = r + nextdr[ct_dir];
 	    upc = c + nextdc[ct_dir];
-	    slope[ct_dir] = alt_nbr[ct_dir] = 0;
+	    slope[ct_dir] = -1;
+	    alt_nbr[ct_dir] = 0;
 	    /* check if r, c are within region */
 	    if (upr >= 0 && upr < nrows && upc >= 0 && upc < ncols) {
 		index_up = SEG_INDEX(alt_seg, upr, upc);
@@ -132,16 +133,16 @@
 			get_slope2(alt_val, alt_nbr[ct_dir],
 				   dist_to_nbr[ct_dir]);
 		}
-		if (!is_in_list) {
+		if (!is_worked) {
 		    if (ct_dir > 3 && slope[ct_dir] > 0) {
-			if (slope[nbr_ew[ct_dir]] > 0) {
+			if (slope[nbr_ew[ct_dir]] >= 0) {
 			    /* slope to ew nbr > slope to center */
 			    if (slope[ct_dir] <
 				get_slope2(alt_nbr[nbr_ew[ct_dir]],
 					   alt_nbr[ct_dir], ew_res))
 				skip_diag = 1;
 			}
-			if (!skip_diag && slope[nbr_ns[ct_dir]] > 0) {
+			if (!skip_diag && slope[nbr_ns[ct_dir]] >= 0) {
 			    /* slope to ns nbr > slope to center */
 			    if (slope[ct_dir] <
 				get_slope2(alt_nbr[nbr_ns[ct_dir]],
@@ -158,9 +159,10 @@
 			/* set flow direction */
 			asp[index_up] = drain[upr - r + 1][upc - c + 1];
 		    }
-		    else if (is_in_list && is_worked == 0) {
+		    else if (is_in_list && is_worked == 0 && slope[ct_dir] > 0) {
 			/* neighbour is edge in list, not yet worked */
 			if (asp[index_up] < 0) {
+			    /* adjust flow direction for edge cell */
 			    asp[index_up] = drain[upr - r + 1][upc - c + 1];
 
 			    if (wat[index_doer] > 0)

Modified: grass/trunk/raster/r.watershed/seg/do_astar.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_astar.c	2015-12-17 08:11:23 UTC (rev 67188)
+++ grass/trunk/raster/r.watershed/seg/do_astar.c	2015-12-17 08:33:04 UTC (rev 67189)
@@ -70,7 +70,8 @@
 	    /* get r, c (upr, upc) for this neighbour */
 	    upr = r + nextdr[ct_dir];
 	    upc = c + nextdc[ct_dir];
-	    slope[ct_dir] = alt_nbr[ct_dir] = 0;
+	    slope[ct_dir] = -1;
+	    alt_nbr[ct_dir] = 0;
 	    /* check if upr, upc are within region */
 	    if (upr >= 0 && upr < nrows && upc >= 0 && upc < ncols) {
 		seg_get(&aspflag, (char *)&af, upr, upc);
@@ -85,16 +86,16 @@
 			get_slope2(alt_val, alt_nbr[ct_dir],
 				   dist_to_nbr[ct_dir]);
 		}
-		if (!is_in_list) {
+		if (!is_worked) {
 		    if (ct_dir > 3 && slope[ct_dir] > 0) {
-			if (slope[nbr_ew[ct_dir]] > 0) {
+			if (slope[nbr_ew[ct_dir]] >= 0) {
 			    /* slope to ew nbr > slope to center */
 			    if (slope[ct_dir] <
 				get_slope2(alt_nbr[nbr_ew[ct_dir]],
 					   alt_nbr[ct_dir], ew_res))
 				skip_diag = 1;
 			}
-			if (!skip_diag && slope[nbr_ns[ct_dir]] > 0) {
+			if (!skip_diag && slope[nbr_ns[ct_dir]] >= 0) {
 			    /* slope to ns nbr > slope to center */
 			    if (slope[ct_dir] <
 				get_slope2(alt_nbr[nbr_ns[ct_dir]],
@@ -113,8 +114,7 @@
 			FLAG_SET(af.flag, INLISTFLAG);
 			seg_put(&aspflag, (char *)&af, upr, upc);
 		    }
-		    else if (is_in_list && is_worked == 0 &&
-			     FLAG_GET(af.flag, EDGEFLAG)) {
+		    else if (is_in_list && is_worked == 0 && slope[ct_dir] > 0) {
 			/* neighbour is edge in list, not yet worked */
 			if (af.asp < 0) {
 			    /* adjust flow direction for edge cell */



More information about the grass-commit mailing list