1

Just a follow-up query about the existing thread QGIS expression for label text to display vertex coordinates of polygons. Is there an expression in QGIS to collect all the coordinates from the geometry generator and add to a virtual field of the polygon?

1
  • 1
    You could use geom_to_wkt("Your Geometry Generator Expression") and save that.
    – Dror Bogin
    Commented Jan 8, 2021 at 7:24

2 Answers 2

2

You could if you use the same expression, but not directly take the expression from the geometry generator. with your example using a buffer over a point layer:

array_to_string(  array_foreach (  
        generate_series( 1,  
        num_points( 
            buffer($geometry,1000)
           )
        ),
         to_string(x(point_n(buffer($geometry,1000), @element)))+' '+
         to_string(y(point_n(buffer($geometry,1000), @element))
        )
    ) ,', ')

I used it on a layer with one point but it should work on any geometry geomerated with an expression if you make sure to use the expression all 3 time (in num_points and in each point_n)

enter image description here

2
  • That works, it creates a list of coordinates of the polygon: i.sstatic.net/S4dZ0.png - however, it is not possible to label individual points: i.sstatic.net/3NaIb.png - is it?
    – Babel
    Commented Jan 8, 2021 at 8:03
  • 1
    It only creates a string for the points, If you wanted to label each one the original question answer is what's needed. or your answer, create a wkt and a virtual layer and label it. Since labels are created per feature, you can't really bypass creating a new layer.
    – Dror Bogin
    Commented Jan 8, 2021 at 8:05
0

If you just need a list of coordinates, the answer by @Dror Bogin is the way to got.

If you want to have coordinates per vertex (e.g. to label them), you can't do this using without creating a new layer. You can create a virtual layer with this solution proposed by @J. Monticolo: https://gis.stackexchange.com/a/382382/88814 - it works great even for complex multipart geometries with holes.

You can than very easily create a (virtual) field on this virtual layer for the coordinates using $x and $y.

Geometry generator however does not create individual points (vertices). So you can't create new features, every vertex of the polygon will always be part of the polygon feature, so you can't address the points individually to get their coordinates. Also the attribute table of the polygons has just one entry per polygon feature, so you can't individualise the points there.

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.