From 5fb7351feb78c41e995fc9169b0001de8917447c Mon Sep 17 00:00:00 2001 From: Huidae Cho Date: Thu, 17 Mar 2022 22:52:46 -0400 Subject: [PATCH] r.watershed: Null accumulation outside elevation, 0 flow from null flow (#2221) * r.watershed: Null accumulation outside elevation * Null flow amount as 0 --- raster/r.watershed/ram/init_vars.c | 10 ++++------ raster/r.watershed/seg/init_vars.c | 4 ---- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/raster/r.watershed/ram/init_vars.c b/raster/r.watershed/ram/init_vars.c index 487d486da4f..4bbf629409c 100644 --- a/raster/r.watershed/ram/init_vars.c +++ b/raster/r.watershed/ram/init_vars.c @@ -190,7 +190,6 @@ int init_vars(int argc, char *argv[]) /* read elevation input and mark NULL/masked cells */ /* initialize accumulation and drainage direction */ - MASK_flag = 0; do_points = nrows * ncols; for (r = 0; r < nrows; r++) { Rast_get_row(fd, elebuf, r, ele_map_type); @@ -243,8 +242,7 @@ int init_vars(int argc, char *argv[]) } Rast_close(fd); G_free(elebuf); - if (do_points < nrows * ncols) - MASK_flag = 1; + MASK_flag = (do_points < nrows * ncols); /* read flow accumulation from input map flow: amount of overland flow per cell */ if (run_flag) { @@ -253,12 +251,12 @@ int init_vars(int argc, char *argv[]) for (r = 0; r < nrows; r++) { Rast_get_d_row(fd, dbuf, r); for (c = 0; c < ncols; c++) { - if (MASK_flag) { + if (Rast_is_d_null_value(&dbuf[c])) + wat[SEG_INDEX(wat_seg, r, c)] = 0.0; + else if (MASK_flag) { block_value = FLAG_GET(worked, r, c); if (!block_value) wat[SEG_INDEX(wat_seg, r, c)] = dbuf[c]; - else - wat[SEG_INDEX(wat_seg, r, c)] = 0.0; } else wat[SEG_INDEX(wat_seg, r, c)] = dbuf[c]; diff --git a/raster/r.watershed/seg/init_vars.c b/raster/r.watershed/seg/init_vars.c index fadebbf0ced..cbe17d4bd80 100644 --- a/raster/r.watershed/seg/init_vars.c +++ b/raster/r.watershed/seg/init_vars.c @@ -24,7 +24,6 @@ int init_vars(int argc, char *argv[]) WAT_ALT wa, *wabuf; ASP_FLAG af, af_nbr, *afbuf; A_TANB sca_tanb; - char MASK_flag; void *elebuf, *ptr, *watbuf, *watptr; int ele_map_type, wat_map_type; size_t ele_size, wat_size; @@ -310,7 +309,6 @@ int init_vars(int argc, char *argv[]) /* read elevation input and mark NULL/masked cells */ G_message("SECTION 1a: Mark masked and NULL cells"); - MASK_flag = 0; do_points = (GW_LARGE_INT) nrows *ncols; for (r = 0; r < nrows; r++) { @@ -402,8 +400,6 @@ int init_vars(int argc, char *argv[]) G_free(watbuf); } - MASK_flag = (do_points < nrows * ncols); - /* read retention map to adjust flow distribution (AG) */ if (rtn_flag) { char rtn_value;