[GRASS-SVN] r54523 - grass/trunk/vector/v.buffer

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 4 05:02:48 PST 2013


Author: martinl
Date: 2013-01-04 05:02:48 -0800 (Fri, 04 Jan 2013)
New Revision: 54523

Modified:
   grass/trunk/vector/v.buffer/main.c
   grass/trunk/vector/v.buffer/v.buffer.html
Log:
v.buffer: define GRASS_VECTOR_BUFFER to force using built-in algorithm instead of GEOS
	  update manual


Modified: grass/trunk/vector/v.buffer/main.c
===================================================================
--- grass/trunk/vector/v.buffer/main.c	2013-01-04 11:23:41 UTC (rev 54522)
+++ grass/trunk/vector/v.buffer/main.c	2013-01-04 13:02:48 UTC (rev 54523)
@@ -195,7 +195,7 @@
 		  *where_opt, *cats_opt;
 
     struct cat_list *cat_list = NULL;
-    int verbose;
+    int verbose, use_geos;
     double da, db, dalpha, tolerance, unit_tolerance;
     int type;
     int i, ret, nareas, area, nlines, line;
@@ -308,6 +308,13 @@
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
+#if !defined HAVE_GEOS
+    use_geos = FALSE;
+#else
+    use_geos = getenv("GRASS_VECTOR_BUFFER") ? FALSE : TRUE;
+#endif
+    G_debug(1, "use_geos = %d", use_geos);
+    
     type = Vect_option_to_types(type_opt);
 
     if ((dista_opt->answer && bufcol_opt->answer) ||
@@ -454,14 +461,13 @@
 
 #ifdef HAVE_GEOS
     initGEOS(G_message, G_fatal_error);
-#else
-    if (da < 0. || db < 0.) {
+#endif
+    if(!use_geos && (da < 0. || db < 0.)) {
 	G_warning(_("Negative distances for internal buffers are not supported "
 	            "and converted to positive values."));
 	da = fabs(da);
 	db = fabs(db);
     }
-#endif
 
     /* Areas */
     if (nareas > 0) {
@@ -522,43 +528,39 @@
 	    }
 
 #ifdef HAVE_GEOS
-	    geos_buffer(&In, &Out, &Buf, area, GV_AREA, da,
-	                &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
-#else
-	    if (da < 0. || db < 0.) {
-		G_warning(_("Negative distances for internal buffers are not supported "
-			    "and converted to positive values."));
-		da = fabs(da);
-		db = fabs(db);
-	    }
-	    Vect_area_buffer2(&In, area, da, db, dalpha,
-			      !(straight_flag->answer),
-			      !(nocaps_flag->answer), unit_tolerance,
-			      &(arr_bc_pts.oPoints),
-			      &(arr_bc_pts.iPoints),
-			      &(arr_bc_pts.inner_count));
-
-	    Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.oPoints, BCats);
-	    line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.oPoints, CCats);
-	    Vect_destroy_line_struct(arr_bc_pts.oPoints);
-	    /* add buffer to spatial index */
-	    Vect_get_line_box(&Buf, line_id, &bbox);
-	    Vect_spatial_index_add_item(&si, buffers_count, &bbox);
-	    arr_bc[buffers_count].outer = line_id;
-
-	    arr_bc[buffers_count].inner_count = arr_bc_pts.inner_count;
-	    if (arr_bc_pts.inner_count > 0) {
-		arr_bc[buffers_count].inner = G_malloc(arr_bc_pts.inner_count * sizeof(int));
-		for (i = 0; i < arr_bc_pts.inner_count; i++) {
-		    Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
-		    line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
-		    Vect_destroy_line_struct(arr_bc_pts.iPoints[i]);
-		    arr_bc[buffers_count].inner[i] = line_id;
+	    if (use_geos)
+		geos_buffer(&In, &Out, &Buf, area, GV_AREA, da,
+			    &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
+#endif
+	    if (!use_geos) {
+		Vect_area_buffer2(&In, area, da, db, dalpha,
+				  !(straight_flag->answer),
+				  !(nocaps_flag->answer), unit_tolerance,
+				  &(arr_bc_pts.oPoints),
+				  &(arr_bc_pts.iPoints),
+				  &(arr_bc_pts.inner_count));
+		
+		Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.oPoints, BCats);
+		line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.oPoints, CCats);
+		Vect_destroy_line_struct(arr_bc_pts.oPoints);
+		/* add buffer to spatial index */
+		Vect_get_line_box(&Buf, line_id, &bbox);
+		Vect_spatial_index_add_item(&si, buffers_count, &bbox);
+		arr_bc[buffers_count].outer = line_id;
+		
+		arr_bc[buffers_count].inner_count = arr_bc_pts.inner_count;
+		if (arr_bc_pts.inner_count > 0) {
+		    arr_bc[buffers_count].inner = G_malloc(arr_bc_pts.inner_count * sizeof(int));
+		    for (i = 0; i < arr_bc_pts.inner_count; i++) {
+			Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
+			line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
+			Vect_destroy_line_struct(arr_bc_pts.iPoints[i]);
+			arr_bc[buffers_count].inner[i] = line_id;
+		    }
+		    G_free(arr_bc_pts.iPoints);
 		}
-		G_free(arr_bc_pts.iPoints);
-	    }
-	    buffers_count++;
-#endif
+		buffers_count++;
+	    } /* native buffer end */
 	}
     }
 
