[GRASS-SVN] r62685 - grass/trunk/raster/r.li/r.li.edgedensity

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Nov 9 06:47:35 PST 2014


Author: mmetz
Date: 2014-11-09 06:47:35 -0800 (Sun, 09 Nov 2014)
New Revision: 62685

Modified:
   grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
Log:
r.li.edgedensity: add flag to exclude border egdes

Modified: grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c
===================================================================
--- grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c	2014-11-09 14:44:36 UTC (rev 62684)
+++ grass/trunk/raster/r.li/r.li.edgedensity/edgedensity.c	2014-11-09 14:47:35 UTC (rev 62685)
@@ -32,9 +32,12 @@
 int calculateD(int fd, struct area_entry *ad, char **par, double *result);
 int calculateF(int fd, struct area_entry *ad, char **par, double *result);
 
+static int brdr = 1;
+
 int main(int argc, char *argv[])
 {
     struct Option *raster, *conf, *output, *class;
+    struct Flag *flag_brdr;
     struct GModule *module;
     char **par = NULL;
 
@@ -66,7 +69,11 @@
     class->description = _("It can be integer, double or float; "
 			   "it will be changed in function of map type");
 
+    flag_brdr = G_define_flag();
+    flag_brdr->key = 'b';
+    flag_brdr->description = _("Exclude border edges");
 
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -75,6 +82,7 @@
     else
 	par = &class->answer;
 
+    brdr = flag_brdr->answer == 0;
 
     return calculateIndex(conf->answer, edgedensity, par, raster->answer,
 			  output->answer);
@@ -206,33 +214,62 @@
 		Rast_set_c_null_value(&supCell, 1);
 	    }
 
