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.
-
2What 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– Babel2022年05月07日 09:19:34 +00:00Commented May 7, 2022 at 9:19
1 Answer 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))
intoradians (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
-
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– Anthony2022年05月11日 18:18:03 +00:00Commented May 11, 2022 at 18:18
-
Should work the same for
Geometry by expression
Babel– Babel2022年05月11日 18:54:57 +00:00Commented May 11, 2022 at 18:54 -
I'm getting ---> Evaluation error: Cannot convert to geometryAnthony– Anthony2022年05月11日 19:15:18 +00:00Commented May 11, 2022 at 19:15
-
For me, it works - testet right now. When you use geometry generator, does it work?Babel– Babel2022年05月11日 19:16:28 +00:00Commented May 11, 2022 at 19:16
-
Yes - your solution works using the Geometry Generator, but returns the evaluation error listed above.Anthony– Anthony2022年05月11日 19:18:43 +00:00Commented May 11, 2022 at 19:18