فهرست منبع

v.buffer: define GRASS_VECTOR_BUFFER to force using built-in algorithm instead of GEOS
update manual


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54523 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 12 سال پیش
والد
کامیت
c31172ff92
2فایلهای تغییر یافته به همراه95 افزوده شده و 79 حذف شده
  1. 75 72
      vector/v.buffer/main.c
  2. 20 7
      vector/v.buffer/v.buffer.html

+ 75 - 72
vector/v.buffer/main.c

@@ -195,7 +195,7 @@ int main(int argc, char *argv[])
 		  *where_opt, *cats_opt;
 		  *where_opt, *cats_opt;
 
 
     struct cat_list *cat_list = NULL;
     struct cat_list *cat_list = NULL;
-    int verbose;
+    int verbose, use_geos;
     double da, db, dalpha, tolerance, unit_tolerance;
     double da, db, dalpha, tolerance, unit_tolerance;
     int type;
     int type;
     int i, ret, nareas, area, nlines, line;
     int i, ret, nareas, area, nlines, line;
@@ -308,6 +308,13 @@ int main(int argc, char *argv[])
     if (G_parser(argc, argv))
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 	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);
     type = Vect_option_to_types(type_opt);
 
 
     if ((dista_opt->answer && bufcol_opt->answer) ||
     if ((dista_opt->answer && bufcol_opt->answer) ||
@@ -454,14 +461,13 @@ int main(int argc, char *argv[])
 
 
 #ifdef HAVE_GEOS
 #ifdef HAVE_GEOS
     initGEOS(G_message, G_fatal_error);
     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 "
 	G_warning(_("Negative distances for internal buffers are not supported "
 	            "and converted to positive values."));
 	            "and converted to positive values."));
 	da = fabs(da);
 	da = fabs(da);
 	db = fabs(db);
 	db = fabs(db);
     }
     }
-#endif
 
 
     /* Areas */
     /* Areas */
     if (nareas > 0) {
     if (nareas > 0) {
@@ -522,43 +528,39 @@ int main(int argc, char *argv[])
 	    }
 	    }
 
 
 #ifdef HAVE_GEOS
 #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;
-		}
-		G_free(arr_bc_pts.iPoints);
-	    }
-	    buffers_count++;
+	    if (use_geos)
+		geos_buffer(&In, &Out, &Buf, area, GV_AREA, da,
+			    &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
 #endif
 #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);
+		}
+		buffers_count++;
+	    } /* native buffer end */
 	}
 	}
     }
     }
 
 
@@ -566,7 +568,7 @@ int main(int argc, char *argv[])
     if (nlines > 0) {
     if (nlines > 0) {
 	int ltype;
 	int ltype;
 
 
-	G_message(_("Buffering lines..."));
+	G_message(_("Buffering features..."));
 	
 	
 	if (da < 0 || db < 0) {
 	if (da < 0 || db < 0) {
 	    G_warning(_("Negative distances are only supported for areas"));
 	    G_warning(_("Negative distances are only supported for areas"));
@@ -649,39 +651,40 @@ int main(int argc, char *argv[])
 
 
 	    }
 	    }
 	    else {
 	    else {
-
 #ifdef HAVE_GEOS
 #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;
-		    }
-		    G_free(arr_bc_pts.iPoints);
-		}
-		buffers_count++;
+		if (use_geos)
+		    geos_buffer(&In, &Out, &Buf, line, type, da,
+				&si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
 #endif
 #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);
+		    }
+		    buffers_count++;
+		} /* native buffer end */
 	    }
 	    }
 	}
 	}
     }
     }

+ 20 - 7
vector/v.buffer/v.buffer.html

@@ -1,21 +1,28 @@
 <h2>DESCRIPTION</h2>
 <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>
 <h2>NOTES</h2>
 
 
 Internal buffers for areas can be generated with negative distiance 
 Internal buffers for areas can be generated with negative distiance 
 values (GRASS must be compiled with GEOS).
 values (GRASS must be compiled with GEOS).
 <p>
 <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 
 The resulting buffer areas can have multiple categories, and multiple 
 buffer areas can have the same category. The buffer for the input 
 buffer areas can have the same category. The buffer for the input 
 feature with category X can thus be retrieved by selecting all buffer 
 feature with category X can thus be retrieved by selecting all buffer 
 areas with category X (see example below).
 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>
 <h2>EXAMPLES</h2>
 
 
@@ -44,6 +51,11 @@ d.vect map=hospitals_circled type=area layer=1 cats=36
 v.extract in=hospitals_circled out=hospital_36_circled layer=1 cats=36 -d
 v.extract in=hospitals_circled out=hospital_36_circled layer=1 cats=36 -d
 </pre></div>
 </pre></div>
 
 
+<h2>REFERENCE</h2>
+
+<ul>
+<li><a href="http://trac.osgeo.org/geos">GEOS Library</a></li>
+</ul>
 
 
 <h2>SEE ALSO</h2>
 <h2>SEE ALSO</h2>
 
 
@@ -55,11 +67,12 @@ v.extract in=hospitals_circled out=hospital_36_circled layer=1 cats=36 -d
 <a href="v.db.connect.html">v.db.connect</a>
 <a href="v.db.connect.html">v.db.connect</a>
 </em>
 </em>
 
 
-
 <h2>AUTHORS</h2>
 <h2>AUTHORS</h2>
 
 
 Radim Blazek<br>
 Radim Blazek<br>
 Rewritten by Rosen Matev (with support through the
 Rewritten by Rosen Matev (with support through the
  Google Summer of Code program 2008)<br>
  Google Summer of Code program 2008)<br>
 Rewritten by Markus Metz (2011, 2012)
 Rewritten by Markus Metz (2011, 2012)
-<p><i>Last changed: $Date$</i>
+
+<p>
+<i>Last changed: $Date$</i>