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

Sethinacan
  • 1,724
  • 11
  • 19

1 Answers1

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

Babel
  • 71,072
  • 14
  • 78
  • 208