AnswerBun.com

Labeling grid automatically using QGIS

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

Geographic Information Systems Asked on December 8, 2021

2 Answers

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!

Related Questions

Measuring area of raster classes?

5  Asked on October 21, 2020 by mr-angus

       

Using Calculated Fields in ArcGIS Pro Reports

1  Asked on October 20, 2020 by camjoe920

   

Merging CSV data into TopoJSON file

2  Asked on October 19, 2020 by travmatth

     

Find vertices of LineStrings within Polygon – Shapely

0  Asked on October 18, 2020 by alex-jstel

     

proj4js with geocentric CRS

1  Asked on October 17, 2020 by jawensi

       

OpenLayers pass character parameters problem

0  Asked on October 17, 2020 by nemo

 

Importing and rendering Esri dot-density data in QGIS

1  Asked on October 16, 2020 by matt-brunt

   

GeoServer behind proxy returning 403

0  Asked on October 16, 2020 by user255480

   

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.