@@ -566,7 +568,7 @@
     if (nlines > 0) {
 	int ltype;
 
-	G_message(_("Buffering lines..."));
+	G_message(_("Buffering features..."));
 	
 	if (da < 0 || db < 0) {
 	    G_warning(_("Negative distances are only supported for areas"));
@@ -649,39 +651,40 @@
 
 	    }
 	    else {
-
 #ifdef HAVE_GEOS
-		geos_buffer(&In, &Out, &Buf, line, type, da,
-			    &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
-#else
-		Vect_line_buffer2(Points, da, db, dalpha,
-				  !(straight_flag->answer),
-				  !(nocaps_flag->answer), unit_tolerance,
-				  &(arr_bc_pts.oPoints),
-				  &(arr_bc_pts.iPoints),
-				  &(arr_bc_pts.inner_count));
-
-		Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.oPoints, BCats);
-		line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.oPoints, CCats);
-		Vect_destroy_line_struct(arr_bc_pts.oPoints);
-		/* add buffer to spatial index */
-		Vect_get_line_box(&Buf, line_id, &bbox);
-		Vect_spatial_index_add_item(&si, buffers_count, &bbox);
-		arr_bc[buffers_count].outer = line_id;
-
-		arr_bc[buffers_count].inner_count = arr_bc_pts.inner_count;
-		if (arr_bc_pts.inner_count > 0) {
-		    arr_bc[buffers_count].inner = G_malloc(arr_bc_pts.inner_count * sizeof(int));
-		    for (i = 0; i < arr_bc_pts.inner_count; i++) {
-			Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
-			line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
-			Vect_destroy_line_struct(arr_bc_pts.iPoints[i]);
-			arr_bc[buffers_count].inner[i] = line_id;
+		if (use_geos)
+		    geos_buffer(&In, &Out, &Buf, line, type, da,
+				&si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
+#endif
+		if (!use_geos) {
+		    Vect_line_buffer2(Points, da, db, dalpha,
+				      !(straight_flag->answer),
+				      !(nocaps_flag->answer), unit_tolerance,
+				      &(arr_bc_pts.oPoints),
+				      &(arr_bc_pts.iPoints),
+				      &(arr_bc_pts.inner_count));
+		    
+		    Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.oPoints, BCats);
+		    line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.oPoints, CCats);
+		    Vect_destroy_line_struct(arr_bc_pts.oPoints);
+		    /* add buffer to spatial index */
+		    Vect_get_line_box(&Buf, line_id, &bbox);
+		    Vect_spatial_index_add_item(&si, buffers_count, &bbox);
+		    arr_bc[buffers_count].outer = line_id;
+		    
+		    arr_bc[buffers_count].inner_count = arr_bc_pts.inner_count;
+		    if (arr_bc_pts.inner_count > 0) {
+			arr_bc[buffers_count].inner = G_malloc(arr_bc_pts.inner_count * sizeof(int));
+			for (i = 0; i < arr_bc_pts.inner_count; i++) {
+			    Vect_write_line(&Out, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
+			    line_id = Vect_write_line(&Buf, GV_BOUNDARY, arr_bc_pts.iPoints[i], BCats);
+			    Vect_destroy_line_struct(arr_bc_pts.iPoints[i]);
+			    arr_bc[buffers_count].inner[i] = line_id;
+			}
+			G_free(arr_bc_pts.iPoints);
 		    }
-		    G_free(arr_bc_pts.iPoints);
-		}
-		buffers_count++;
-#endif
+		    buffers_count++;
+		} /* native buffer end */
 	    }
 	}
     }

