浏览代码

v.buffer: implement -c -s flags also for GEOS

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@65710 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 9 年之前
父节点
当前提交
cfd48083e2

+ 15 - 4
vector/v.buffer/geos.c

@@ -142,7 +142,7 @@ int geos_buffer(struct Map_info *In, struct Map_info *Out,
 		struct spatial_index *si,
 		struct line_cats *Cats,
 		struct buf_contours **arr_bc,
-		int *buffers_count, int *arr_bc_alloc)
+		int *buffers_count, int *arr_bc_alloc, int flat, int no_caps)
 {
     GEOSGeometry *IGeom = NULL;
     GEOSGeometry *OGeom = NULL;
@@ -158,10 +158,21 @@ int geos_buffer(struct Map_info *In, struct Map_info *Out,
      * A value of 8 gives less than 2% max error in the buffer distance.
      * For a max error of < 1%, use QS = 12.
      * For a max error of < 0.1%, use QS = 18. */
-    OGeom = GEOSBuffer(IGeom, da, 12);
+    if (flat || no_caps) {
+        GEOSBufferParams* geos_params = GEOSBufferParams_create();
+        GEOSBufferParams_setEndCapStyle(geos_params,
+                                        no_caps ? GEOSBUF_CAP_FLAT : GEOSBUF_CAP_SQUARE);
 
-    if (!OGeom)
-	G_warning(_("Buffering failed"));
+        OGeom = GEOSBufferWithParams(IGeom, geos_params, da);
+        GEOSBufferParams_destroy(geos_params);
+    }
+    else {
+        OGeom = GEOSBuffer(IGeom, da, 12);
+    }
+    
+    if (!OGeom) {
+	G_fatal_error(_("Buffering failed"));
+    }
     
     geom2ring(OGeom, Out, Buf, si, Cats, arr_bc, buffers_count, arr_bc_alloc);
 

+ 1 - 1
vector/v.buffer/local_proto.h

@@ -19,6 +19,6 @@ int geos_buffer(struct Map_info *, struct Map_info *,
 		struct spatial_index *,
 		struct line_cats *,
 		struct buf_contours **,
-		int *, int *);
+		int *, int *, int, int);
 #endif
 

+ 4 - 2
vector/v.buffer/main.c

@@ -543,7 +543,8 @@ int main(int argc, char *argv[])
 #ifdef HAVE_GEOS
 	    if (use_geos)
 		geos_buffer(&In, &Out, &Buf, area, GV_AREA, da,
-			    &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
+			    &si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc,
+                            straight_flag->answer, nocaps_flag->answer);
 #endif
 	    if (!use_geos) {
 		Vect_area_buffer2(&In, area, da, db, dalpha,
@@ -667,7 +668,8 @@ int main(int argc, char *argv[])
 #ifdef HAVE_GEOS
 		if (use_geos)
 		    geos_buffer(&In, &Out, &Buf, line, type, da,
-				&si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc);
+				&si, CCats, &arr_bc, &buffers_count, &arr_bc_alloc,
+                                straight_flag->answer, nocaps_flag->answer);
 #endif
 		if (!use_geos) {
 		    Vect_line_buffer2(Points, da, db, dalpha,

+ 34 - 5
vector/v.buffer/v.buffer.html

@@ -21,11 +21,40 @@ areas with category X (see example below).
 Buffers for lines and areas are generated using the algorithms from
 the GEOS library.
 
-<!-- built-in buffer algorithm no longer desired, we use GEOS:
-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).
+<p>
+<i>For advanced users:</i> built-in buffer algorithm no longer
+desired, we use GEOS: If GRASS is not compiled with GEOS support
+or <a href="variables.html">environmental
+variable</a> <tt>GRASS_VECTOR_BUFFER</tt> is defined, then GRASS
+generates buffers using built-in buffering algorithm (which is still
+buggy for some input data).
+
+<h3>Corner settings</h3>
+
+By default <em>v.buffer</em> creates rounded buffers (blue color on
+figure below): 
+
+<center>
+  <img src="v_buffer_line.png">
+</center>
+
+Straight corners with caps are created by <b>-s</b> flag (red color on
+the figure below), while <b>-c</b> flag doesn't make caps at the ends of
+polylines (green color on the figure below):
+
+<center>
+  <img src="v_buffer_line_s.png">
+  <img src="v_buffer_line_c.png">
+</center>
+
+<!-- Only support by GRASS buffer 
+Flag <b>-s</b> also influences corners around polygons (see red color
+on the figure below):
+
+<center>
+  <img src="v_buffer_area.png">
+  <img src="v_buffer_area_s.png">
+</center>
 -->
 
 <h2>EXAMPLES</h2>

二进制
vector/v.buffer/v_buffer_area.png


二进制
vector/v.buffer/v_buffer_area_s.png


二进制
vector/v.buffer/v_buffer_line.png


二进制
vector/v.buffer/v_buffer_line_c.png


二进制
vector/v.buffer/v_buffer_line_s.png