TransWikia.com

Labeling grid automatically using QGIS

Geographic Information Systems Asked on December 8, 2021

I have a polygon layer with a number as label. Now I want that my labeling is always in the left upper corner of the single polygon, like in the screenshot.The red rectangle is the position, where the label should be placed

enter image description here

If I zoom in the should be visible and placed like in the second screenshot.

enter image description here

If such a labeling is possible, how can I create that?

I tried the labeling tab of the gui, but it doesn´t work pretty well
With my settings the labels of other polygons where placed in their visible neighbours

enter image description here

2 Answers

To completely answer the question we need to extend the answer of Michel by adding a label to any grid squares cut off by the top and left hand edges of the canvas. This can be done by updating the geometry expression to:

make_point(x_min(intersection(@map_extent, $geometry)), y_max( intersection(@map_extent, $geometry)))

enter image description here

Answered by Ian Turton on December 8, 2021

To get that result in QGIS 3.14:

  • Check the 'Geometry generator' option inside the labels options and add make_point(x_min( $geometry), y_max( $geometry)) in the expression box
  • Select 'Offset from point' placement
  • Select the bottom right Placement Quadrant
  • Adjust the 'Offset X,Y' settings to move the label a little away from the corner if necessary

enter image description here

An alternative method for older QGIS versions:

  • Duplicate your layer (we'll use one layer for the grid and another for the labels)
  • Select 'Single Symbol' styling
  • Select 'Geometry Generator' as 'Symbol layer type'
  • Select 'Point/Multipoint' as 'Geometry type'
  • Add make_point(x_min( $geometry), y_max( $geometry)) in the expression box
  • Change the 'Symbol layer type' under 'Geometry Generator' from 'Simple marker' to 'Font marker'.
  • Set the 'Anchor point' to 'top left'
  • Click on the 'Data defined overide' button next to the 'Character' box and select 'Edit'.
  • In the window that pops up type in the field name (between double quotes) you want to use to label.
  • Click OK
  • Adjust the 'Offset X,Y' settings to move the label a little away from the corner if necessary

enter image description here

enter image description here

enter image description here

enter image description here

Answered by Michel Stuyts on December 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP