[GRASS-SVN] r67309 - in grass/branches/releasebranch_6_4/raster/r.watershed: ram seg
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Dec 21 14:17:28 PST 2015
Author: mmetz
Date: 2015-12-21 14:17:28 -0800 (Mon, 21 Dec 2015)
New Revision: 67309
Modified:
grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_astar.c
grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c
grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_astar.c
grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c
Log:
r.watershed: fix correction for diagonal flow bias
Modified: grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_astar.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_astar.c 2015-12-21 15:58:18 UTC (rev 67308)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_astar.c 2015-12-21 22:17:28 UTC (rev 67309)
@@ -71,8 +71,9 @@
/* 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;
- /* check that r, c are within region */
+ 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);
/* check if neighbour is in the list */
@@ -87,16 +88,16 @@
get_slope2(alt_val, alt_nbr[ct_dir],
dist_to_nbr[ct_dir]);
}
- if (!is_in_list) {
+ 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) {
+ 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]],
@@ -107,12 +108,12 @@
}
/* add neighbour as new point if not in the list */
- if (is_in_list == 0 && skip_diag == 0) {
+ if (!is_in_list && !skip_diag) {
add_pt(upr, upc, alt_nbr[ct_dir], alt_val);
/* set flow direction */
asp[index_up] = drain[upr - r + 1][upc - c + 1];
}
- else if (is_in_list && is_worked == 0) {
+ else if (!is_worked && !skip_diag && slope[ct_dir] > 0) {
/* neighbour is edge in list, not yet worked */
if (asp[index_up] < 0) {
asp[index_up] = drain[upr - r + 1][upc - c + 1];
Modified: grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c 2015-12-21 15:58:18 UTC (rev 67308)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c 2015-12-21 22:17:28 UTC (rev 67309)
@@ -198,7 +198,7 @@
stream_cells++;
is_worked = FLAG_GET(worked, r_nbr, c_nbr);
- if (is_worked == 0) {
+ if (!is_worked) {
is_null = G_is_c_null_value(&ele_nbr);
edge = is_null;
if (ele_nbr != ele)
@@ -225,6 +225,8 @@
if (dr == r_nbr && dc == c_nbr) {
astar_not_set = 0;
}
+ if (value < 0 && valued > 0)
+ wat[nbr_index] = -valued;
}
}
if (dr == r_nbr && dc == c_nbr)
Modified: grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_astar.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_astar.c 2015-12-21 15:58:18 UTC (rev 67308)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_astar.c 2015-12-21 22:17:28 UTC (rev 67309)
@@ -79,12 +79,14 @@
/* 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;
- /* check that upr, upc are within region */
+ 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) {
/* avoid diagonal flow direction bias */
bseg_get(&in_list, &in_val, upr, upc);
bseg_get(&worked, &work_val, upr, upc);
+ cseg_get(&asp, &asp_up, upr, upc);
skip_diag = 0;
if (!work_val) {
cseg_get(&alt, &alt_up, upr, upc);
@@ -93,16 +95,16 @@
get_slope2(alt_val, alt_nbr[ct_dir],
dist_to_nbr[ct_dir]);
}
- if (!in_val) {
+ if (!in_val || (!work_val && asp_up < 0)) {
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]],
@@ -112,15 +114,14 @@
}
}
/* put neighbour in search list if not yet in */
- if (in_val == 0 && skip_diag == 0) {
+ if (!skip_diag && !in_val) {
add_pt(upr, upc, alt_nbr[ct_dir], alt_val);
/* flow direction is set here */
drain_val = drain[upr - r + 1][upc - c + 1];
cseg_put(&asp, &drain_val, upr, upc);
}
/* check if neighbour has not been worked on */
- else if (in_val && !work_val) {
- cseg_get(&asp, &asp_up, upr, upc);
+ else if (!skip_diag && in_val && !work_val && slope[ct_dir] > 0) {
if (asp_up < 0) {
drain_val = drain[upr - r + 1][upc - c + 1];
cseg_put(&asp, &drain_val, upr, upc);
Modified: grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c 2015-12-21 15:58:18 UTC (rev 67308)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c 2015-12-21 22:17:28 UTC (rev 67309)
@@ -241,6 +241,10 @@
if (dr == r_nbr && dc == c_nbr) {
astar_not_set = 0;
}
+ if (value < 0 && wat_nbr[ct_dir] > 0) {
+ valued = -wat_nbr[ct_dir];
+ dseg_put(&wat, &valued, r_nbr, c_nbr);
+ }
}
}
if (dr == r_nbr && dc == c_nbr)
More information about the grass-commit
mailing list