QGIS – Making an Octagon Using Geometry Generator

expressiongeometry-generatorpolygonpolygon-creationqgis

I am a self-taught QGIS user and am trying my hand at the geometry generator. I have been tasked with creating a map that has gazebos as points. There are so many easier ways to get a polygon like the one I am going for (.svg marker), but I'm trying to branch out. I got to this point by following Klas Karlson awesome geometry generator video. Here is my go at making an octagon:

make_polygon(
    make_line(
        make_point($geometry, 0.414, 1.000),
        make_point($geometry, 1.000, 0.414),
        make_point($geometry,  1.000, -0.414),
        make_point($geometry,  0.414, -1.000),
        make_point($geometry,  -0.414, -1.000),
        make_point($geometry, -1.000, -0.414),
        make_point($geometry, -1.000, 0.414),
        make_point($geometry, -0.414, 1.000)
))

This is what I got so far:

10-sided "octagon"
10-sided "octagon"

Klas Karlson Geometry Generator Video

Best Answer

You can do this much easier with the function make_regular_polygon() like this:

make_regular_polygon(
    $geometry, 
    project($geometry,5,radians(360/16)),
    8
)

5 in line 3 is the size of the radius, radians(360/16) is the rotation for a horizontal upper line, you can change the angle inside the brackets to get other rotations - e.g. 0 for the rotation like in the screenshot:

enter image description here