ソースを参照

r.watershed: Keep 0 accumulation with -a as 0 as opposed to null (#2169)

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

* apply the same change to seg
Huidae Cho 3 年 前
コミット
792b8900d2
2 ファイル変更13 行追加23 行削除
  1. 12 22
      raster/r.watershed/ram/close_maps.c
  2. 1 1
      raster/r.watershed/seg/close_maps.c

+ 12 - 22
raster/r.watershed/ram/close_maps.c

@@ -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);
 

+ 1 - 1
raster/r.watershed/seg/close_maps.c

@@ -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;