3

Is there a way to generate a polygonal buffer on the end of an existing polygon in QGIS? The red polygon was added using MS Paint as an example of what I would like to achieve. Ideally, the red polygon would extend from the orange polygon from the center point (red vertex) - equally or similar to a buffer. It would be even better if the red polygon could maintain the width of the orange polygon. Not sure if this is possible or something Geometry by Expression could handle.

polygon_buffer_on_end_of_polygon

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 6, 2022 at 17:34
1
  • 2
    What is the "end of a polygon"? You have only rectangles and you want to create the buffer at the smaller side of it? At both ends or just one end? Commented May 7, 2022 at 9:19

1 Answer 1

2

You can use QGIS expressions with Geometry Generator and this expression for rectangles - see screenshot at the bottom.

Variants:

  • If you want the "buffers" only on one side, in line 3 replace (-1,1) by (1) to get only one end or by (-1) to get only the other end.
  • In case you want the "buffers" on the long side of the rectangle, in line 18 change radians (main_angle ($geometry)) into radians (main_angle( $geometry)-90)
collect_geometries (
 array_foreach(
 array(-1,1), --change here to get buffers only at one end
 with_variable (
 'int',
 intersection (
 boundary($geometry),
 make_line(
 centroid ($geometry),
 project (
 centroid($geometry),
 @element* length (
 make_line(
 centroid($geometry),
 point_n($geometry,1)
 )
 ),
 radians (main_angle ($geometry)) -- change here to get buffers at the long side of rectangles
 )
 )
 ),
 make_regular_polygon(
 @int, 
 project (
 @int, 
 length(
 make_line (
 @int,
 closest_point (
 nodes_to_points($geometry),
 @int
 )
 )
 ),
 radians (main_angle ($geometry))
 ),
 4,
 1
 )
 )
 )
)

Yellow: original rectangles, blue with red outline: created "buffers": enter image description here

answered May 7, 2022 at 10:36
10
  • Thank you for providing an answer to my question. What would I change in your expression if I wanted to save the results to a shapefile using Geometry by Expression? Commented May 11, 2022 at 18:18
  • Should work the same for Geometry by expression Commented May 11, 2022 at 18:54
  • I'm getting ---> Evaluation error: Cannot convert to geometry Commented May 11, 2022 at 19:15
  • For me, it works - testet right now. When you use geometry generator, does it work? Commented May 11, 2022 at 19:16
  • Yes - your solution works using the Geometry Generator, but returns the evaluation error listed above. Commented May 11, 2022 at 19:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.