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?
2 Answers
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
)
-
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?– BabelCommented Jan 8, 2021 at 8:03
-
1It 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. Commented Jan 8, 2021 at 8:05
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.
geom_to_wkt("Your Geometry Generator Expression")
and save that.