[GRASS-SVN] r72674 - grass/branches/releasebranch_7_2/raster/r.contour

svn_grass at osgeo.org svn_grass at osgeo.org
Fri May 4 13:05:58 PDT 2018


Author: mmetz
Date: 2018-05-04 13:05:58 -0700 (Fri, 04 May 2018)
New Revision: 72674

Modified:
   grass/branches/releasebranch_7_2/raster/r.contour/cont.c
   grass/branches/releasebranch_7_2/raster/r.contour/main.c
Log:
r.contour: avoid tracing back of contour lines (backport trunk r72668)

Modified: grass/branches/releasebranch_7_2/raster/r.contour/cont.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.contour/cont.c	2018-05-04 20:05:32 UTC (rev 72673)
+++ grass/branches/releasebranch_7_2/raster/r.contour/cont.c	2018-05-04 20:05:58 UTC (rev 72674)
@@ -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/branches/releasebranch_7_2/raster/r.contour/main.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.contour/main.c	2018-05-04 20:05:32 UTC (rev 72673)
+++ grass/branches/releasebranch_7_2/raster/r.contour/main.c	2018-05-04 20:05:58 UTC (rev 72674)
@@ -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