[GRASS-SVN] r70960 - grass-addons/grass7/raster/r.pi/r.pi.enn

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 26 14:51:02 PDT 2017


Author: mmetz
Date: 2017-04-26 14:51:02 -0700 (Wed, 26 Apr 2017)
New Revision: 70960

Modified:
   grass-addons/grass7/raster/r.pi/r.pi.enn/func.c
   grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
Log:
r.pi.enn: bugfix

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/func.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/func.c	2017-04-26 17:42:50 UTC (rev 70959)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/func.c	2017-04-26 21:51:02 UTC (rev 70960)
@@ -23,7 +23,7 @@
 DCELL min_dist(Coords ** frags, int n1, int n2)
 {
     Coords *p1, *p2;
-    DCELL min = 1000000.0;
+    DCELL min = 0;
 
     /* for all cells in the first patch */
     for (p1 = frags[n1]; p1 < frags[n1 + 1]; p1++) {
@@ -35,7 +35,7 @@
 		if (p2->neighbors < 4) {
 		    DCELL d = dist(p1, p2);
 
-		    if (d < min) {
+		    if (min == 0 || d < min) {
 			min = d;
 		    }
 		}

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn/main.c	2017-04-26 17:42:50 UTC (rev 70959)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn/main.c	2017-04-26 21:51:02 UTC (rev 70960)
@@ -88,8 +88,6 @@
     int keyval;
 
     int n;
-    int copycolr;
-    struct Colors colr;
     struct GModule *module;
     struct
     {
@@ -219,9 +217,6 @@
     if (in_fd < 0)
 	G_fatal_error(_("Unable to open raster map <%s>"), oldname);
 
-    /* copy color table */
-    copycolr = (Rast_read_colors(oldname, oldmapset, &colr) > 0);
-
     /* get key value */
     sscanf(parm.keyval->answer, "%d", &keyval);
 
@@ -289,23 +284,16 @@
 	for (col = 0; col < ncols; col++) {
 	    if (result[col] == keyval)
 		flagbuf[row * ncols + col] = 1;
+	    else
+		flagbuf[row * ncols + col] = 0;
 	}
 
 	G_percent(row, nrows, 2);
     }
     Rast_close(in_fd);
 
-    /* TODO: merge with previous loop */
-    for (row = 0; row < nrows; row++) {
-	for (col = 0; col < ncols; col++) {
-	    if (flagbuf[row * ncols + col] == 1) {
-		fragcount++;
-		writeFrag(flagbuf, actpos, row, col, nrows, ncols, neighb_count);
-		fragments[fragcount] = actpos;
-	    }
-	}
-    }
-    G_percent(nrows, nrows, 2);
+    /* find fragments */
+    fragcount = writeFragments(fragments, flagbuf, nrows, ncols, neighb_count);
 
     /* generate the distance matrix */
     get_dist_matrix(fragcount);
@@ -363,8 +351,10 @@
 	    }
 
 	    Rast_close(out_fd);
-	}
 
+	    Rast_init_cats(title, &cats);
+	    Rast_write_cats(fullname, &cats);
+	}
     }				/* for each method */
 
     G_percent(100, 100, 2);
@@ -388,11 +378,5 @@
     G_free(distmatrix);
     G_free(nearest_indices);
 
-    Rast_init_cats(title, &cats);
-    Rast_write_cats(newname, &cats);
-
-    if (copycolr)
-	Rast_write_colors(newname, G_mapset(), &colr);
-
     exit(exitres);
 }



More information about the grass-commit mailing list