[GRASS-SVN] r45839 - grass/branches/develbranch_6/vector/v.buffer

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Apr 4 04:31:52 EDT 2011


Author: mmetz
Date: 2011-04-04 01:31:52 -0700 (Mon, 04 Apr 2011)
New Revision: 45839

Modified:
   grass/branches/develbranch_6/vector/v.buffer/description.html
   grass/branches/develbranch_6/vector/v.buffer/main.c
Log:
code cleanup, documentation

Modified: grass/branches/develbranch_6/vector/v.buffer/description.html
===================================================================
--- grass/branches/develbranch_6/vector/v.buffer/description.html	2011-04-04 08:31:30 UTC (rev 45838)
+++ grass/branches/develbranch_6/vector/v.buffer/description.html	2011-04-04 08:31:52 UTC (rev 45839)
@@ -9,6 +9,13 @@
 
 Attributes are not transferred due to potential buffer overlap, which
 cannot be resolved automatically.
+<P>
+The input vector must be reasonably clean: lines must not intersect
+themselves. It is recommended to clean the input vector first with
+<em>v.clean tool=snap,break,rmdupl</em> and then create buffers. The 
+snapping threshold depends on the digitization threshold and the desired 
+buffering distance. As a rule of thumb, the snapping distance can be 
+up to 1% of the buffering distance.
 
 <h2>EXAMPLES</h2>
 
@@ -45,12 +52,8 @@
 the buffer size is bigger than input features. Usually you can solve the
 problem if you run <em>v.buffer</em> more times with smaller buffer.
 <P>
-The <b>bufcol</b> dynamic buffer distance parameter has problems cleaning
-complex features (holes left filled, etc.). If you experience problems, try
-running <em>v.buffer</em> multiple times with a single buffer distance, patch
-the results with <em>v.patch</em> and remove any overlaps with 
-<em>v.extract -d</em>.
 
+
 <h2>SEE ALSO</h2>
 
 <em>
@@ -63,7 +66,8 @@
 
 <h2>AUTHOR</h2>
 
-Radim Blazek
+Radim Blazek<br>
+Markus Metz
 
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/vector/v.buffer/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.buffer/main.c	2011-04-04 08:31:30 UTC (rev 45838)
+++ grass/branches/develbranch_6/vector/v.buffer/main.c	2011-04-04 08:31:52 UTC (rev 45839)
@@ -41,6 +41,9 @@
 
 /* 
  * Test if area in Out is in buffer, using the x,y coords of the area centroid.
+ * requires that buffers as returned by the library functions are clean:
+ *  - no self-intersections
+ *  - inner buffers must be inside corresponding outer buffer
  * Return: 1 in buffer
  *         0 outside buffer
  */
@@ -362,7 +365,7 @@
     /* Create buffers' boundaries */
 
     /* Lines (and Points) */
-    if ((type & GV_POINTS) || (type & GV_LINES)) {
+    if (((type & GV_POINTS) || (type & GV_LINES)) && nlines) {
 	int line, ltype, looped;
 	double pbuffer;
 
@@ -444,7 +447,7 @@
 		    /* determine correct sides for outer and inner contours */
 		    dig_find_area_poly(Points, &area_size);
 		    if (area_size == 0) {
-			G_warning("zero area size");
+			G_warning(_("Zero area size, please clean input vector first."));
 			looped = 0;
 		    }
 		    else if (area_size > 0)
@@ -454,25 +457,10 @@
 
 		    looped = 1;
 		}
-		if (!looped) {
-		    double dx = Points->x[0] - Points->x[Points->n_points - 1];
-		    double dy = Points->y[0] - Points->y[Points->n_points - 1];
-		    double dist = sqrt(dx * dx + dy * dy);
-		    
-		    /* if the distance between endpoints is < 2 * buffer
-		     * and at least one point is > 2 * buffer away from the endpoints, 
-		     * problems may occur
-		     * break up the line if possible
-		     * find point farthest away from end point
-		     * if this point is > 2 * buffer away from end point, break
-		     * first line from start point to this point
-		     * second line from this point to end point */
-
-		    looped = 0;
-		}
 	    }
 
 	    if (looped) {
+		/* get parallel lines */
 		Vect_line_parallel(Points, pbuffer, tolerance, 1, BPoints);
 		if (BPoints->n_points > 3) {
 		    if (BPoints->x[0] != BPoints->x[BPoints->n_points - 1] ||
@@ -509,6 +497,8 @@
 		buffers_count++;
 	    }
 	    else {
+		/* TODO: should return outer buffer and one or more
+		 * inner buffers in some cases */
 		Vect_line_buffer(Points, buffer, tolerance, BPoints);
 		Vect_write_line(&Out, GV_BOUNDARY, BPoints, BCats);
 		line_id = Vect_write_line(&Buf, GV_BOUNDARY, BPoints, Cats);
@@ -524,7 +514,7 @@
     }
 
     /* Areas */
-    if (type & GV_AREA) {
+    if ((type & GV_AREA) && nareas) {
 	int i, area, centroid, nisles, isle, line_id;
 
 	G_message(_("Area buffers... "));
@@ -629,6 +619,8 @@
 		    dig_find_area_poly(Points, &isle_size);
 		    dig_find_area_poly(BPoints, &inner_size);
 		    /* area size of inner contour must be smaller than isle size */
+		    /* TODO: should return more than one buffer for certain
+		     * island shapes and buffer distances */
 		    if (fabs(inner_size) < fabs(isle_size)) {
 			Vect_write_line(&Out, GV_BOUNDARY, BPoints, BCats);
 			line_id = Vect_write_line(&Buf, GV_BOUNDARY, BPoints, Cats);



More information about the grass-commit mailing list