2

I have a point shape with the following structure:

enter image description here

What I want is to know if I can draw the polygons through the QGIS geometry generator. The separator of the polygons of another is in the "NO" field, and the order of the vertices is in the "VERTICES" field, so that it is displayed as follows:

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Gab De
  • 21
  • 1

3 Answers3

2

Perhaps the simplest way to do this with a Geometry Generator expression is with concave_hull.

concave_hull(
    -- collect points in multipoint geometries, grouped by the "NO" field.
    collect(
        @geometry, 
        group_by:="NO"
    ),
    target_percent:=0
)

The target_percent parameter is described in the documentation as follows:

target_percent

the percentage of area of the convex hull the solution tries to approach. A target_percent of 1 gives the same result as the convex hull. A target_percent between 0 and 0.99 produces a result that should have a smaller area than the convex hull.

A target percent of 0 ensures the algorithm attempts a tight a fit as possible.

Be aware that this solution may not work perfectly for very complex polygon shapes.

enter image description here

Matt
  • 16,843
  • 3
  • 21
  • 52
  • Great, it's worked for me. I used the following expression: make_polygon(make_line(array_agg($geometry, group_by:="POLYGON", order_by:="VERTICES"))) The problem I have is that I can't get the area in the center of the polygon to be displayed. – Gab De Feb 05 '24 at 21:56
2

I do not know if it is possible not to create N polygon features from N input points with the "Geometry by expression".

However, one can try the following expression:

make_polygon(
    close_line(
        make_line( 
            geometries_to_array(
                aggregate(
                    layer:='YOUR_LAYER_NAME',
                    aggregate:='collect',
                    expression:=@geometry,
                    order_by:="vertex_ind", -- change accordingly
                    filter:="id"=attribute(@parent,'id') -- change accordingly
                    )
                )
            )
        )
    )

to revive the polygons from their initial vertices.

However, one more additional step via the "Delete duplicate geometries" will be needed.

Input:
input

Output:
output

To visualize area use this expression:

round($area, 4)

in the Labels > Single labels tab.

labels

P.S. Also pay attention to this thread: Calculating polygon areas in shapefile using QGIS.

Taras
  • 32,823
  • 4
  • 66
  • 137
  • Great, it's worked for me. I used the following expression: make_polygon(make_line(array_agg($geometry, group_by:="POLYGON", order_by:="VERTICES"))) The problem I have is that I can't get the area in the center of the polygon to be displayed. – Gab De Feb 05 '24 at 21:56
1

I used my point example with two squares:

  1. Add table as point layer:

Add table as point layer:

  1. Use "Point to path" tool to convert point to line in correct order and group them according to your data. Use Closed Path option to create polygon if your last point is not the same as the first point:

Convert point to line

  1. Use "Line to Polygon" tool to convert close polylines to polygon:

Convert close polylines to polygon

  1. And you have the correct result:

Result

  1. The other possibility is to do it directly with tool Geometry by expression. But points have to be in our case (without advanced expression :)) in csv file already in correct order! :

Geometry by expression

JA_LL
  • 31
  • 5
  • Let me tell you, that the query arises as a result of the fact that I have just discovered the Geometry Generator tool, and that is why I wanted to know if it was possible to do this "work", outside the normal QGIS process. – Gab De Feb 05 '24 at 08:30
  • I added "5. The other possibility is to do it directly with tool Geometry by expression.". It is quite straightforward – JA_LL Feb 05 '24 at 09:37