Skip to content

Commit

Permalink
r.watershed: Keep 0 accumulation with -a as 0 as opposed to null (OSG…
Browse files Browse the repository at this point in the history
…eo#2169)

* r.watershed: Keep 0 accumulation with -a as 0 as opposed to null

* apply the same change to seg
  • Loading branch information
HuidaeCho authored and neteler committed Nov 7, 2023
1 parent ac1cfa1 commit 97b2ed4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
34 changes: 12 additions & 22 deletions raster/r.watershed/ram/close_maps.c
Expand Up @@ -34,34 +34,24 @@ int close_maps(void)
G_message("Writing out only positive flow accumulation values.");
G_message
("Cells with a likely underestimate for flow accumulation can no longer be identified.");
for (r = 0; r < nrows; r++) {
Rast_set_d_null_value(dbuf, ncols); /* reset row to all NULL */
for (c = 0; c < ncols; c++) {
dvalue = wat[SEG_INDEX(wat_seg, r, c)];
if (Rast_is_d_null_value(&dvalue) == 0 && dvalue) {
dvalue = ABS(dvalue);
dbuf[c] = dvalue;
sum += dvalue;
sum_sqr += dvalue * dvalue;
}
}
Rast_put_row(fd, dbuf, DCELL_TYPE);
}
}
else {
for (r = 0; r < nrows; r++) {
Rast_set_d_null_value(dbuf, ncols); /* reset row to all NULL */
for (c = 0; c < ncols; c++) {
dvalue = wat[SEG_INDEX(wat_seg, r, c)];
if (!Rast_is_d_null_value(&dvalue)) {
dbuf[c] = dvalue;
for (r = 0; r < nrows; r++) {
Rast_set_d_null_value(dbuf, ncols); /* reset row to all NULL */
for (c = 0; c < ncols; c++) {
dvalue = wat[SEG_INDEX(wat_seg, r, c)];
if (!Rast_is_d_null_value(&dvalue)) {
if (abs_acc) {
dvalue = ABS(dvalue);
sum += dvalue;
sum_sqr += dvalue * dvalue;
}
else
sum += ABS(dvalue);

dbuf[c] = dvalue;
sum_sqr += dvalue * dvalue;
}
Rast_put_row(fd, dbuf, DCELL_TYPE);
}
Rast_put_row(fd, dbuf, DCELL_TYPE);
}
Rast_close(fd);

Expand Down
2 changes: 1 addition & 1 deletion raster/r.watershed/seg/close_maps.c
Expand Up @@ -40,7 +40,7 @@ int close_maps(void)
for (c = 0; c < ncols; c++) {
/* dseg_get(&wat, &dvalue, r, c); */
dvalue = wabuf[c].wat;
if (Rast_is_d_null_value(&dvalue) == 0 && dvalue) {
if (!Rast_is_d_null_value(&dvalue)) {
if (abs_acc) {
dvalue = fabs(dvalue);
sum += dvalue;
Expand Down

0 comments on commit 97b2ed4

Please sign in to comment.