4

I am using the smooth function in a shape generator to represent tree canopies following this example It mostly works really well but I always get one sharp corner and its always at the second vertex. I have tried running Vector:Smooth from the processing toolbox to test if it's the shape generator that's the issue but I get the same results. I also get the same issue if I use create geometry by expression from the processing toolbox.

I know 50 iterations is extreme and I only need 10 to get a good result Smoothing code

And here is an example with the smoothed line shown in orange - the north most corner is sharper than it should be

Smoothed Canopy

3
  • 2
    Can you provide sample data? Otherwiese it's difficult to help. Please also post your code as text, not as image.
    – Babel
    Commented Dec 3, 2022 at 20:07
  • You might be also interested in this: gis.stackexchange.com/a/390649/88814
    – Babel
    Commented Dec 3, 2022 at 20:35
  • That answer has some different ways of doing it I hadn't thought of
    – Sethinacan
    Commented Dec 4, 2022 at 18:52

1 Answer 1

6

You set the fifth argument of the function smooth(), the optional max_angle. You have a value of 130. Delete it, than the sharp angle disappears: smooth ([your_polygon], 50, 0.2, 0.1)

From help:

Argument max_angle: maximum angle at node for smoothing to be applied (0-180). By lowering the maximum angle intentionally sharp corners in the geometry can be preserved. For instance, a value of 80 degrees will retain right angles in the geometry. https://docs.qgis.org/3.22/en/docs/user_manual/expressions/functions_list.html#smooth

Smoothing a line based on the blue points: with (black line) and without (red line) max_angle argument: enter image description here

1
  • 1
    Glad it was something simple
    – Sethinacan
    Commented Dec 4, 2022 at 18:51

Your Answer

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

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