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

1
  • 1
    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?
    – Babel
    May 7 at 9:19

1 Answer 1

1

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

11
  • 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?
    – Anthony
    May 11 at 18:18
  • Should work the same for Geometry by expression
    – Babel
    May 11 at 18:54
  • I'm getting ---> Evaluation error: Cannot convert to geometry
    – Anthony
    May 11 at 19:15
  • For me, it works - testet right now. When you use geometry generator, does it work?
    – Babel
    May 11 at 19:16
  • Yes - your solution works using the Geometry Generator, but returns the evaluation error listed above.
    – Anthony
    May 11 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.