瀏覽代碼

r.li: fix total area: sample area without NULL cells

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@62583 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 10 年之前
父節點
當前提交
c809e81703

+ 9 - 12
raster/r.li/r.li.cwed/cwed.c

@@ -365,12 +365,11 @@ int calculate(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	    if (masked && mask_corr[i] == 0) {
 	    if (masked && mask_corr[i] == 0) {
 		Rast_set_c_null_value(&corrCell, 1);
 		Rast_set_c_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 	    
 	    
 	    if (!(Rast_is_null_value(&corrCell, CELL_TYPE))) {
 	    if (!(Rast_is_null_value(&corrCell, CELL_TYPE))) {
+		/* total sample area */
+		area += 1;
+
 		supCell = buf_sup[i + ad->x];
 		supCell = buf_sup[i + ad->x];
 		if (masked && (mask_sup[i] == 0)) {
 		if (masked && (mask_sup[i] == 0)) {
 		    Rast_set_c_null_value(&supCell, 1);
 		    Rast_set_c_null_value(&supCell, 1);
@@ -512,12 +511,11 @@ int calculateD(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	    if (masked && mask_corr[i] == 0) {
 	    if (masked && mask_corr[i] == 0) {
 		Rast_set_d_null_value(&corrCell, 1);
 		Rast_set_d_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 
 
 	    if (!(Rast_is_null_value(&corrCell, DCELL_TYPE))) {
 	    if (!(Rast_is_null_value(&corrCell, DCELL_TYPE))) {
+		/* total sample area */
+		area += 1;
+
 		supCell = buf_sup[i + ad->x];
 		supCell = buf_sup[i + ad->x];
 		if (masked && (mask_sup[i] == 0)) {
 		if (masked && (mask_sup[i] == 0)) {
 		    Rast_set_d_null_value(&supCell, 1);
 		    Rast_set_d_null_value(&supCell, 1);
@@ -660,12 +658,11 @@ int calculateF(int fd, struct area_entry *ad, Coppie * cc, long totCoppie,
 	    if (masked && mask_corr[i] == 0) {
 	    if (masked && mask_corr[i] == 0) {
 		Rast_set_f_null_value(&corrCell, 1);
 		Rast_set_f_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 
 
 	    if (!(Rast_is_null_value(&corrCell, FCELL_TYPE))) {
 	    if (!(Rast_is_null_value(&corrCell, FCELL_TYPE))) {
+		/* total sample area */
+		area += 1;
+
 		supCell = buf_sup[i + ad->x];
 		supCell = buf_sup[i + ad->x];
 		if (masked && (mask_sup[i] == 0)) {
 		if (masked && (mask_sup[i] == 0)) {
 		    Rast_set_f_null_value(&supCell, 1);
 		    Rast_set_f_null_value(&supCell, 1);

+ 3 - 3
raster/r.li/r.li.edgedensity/edgedensity.c

@@ -200,7 +200,7 @@ int calculate(int fd, struct area_entry *ad, char **par, double *result)
 	    if (masked && mask_buf[j] == 0) {
 	    if (masked && mask_buf[j] == 0) {
 		Rast_set_c_null_value(&corrCell, 1);
 		Rast_set_c_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
+	    if (!Rast_is_c_null_value(&corrCell)) {
 		/* total sample area */
 		/* total sample area */
 		area++;
 		area++;
 	    }
 	    }
@@ -378,7 +378,7 @@ int calculateD(int fd, struct area_entry *ad, char **par, double *result)
 	    if (masked && mask_buf[j] == 0) {
 	    if (masked && mask_buf[j] == 0) {
 		Rast_set_d_null_value(&corrCell, 1);
 		Rast_set_d_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
+	    if (!Rast_is_d_null_value(&corrCell)) {
 		/* total sample area */
 		/* total sample area */
 		area++;
 		area++;
 	    }
 	    }
@@ -556,7 +556,7 @@ int calculateF(int fd, struct area_entry *ad, char **par, double *result)
 	    if (masked && mask_buf[j] == 0) {
 	    if (masked && mask_buf[j] == 0) {
 		Rast_set_f_null_value(&corrCell, 1);
 		Rast_set_f_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
+	    if (!Rast_is_f_null_value(&corrCell)) {
 		/* total sample area */
 		/* total sample area */
 		area++;
 		area++;
 	    }
 	    }

+ 6 - 12
raster/r.li/r.li.patchdensity/main.c

@@ -207,10 +207,6 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_c_null_value(&corrCell, 1);
 		Rast_set_c_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total landscape area */
-		area++;
-	    }
 
 
 	    if (Rast_is_c_null_value(&corrCell)) {
 	    if (Rast_is_c_null_value(&corrCell)) {
 		connected = 0;
 		connected = 0;
@@ -218,6 +214,8 @@ int calculate(int fd, struct area_entry *ad, double *result)
 		continue;
 		continue;
 	    }
 	    }
 
 
+	    area++;
+
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {
 		Rast_set_c_null_value(&supCell, 1);
 		Rast_set_c_null_value(&supCell, 1);
@@ -432,10 +430,6 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_d_null_value(&corrCell, 1);
 		Rast_set_d_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total landscape area */
-		area++;
-	    }
 
 
 	    if (Rast_is_d_null_value(&corrCell)) {
 	    if (Rast_is_d_null_value(&corrCell)) {
 		connected = 0;
 		connected = 0;
@@ -443,6 +437,8 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 		continue;
 		continue;
 	    }
 	    }
 
 
+	    area++;
+
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {
 		Rast_set_d_null_value(&supCell, 1);
 		Rast_set_d_null_value(&supCell, 1);
@@ -657,10 +653,6 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_f_null_value(&corrCell, 1);
 		Rast_set_f_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total landscape area */
-		area++;
-	    }
 
 
 	    if (Rast_is_f_null_value(&corrCell)) {
 	    if (Rast_is_f_null_value(&corrCell)) {
 		connected = 0;
 		connected = 0;
@@ -668,6 +660,8 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 		continue;
 		continue;
 	    }
 	    }
 
 
+	    area++;
+
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {
 		Rast_set_f_null_value(&supCell, 1);
 		Rast_set_f_null_value(&supCell, 1);

+ 3 - 18
raster/r.li/r.li.shape/main.c

@@ -112,7 +112,7 @@ int calculate(int fd, struct area_entry *ad, double *result)
 {
 {
     CELL *buf, *buf_sup, *buf_null;
     CELL *buf, *buf_sup, *buf_null;
     CELL corrCell, precCell, supCell;
     CELL corrCell, precCell, supCell;
-    long npatch, area; 
+    long npatch; 
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     struct pst *pst;
     struct pst *pst;
     long nalloc, incr;
     long nalloc, incr;
@@ -158,7 +158,6 @@ int calculate(int fd, struct area_entry *ad, double *result)
 
 
     /* calculate number of patches */
     /* calculate number of patches */
     npatch = 0;
     npatch = 0;
-    area = 0;
     pid = 0;
     pid = 0;
 
 
     /* patch size and type */
     /* patch size and type */
@@ -204,10 +203,6 @@ int calculate(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_c_null_value(&corrCell, 1);
 		Rast_set_c_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 
 
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {
@@ -351,7 +346,7 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 {
 {
     DCELL *buf, *buf_sup, *buf_null;
     DCELL *buf, *buf_sup, *buf_null;
     DCELL corrCell, precCell, supCell;
     DCELL corrCell, precCell, supCell;
-    long npatch, area; 
+    long npatch; 
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     struct pst *pst;
     struct pst *pst;
     long nalloc, incr;
     long nalloc, incr;
@@ -397,7 +392,6 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 
 
     /* calculate number of patches */
     /* calculate number of patches */
     npatch = 0;
     npatch = 0;
-    area = 0;
     pid = 0;
     pid = 0;
 
 
     /* patch size and type */
     /* patch size and type */
@@ -443,10 +437,6 @@ int calculateD(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_d_null_value(&corrCell, 1);
 		Rast_set_d_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 
 
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {
@@ -590,7 +580,7 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 {
 {
     FCELL *buf, *buf_sup, *buf_null;
     FCELL *buf, *buf_sup, *buf_null;
     FCELL corrCell, precCell, supCell;
     FCELL corrCell, precCell, supCell;
-    long npatch, area; 
+    long npatch; 
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     long pid, old_pid, new_pid, *pid_corr, *pid_sup, *ltmp;
     struct pst *pst;
     struct pst *pst;
     long nalloc, incr;
     long nalloc, incr;
@@ -636,7 +626,6 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 
 
     /* calculate number of patches */
     /* calculate number of patches */
     npatch = 0;
     npatch = 0;
-    area = 0;
     pid = 0;
     pid = 0;
 
 
     /* patch size and type */
     /* patch size and type */
@@ -682,10 +671,6 @@ int calculateF(int fd, struct area_entry *ad, double *result)
 	    if (masked && (mask_buf[j] == 0)) {
 	    if (masked && (mask_buf[j] == 0)) {
 		Rast_set_f_null_value(&corrCell, 1);
 		Rast_set_f_null_value(&corrCell, 1);
 	    }
 	    }
-	    else {
-		/* total sample area */
-		area++;
-	    }
 
 
 	    supCell = buf_sup[j + ad->x];
 	    supCell = buf_sup[j + ad->x];
 	    if (masked && (mask_sup[j] == 0)) {
 	    if (masked && (mask_sup[j] == 0)) {