4

I am trying to display the vertices of a polygon with vertex number. In symbology, I have used the Marker line and font marker. enter image description here.

When the Line offset is -5 positive the text 'P7' is displayed far from the point. So I changed the Line offset to 5, and an extra vertex gets added (p8).

My Questions

  1. Why does extra vertex appear? (I have checked the vertex editor, there is only one vertex at that position)
  2. How can I place the text near the point at the concave section? When offset is negativeWhen offset is positive
2
  • 1
    I can replicate it - feels like it is probably a bug. Feb 26 at 5:41
  • Maybe all those vertices are "inner"? Can you disable the "first"? Feb 26 at 9:39

2 Answers 2

3

Instead of marker line, use Geometry Generator symbol layer type and use the following expression to create the vertices, then apply the marker type you wish:

collect_geometries(
    array_foreach(
        generate_series (
            1,  
            array_length(
                geometries_to_array( 
                    nodes_to_points ($geometry)
                )
            )-1
        ),
        point_n($geometry, @element)
    )
)

enter image description here


Variant to place all the font markers indide (or outside) of the polygon

For this, modify the geometry expression accordingly. Adapt the distance in line 3 to an appropriate value (if you make the value negative, points will be place outside of the polygon; with positive values inside the polygon):

enter image description here

with_variable(
    'dist',
    0.01, -- set an appropriate distance; negative values to place outside of the polygon
collect_geometries(
    array_foreach(
        generate_series (
            1,  
            array_length(
                geometries_to_array( 
                    nodes_to_points ($geometry)
                )
            )-1
        ),
        end_point(
            extend(
                make_line (
                    point_n($geometry, @element),
                    project (
                        point_n($geometry, @element),
                        -@dist,
                        radians(90+angle_at_vertex( $geometry, @element-1)))
                ), 
                0,
                @dist*5
            )
        )
    )
))
2
  • For your first expression, to generate the vertices you could just use nodes_to_points($geometry,true) (second parameter specifies ignore_closing_node) And the second expression could be simplified to with_variable('dist', 0.01,collect_geometries(array_foreach(generate_series(1,num_points($geometry)-1), project(point_n($geometry,@element),@dist,radians(90+angle_at_vertex($geometry,@element-1)))))) - maybe modulate @dist by @map_scale to allow for scaled distance.
    – she_weeds
    Feb 29 at 13:11
  • Thanks a lot @she_weeds for these improvements! Appreciate it very much. Indeed, obviously I should have not complicated things too much and simply used nodes_to_points
    – Babel
    Feb 29 at 16:03
3

To answer question 1: it isn't a bug. It's because you changed the entire line offset of the line that the font marker is applied to, not the offset for the font markers themselves.

Applying a line offset is like drawing the outline of a buffer. At sharp corners, whether concave or convex, in order to maintain a constant line offset distance, the geometry of the resulting line has to change by adding an extra vertex to accommodate, even when the join type is miter (i.e. retains sharpness; join type round will obviously generate way more additional vertices).

Here's a visualisation of an Outline: simple line symbol, with the line offset set to 5 mm. Notice that with the sharp concave corner, the shape cannot retain the same sharpness (=1 vertex) without the extreme point having >5mm distance from the original line. Therefore an extra vertex is added to accommodate. You will see a similar effect for sharp convex corners as well.

enter image description here


Question 2: Going back to your original set up, to adjust font marker position typically you should use the x/y offset parameters of the font marker itself, rather than the line offset for the marker line.

Of course, this only adjusts your font markers in the X/Y direction rather than away from the point.

However, if you just want the font marker at a specific vertex to be shifted, you can use a data-defined override for the font marker offset.

enter image description here

For example, if you want to offset vertex 7 by -10mm in the X dimension:

array(
    if(@geometry_point_num = 7, --vertex no. to apply custom x offset to
       -10,                      --custom x offset
       string_to_array(@value,',')[0]),
    string_to_array(@value,',')[1]
    )

enter image description here


Ultimately, though, a geometry generator approach like Babel's is ideal (if you want to use layer styling) as you have full control of the geometry and therefore number of vertices generated, rather than be vulnerable to the number of markers generated by marker line symbology.


If you want full labeling control of your vertices, rather than mucking around with complex offset expressions, you could use Virtual Layer per this answer as long as your polygon layer has an unique ID field (p.id in the linked answer)

1
  • Well spotted, and a great explanation.
    – Matt
    Feb 29 at 13:52

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.