3

This question is inspired by Displaying vertex coordinates of a polygon or line without creating a new layer and especially by the answer by @JGH: https://gis.stackexchange.com/a/381130/88814

The basic problem is how to label vertices in QGIS using expressions only (without creating a new layer). Whereas @JGH uses geometry generator to create points on the vertices and sets a Font Marker to it, which in turn is not a character, but an expression to generate in this way sort of a label for the coordinates of every vertex.

This is really a great solution, only that you don't have all the styling options for labels like marker lines, rotation, text buffer etc. (see screenshot below). It would be great to create real labels for each vertex. The only problem seems to be that it is not possible to select the @geometry_part_num Variable (as in @JGH's solution) in the label text field as this variable is not available.

So the question is: is it possible to find an expression that generates the values of the x and y coordinates of each vertex?

Placing a label for each vertex of a geometry (but with the same label text) is possible by setting a label that is placed on a point created by geometry generator with the following expression - maybe it can be adapted somehow for the label text as well:

collect_geometries(
    array_foreach (  
        generate_series( 1,  num_points( $geometry)),

        make_point (
            x ( point_n($geometry, @element)),
            y ( point_n($geometry, @element))
        )
    )
)

enter image description here

2
  • 3
    Conceptually a label is the display of one property, applied on each features. To have multiple labels for a feature, we must use rule based labeling and add different rules, so here it would be a value of x(point_n($geometry,1)) for a placement of point_n($geometry,1) and repeat with an increasing index... it may work for small polygons - with the help of a script writing all the rules - but I doubt it would work for larger ones. At this point, it might be simpler to just add a layer, maybe a virtual layer, to extract the points and to apply a simple label. – JGH Dec 5 '20 at 3:01
  • OK, that sounds reasonable – Babel Dec 5 '20 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.