[GRASS-SVN] r51605 - in
grass/branches/releasebranch_6_4/raster/r.watershed: ram seg
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed May 9 06:18:03 EDT 2012
Author: mmetz
Date: 2012-05-09 03:18:03 -0700 (Wed, 09 May 2012)
New Revision: 51605
Modified:
grass/branches/releasebranch_6_4/raster/r.watershed/ram/def_basin.c
grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c
grass/branches/releasebranch_6_4/raster/r.watershed/seg/def_basin.c
grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c
Log:
r.watershed: fix drainage directions
Modified: grass/branches/releasebranch_6_4/raster/r.watershed/ram/def_basin.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/ram/def_basin.c 2012-05-09 06:06:00 UTC (rev 51604)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/ram/def_basin.c 2012-05-09 10:18:03 UTC (rev 51605)
@@ -18,7 +18,7 @@
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
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);
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 2012-05-09 06:06:00 UTC (rev 51604)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/ram/do_cum.c 2012-05-09 10:18:03 UTC (rev 51605)
@@ -108,7 +108,7 @@
int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
double dx, dy;
CELL ele, ele_nbr, aspect, is_worked;
- double prop, max_acc;
+ double prop, max_val;
int workedon, edge, flat;
SHORT asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
SHORT asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
@@ -259,7 +259,7 @@
}
/* set flow accumulation for neighbours */
- max_acc = -1;
+ max_val = -1;
if (mfd_cells > 1) {
prop = 0.0;
@@ -276,6 +276,13 @@
nbr_index = SEG_INDEX(wat_seg, r_nbr, c_nbr);
+ /* 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 sums up to 1.0 */
prop += weight[ct_dir];
@@ -294,13 +301,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/branches/releasebranch_6_4/raster/r.watershed/seg/def_basin.c
===================================================================
--- grass/branches/releasebranch_6_4/raster/r.watershed/seg/def_basin.c 2012-05-09 06:06:00 UTC (rev 51604)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/seg/def_basin.c 2012-05-09 10:18:03 UTC (rev 51605)
@@ -19,7 +19,7 @@
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
cseg_get(&asp, &value, r, c);
- if (value < -1)
+ if (value < 0)
value = -value;
if (value == drain[rr][cc]) {
bseg_get(&swale, &value, r, c);
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 2012-05-09 06:06:00 UTC (rev 51604)
+++ grass/branches/releasebranch_6_4/raster/r.watershed/seg/do_cum.c 2012-05-09 10:18:03 UTC (rev 51605)
@@ -113,7 +113,7 @@
int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
double dx, dy;
CELL ele, ele_nbr, asp_val, asp_val2, cvalue, *worked_nbr;
- double prop, max_acc;
+ double prop, max_val;
int workedon, edge, flat;
SHORT asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
SHORT asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
@@ -275,7 +275,7 @@
}
/* set flow accumulation for neighbours */
- max_acc = -1;
+ max_val = -1;
if (mfd_cells > 1) {
prop = 0.0;
@@ -290,6 +290,13 @@
/* bseg_get(&worked, &is_worked, r_nbr, c_nbr); */
if (worked_nbr[ct_dir] == 0) {
+ /* 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 sums up to 1.0 */
prop += weight[ct_dir];
@@ -308,13 +315,6 @@
}
valued = wat_nbr[ct_dir];
dseg_put(&wat, &valued, r_nbr, c_nbr);
-
- /* get main drainage direction */
- if (ABS(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