Modified: grass/trunk/vector/v.buffer/v.buffer.html
===================================================================
--- grass/trunk/vector/v.buffer/v.buffer.html	2013-01-04 11:23:41 UTC (rev 54522)
+++ grass/trunk/vector/v.buffer/v.buffer.html	2013-01-04 13:02:48 UTC (rev 54523)
@@ -1,21 +1,28 @@
 <h2>DESCRIPTION</h2>
 
-<em>v.buffer</em> creates a buffer around features of given <b>type
-</b>, which have a category in the given <b>layer</b>. The <b>
-tolerance</b> controls the number of vector segments being generated 
-(the smaller the value, the more vector segments are generated).
+<em>v.buffer</em> creates a buffer around features of
+given <b>type</b>, which have a category in the
+given <b>layer</b>. The <b>tolerance</b> controls the number of vector
+segments being generated (the smaller the value, the more vector
+segments are generated).
 
 <h2>NOTES</h2>
 
 Internal buffers for areas can be generated with negative distiance 
 values (GRASS must be compiled with GEOS).
 <p>
-Categories and attributes can be transferred with the <em>t</em> flag. 
+Categories and attributes can be transferred with the <b>t</b> flag. 
 The resulting buffer areas can have multiple categories, and multiple 
 buffer areas can have the same category. The buffer for the input 
 feature with category X can thus be retrieved by selecting all buffer 
 areas with category X (see example below).
 
+<p>
+Buffers for lines and areas are generated using algorithm from GEOS
+library. If GRASS is not compiled with GEOS support or environmental
+variable <tt>GRASS_VECTOR_BUFFER</tt> is defined, then GRASS generates
+buffers using built-in buffering algorithm (which is still buggy for
+some input data).
 
 <h2>EXAMPLES</h2>
 
@@ -44,7 +51,12 @@
 v.extract in=hospitals_circled out=hospital_36_circled layer=1 cats=36 -d
 </pre></div>
 
+<h2>REFERENCE</h2>
 
+<ul>
+<li><a href="http://trac.osgeo.org/geos">GEOS Library</a></li>
+</ul>
+
 <h2>SEE ALSO</h2>
 
 <em>
@@ -55,11 +67,12 @@
 <a href="v.db.connect.html">v.db.connect</a>
 </em>
 
-
 <h2>AUTHORS</h2>
 
 Radim Blazek<br>
 Rewritten by Rosen Matev (with support through the
  Google Summer of Code program 2008)<br>
 Rewritten by Markus Metz (2011, 2012)
-<p><i>Last changed: $Date$</i>
+
+<p>
+<i>Last changed: $Date$</i>



More information about the grass-commit mailing list