2

I wished to know if there's a way to make the Font Marker don't cross or be inside the the feature, as shown in the images bellow.

The text is not a label, but made in Geometry Generator with "Point/Multipoint" as Geometry Type. I imagine there's a solution with an expression in the Rotation or Offset properties, but I'm not well familiar in writing them yet.

This is the text settings:

In simbology, add a symbol layers with Geometry Generator as type. This is the expression I use: nodes_to_points( $geometry). Geometry type: Point/Multipoint.

Then in Symbol layer type I put "Font Maker". And in property Character(s) I use this expression:

'P' || to_string ( with_variable('new_position',
  with_variable('n_to_p', nodes_to_points(force_rhr($geometry)),
    with_variable('array_coord_y', array_foreach(
        generate_series(1, num_points(@n_to_p)), y(point_n(@n_to_p, @element))
      ),
      array_find(@array_coord_y, array_first(
          array_sort(
            @array_coord_y, ascending:=false
          )
        )
      )
    )
  ),
  if (
    @geometry_part_num <= @new_position,
    num_points($geometry) - 1 + @geometry_part_num - @new_position,
    @geometry_part_num - (@new_position)
  )
)-1) 

This is how it is right now: enter image description here

This is how I wanted it to be, the text outside the feature: enter image description here

3
  • Please add the whole label settings in text form, thank you.
    – Erik
    Aug 5, 2021 at 14:47
  • I wrote all the settings that I use to create the text. Hope it helps, thanks!!
    – Felippe M.
    Aug 5, 2021 at 15:21
  • I suspect you may need to generate the points as a virtual layer (with labels) and then use the polygon's labelling settings (labels>placement>obstacles>settings>minimise placing labels over the feature's interior) to ensure those labels are always outside the polygon. I can help with generating the points in SQL but the label text column I'm not so sure.
    – she_weeds
    Aug 6, 2021 at 5:02

1 Answer 1

2

Depending on the complexity of your polygons, you could get their boundaries, offset them using a miter join type (2) and then convert to points for pseudo-labelling.

nodes_to_points( 
 offset_curve( 
   boundary($geometry),
   0.05, 
   join:=2))

enter image description here

1
  • It would work if only it didn't duplicate some vertices. I don't know why it happens, but in duplicating the vertices it won't be a true representation of the polygon I'm working. I don't think there's a function that offsets the polygon preserving number of vertices, is there? I searched for it after seeing your answer but couldn't find anything. Thank you.
    – Felippe M.
    Aug 19, 2021 at 14:06

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.