-	    if (!Rast_is_c_null_value(&corrCell)) {
-		area++; 
-	        if (Rast_is_c_null_value(&ptype) || corrCell == ptype) {
-		    
-		    if (Rast_is_c_null_value(&precCell) || precCell != corrCell) {
-			nedges++;
+	    if (brdr) {
+		if (!Rast_is_c_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_c_null_value(&ptype) || corrCell == ptype) {
+			if (Rast_is_c_null_value(&precCell) || precCell != corrCell) {
+			    nedges++;
+			}
+			if (Rast_is_c_null_value(&supCell) || supCell != corrCell) {
+			    nedges++;
+			}
+			/* right and bottom */
+			if (i == ad->rl - 1)
+			    nedges++;
+			if (j == ad->cl - 1)
+			    nedges++;
 		    }
-		    if (Rast_is_c_null_value(&supCell) || supCell != corrCell) {
-			nedges++;
+		}
+		else /* corrCell == NULL */ {
+		    if (!Rast_is_c_null_value(&precCell)) {
+			if (Rast_is_c_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
-		    /* right and bottom */
-		    if (i == ad->rl - 1)
-			nedges++;
-		    if (j == ad->cl - 1)
-			nedges++;
+		    if (!Rast_is_c_null_value(&supCell)) {
+			if (Rast_is_c_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
-	    else /* corrCell == NULL */ {
-		if (!Rast_is_c_null_value(&precCell)) {
-		    if (Rast_is_c_null_value(&ptype) || precCell == ptype) {
-			nedges++;
+	    else {
+		/* exclude border edges */
+		if (!Rast_is_c_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_c_null_value(&ptype) || corrCell == ptype) {
+			if (j > 0 && !(masked && mask_buf[j - 1] == 0) &&
+			    (Rast_is_c_null_value(&precCell) || precCell != corrCell)) {
+			    nedges++;
+			}
+			if (i > 0 && !(masked && mask_sup[i - 1] == 0) &&
+			    (Rast_is_c_null_value(&supCell) || supCell != corrCell)) {
+			    nedges++;
+			}
 		    }
 		}
-		if (!Rast_is_c_null_value(&supCell)) {
-		    if (Rast_is_c_null_value(&ptype) || supCell == ptype) {
-			nedges++;
+		else if (Rast_is_c_null_value(&corrCell) && !(masked && mask_buf[j] == 0)) {
+		    if (!Rast_is_c_null_value(&precCell)) {
+			if (Rast_is_c_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
+		    if (!Rast_is_c_null_value(&supCell)) {
+			if (Rast_is_c_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
 	    precCell = corrCell;
@@ -365,33 +402,62 @@
 		Rast_set_d_null_value(&supCell, 1);
 	    }
 
-	    if (!Rast_is_d_null_value(&corrCell)) {
-		area++; 
-	        if (Rast_is_d_null_value(&ptype) || corrCell == ptype) {
-		    
-		    if (Rast_is_d_null_value(&precCell) || precCell != corrCell) {
-			nedges++;
+	    if (brdr) {
+		if (!Rast_is_d_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_d_null_value(&ptype) || corrCell == ptype) {
+			if (Rast_is_d_null_value(&precCell) || precCell != corrCell) {
+			    nedges++;
+			}
+			if (Rast_is_d_null_value(&supCell) || supCell != corrCell) {
+			    nedges++;
+			}
+			/* right and bottom */
+			if (i == ad->rl - 1)
+			    nedges++;
+			if (j == ad->cl - 1)
+			    nedges++;
 		    }
-		    if (Rast_is_d_null_value(&supCell) || supCell != corrCell) {
-			nedges++;
+		}
+		else /* corrCell == NULL */ {
+		    if (!Rast_is_d_null_value(&precCell)) {
+			if (Rast_is_d_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
-		    /* right and bottom */
-		    if (i == ad->rl - 1)
-			nedges++;
-		    if (j == ad->cl - 1)
-			nedges++;
+		    if (!Rast_is_d_null_value(&supCell)) {
+			if (Rast_is_d_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
-	    else /* corrCell == NULL */ {
-		if (!Rast_is_d_null_value(&precCell)) {
-		    if (Rast_is_d_null_value(&ptype) || precCell == ptype) {
-			nedges++;
+	    else {
+		/* exclude border edges */
+		if (!Rast_is_d_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_d_null_value(&ptype) || corrCell == ptype) {
+			if (j > 0 && !(masked && mask_buf[j - 1] == 0) &&
+			    (Rast_is_d_null_value(&precCell) || precCell != corrCell)) {
+			    nedges++;
+			}
+			if (i > 0 && !(masked && mask_sup[i - 1] == 0) &&
+			    (Rast_is_d_null_value(&supCell) || supCell != corrCell)) {
+			    nedges++;
+			}
 		    }
 		}
-		if (!Rast_is_d_null_value(&supCell)) {
-		    if (Rast_is_d_null_value(&ptype) || supCell == ptype) {
-			nedges++;
+		else if (Rast_is_d_null_value(&corrCell) && !(masked && mask_buf[j] == 0)) {
+		    if (!Rast_is_d_null_value(&precCell)) {
+			if (Rast_is_d_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
+		    if (!Rast_is_d_null_value(&supCell)) {
+			if (Rast_is_d_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
 	    precCell = corrCell;
@@ -524,33 +590,62 @@
 		Rast_set_f_null_value(&supCell, 1);
 	    }
 
-	    if (!Rast_is_f_null_value(&corrCell)) {
-		area++; 
-	        if (Rast_is_f_null_value(&ptype) || corrCell == ptype) {
-		    
-		    if (Rast_is_f_null_value(&precCell) || precCell != corrCell) {
-			nedges++;
+	    if (brdr) {
+		if (!Rast_is_f_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_f_null_value(&ptype) || corrCell == ptype) {
+			if (Rast_is_f_null_value(&precCell) || precCell != corrCell) {
+			    nedges++;
+			}
+			if (Rast_is_f_null_value(&supCell) || supCell != corrCell) {
+			    nedges++;
+			}
+			/* right and bottom */
+			if (i == ad->rl - 1)
+			    nedges++;
+			if (j == ad->cl - 1)
+			    nedges++;
 		    }
-		    if (Rast_is_f_null_value(&supCell) || supCell != corrCell) {
-			nedges++;
+		}
+		else /* corrCell == NULL */ {
+		    if (!Rast_is_f_null_value(&precCell)) {
+			if (Rast_is_f_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
-		    /* right and bottom */
-		    if (i == ad->rl - 1)
-			nedges++;
-		    if (j == ad->cl - 1)
-			nedges++;
+		    if (!Rast_is_f_null_value(&supCell)) {
+			if (Rast_is_f_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
-	    else /* corrCell == NULL */ {
-		if (!Rast_is_f_null_value(&precCell)) {
-		    if (Rast_is_f_null_value(&ptype) || precCell == ptype) {
-			nedges++;
+	    else {
+		/* exclude border edges */
+		if (!Rast_is_f_null_value(&corrCell)) {
+		    area++; 
+		    if (Rast_is_f_null_value(&ptype) || corrCell == ptype) {
+			if (j > 0 && !(masked && mask_buf[j - 1] == 0) &&
+			    (Rast_is_f_null_value(&precCell) || precCell != corrCell)) {
+			    nedges++;
+			}
+			if (i > 0 && !(masked && mask_sup[i - 1] == 0) &&
+			    (Rast_is_f_null_value(&supCell) || supCell != corrCell)) {
+			    nedges++;
+			}
 		    }
 		}
-		if (!Rast_is_f_null_value(&supCell)) {
-		    if (Rast_is_f_null_value(&ptype) || supCell == ptype) {
-			nedges++;
+		else if (Rast_is_f_null_value(&corrCell) && !(masked && mask_buf[j] == 0)) {
+		    if (!Rast_is_f_null_value(&precCell)) {
+			if (Rast_is_f_null_value(&ptype) || precCell == ptype) {
+			    nedges++;
+			}
 		    }
+		    if (!Rast_is_f_null_value(&supCell)) {
+			if (Rast_is_f_null_value(&ptype) || supCell == ptype) {
+			    nedges++;
+			}
+		    }
 		}
 	    }
 	    precCell = corrCell;



More information about the grass-commit mailing list