[GRASS-SVN] r72668 - grass/trunk/raster/r.contour

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 3 13:01:10 PDT 2018


Author: mmetz
Date: 2018-05-03 13:01:09 -0700 (Thu, 03 May 2018)
New Revision: 72668

Modified:
   grass/trunk/raster/r.contour/cont.c
   grass/trunk/raster/r.contour/main.c
Log:
r.contour: avoid tracing back of contour lines

Modified: grass/trunk/raster/r.contour/cont.c
===================================================================
--- grass/trunk/raster/r.contour/cont.c	2018-05-03 18:49:54 UTC (rev 72667)
+++ grass/trunk/raster/r.contour/cont.c	2018-05-03 20:01:09 UTC (rev 72668)
@@ -92,6 +92,7 @@
 		hit[i][j] = 0;
 	    }
 	}
+
 	/* check each cell of top and bottom borders  */
 	for (startrow = 0; startrow < nrow; startrow += (nrow - 2)) {
 	    for (startcol = 0; startcol <= ncol - 2; startcol++) {
@@ -113,14 +114,14 @@
 		    if (checkedge(current.z[p1], current.z[p2], level)) {
 			getpoint(&current, level, Cell, Points);
 			/* while not off an edge, follow line */
-			while (!outside) {
-			    hit[current.r][current.c] +=
+			while (!outside && !hit[current.r][current.c]) {
+			    hit[current.r][current.c] |=
 				findcrossing(&current, level, Cell, Points,
 					     &ncrossing);
 			    newedge(&current);
 			    outside = getnewcell(&current, nrow, ncol, z);
 			}
-			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
+			if ((n_cut <= 0) || ((Points->n_points) >= n_cut)) {
 			    Vect_reset_cats(Cats);
 			    Vect_cat_set(Cats, 1, n + 1);
 			    Vect_write_line(&Map, GV_LINE, Points, Cats);
@@ -150,14 +151,14 @@
 		    if (checkedge(current.z[p1], current.z[p2], level)) {
 			getpoint(&current, level, Cell, Points);
 			/* while not off an edge, follow line */
-			while (!outside) {
-			    hit[current.r][current.c] +=
+			while (!outside && !hit[current.r][current.c]) {
+			    hit[current.r][current.c] |=
 				findcrossing(&current, level, Cell, Points,
 					     &ncrossing);
 			    newedge(&current);
 			    outside = getnewcell(&current, nrow, ncol, z);
 			}
-			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
+			if ((n_cut <= 0) || ((Points->n_points) >= n_cut)) {
 			    Vect_reset_cats(Cats);
 			    Vect_cat_set(Cats, 1, n + 1);
 			    Vect_write_line(&Map, GV_LINE, Points, Cats);
@@ -180,7 +181,7 @@
 		    if (!outside &&
 			checkedge(current.z[0], current.z[1], level)) {
 			getpoint(&current, level, Cell, Points);
-			hit[current.r][current.c] +=
+			hit[current.r][current.c] |=
 			    findcrossing(&current, level, Cell, Points,
 					 &ncrossing);
 			newedge(&current);
@@ -187,17 +188,17 @@
 			outside = getnewcell(&current, nrow, ncol, z);
 
 			/* while not back to starting point, follow line */
-			while (!outside &&
+			while (!outside && !hit[current.r][current.c] &&
 			       ((current.edge != 0) ||
 				((current.r != startrow) ||
 				 (current.c != startcol)))) {
-			    hit[current.r][current.c] +=
+			    hit[current.r][current.c] |=
 				findcrossing(&current, level, Cell, Points,
 					     &ncrossing);
 			    newedge(&current);
 			    outside = getnewcell(&current, nrow, ncol, z);
 			}
-			if ((n_cut <= 0) || ((Points->n_points) > n_cut)) {
+			if ((n_cut <= 0) || ((Points->n_points) >= n_cut)) {
 			    Vect_reset_cats(Cats);
 			    Vect_cat_set(Cats, 1, n + 1);
 			    Vect_write_line(&Map, GV_LINE, Points, Cats);
@@ -378,8 +379,11 @@
     y = Cell.north - (y + .5) * Cell.ns_res;
     x = Cell.west + (x + .5) * Cell.ew_res;
 
-    Vect_append_point(Points, x, y, level);
-
+    if (Points->n_points == 0 || (Points->n_points > 0 &&
+        (Points->x[Points->n_points - 1] != x ||
+	 Points->y[Points->n_points - 1] != y))) {
+	Vect_append_point(Points, x, y, level);
+    }
 }
 
 /***********************************************************************

Modified: grass/trunk/raster/r.contour/main.c
===================================================================
--- grass/trunk/raster/r.contour/main.c	2018-05-03 18:49:54 UTC (rev 72667)
+++ grass/trunk/raster/r.contour/main.c	2018-05-03 20:01:09 UTC (rev 72668)
@@ -127,7 +127,7 @@
     cut->key = "cut";
     cut->type = TYPE_INTEGER;
     cut->required = NO;
-    cut->answer = "0";
+    cut->answer = "2";
     cut->description =
 	_("Minimum number of points for a contour line (0 -> no limit)");
 



More information about the grass-commit mailing list