6

I've set my custom grid in the print layout. The problem is, that in one corner both values from X and Y axes overlap each other.

enter image description here

I used the offset, as you can see below, but I am wondering how to make this only one value offset more than the rest.

I found some similar problems here:

Stop Grid Coordinates Overlapping in Print Layout

which led me to the bug here:

https://github.com/qgis/QGIS/issues/45876

My formula for custom grids looks like this:

CASE 
  WHEN @grid_axis = 'y'
    THEN substr('ABCDEFGHIJKLMNOPQRST', (@grid_number +105) / 100, 1) 
  WHEN @grid_axis = 'x'
    THEN round((@grid_number - 5) / 100,0)
END

And I obviously can change it simultaneously with the offset bringing them up, although I tried the solution, which would led offset just only the first value at the Y axis.

The formula I prepared looks like this:

CASE 
  WHEN @grid_axis = 'y' AND @grid_number = 'A' THEN offset = 15
END

but it stays as it is despite lack of error in the formula.

How can I offset only this one value separately?

Regarding my situation with interval 100 and offset 7 I tried also:

CASE 
  WHEN @grid_axis = 'y' AND substr('ABCDEFGHIJKLMNOPQRST', (@grid_number = 0) / 100, 1)   THEN OFFSET = 15
END

UPDATE:

I think the problem lies with the "Distance to the map frame" issue. As I set it to 5mm then the overlapping occurs. What kind of formula should I place inside then?

enter image description here

I could reduce the distance from the map frame, although with the font size I applied (24px) it still won't work.

enter image description here

9
  • How did you manage to overlap them? I cannot produce that issue. Jan 16, 2022 at 17:53
  • As you can see in the panel on your right. I used primary coordinates for lines only and secondary coordinates for the labels. By adding the offset 6 for X and 7 for Y I got quite a nice placement of my labels like 10 A, 1 I, 10 I, except for 0A in the bottom left corner, which is overlapped.
    – MKR
    Jan 16, 2022 at 18:40
  • Which version of QGIS are you using? I also couldn't reproduce the problem (QGIS 3.22). Perhaps the label engine has been updated. In my case the A and 0 were displaced independently of the offset so they didn't overlap.
    – Matt
    Jan 16, 2022 at 20:05
  • My version is 3.12
    – MKR
    Jan 17, 2022 at 9:02
  • 1
    I suggest as a test to install the latest version of QGIS and open the same project and see if this error can be reproduced. If the error disappears, it is probably a bug in an older version of QGIS. Jan 17, 2022 at 11:39

1 Answer 1

2
+50

After some experimentation it appears that the distance to frame cannot be set independently for the X and Y axes.

Here is my label grid set up. I chose Outside frame for the labels so there were legible.

enter image description here

Using a Distance to frame of 5 mm and the formula:

(@grid_axis || @grid_number)

to show the grid axis and grid number in the label itself so there can be no confusion.

enter image description here

Then for Distance to frame I used the formula

CASE 
  WHEN @grid_axis = 'y' then 20
  WHEN @grid_axis = 'x' then 0
END

Both sets of labels end up at 0 mm distance.

enter image description here

A formula using @grid_number

CASE 
  WHEN @grid_number < 10 then 20.0
  ELSE 0
END

enter image description here


Separate note about one of your formulae

The formula I prepared looks like this:

CASE    
   WHEN @grid_axis = 'y' AND @grid_number = 'A' 
   THEN offset = 15 
END 

but it stays as it is despite lack of error in the formula.

The @grid_number is never going to be A, so this formula, despite having no errors, will not evaluate. The @grid_number is always an integer and it is tied to the grid interval. The first grid square contains 100 grid numbers for each axis (1-100, 100 being your interval in mm). As seen in the image directly above, the displayed grid number for this particular set of labels is the interval 0, 100, 200, etc + the offset 6 for the x axis and + 7 for the y axis. The rest of the grid numbes still exist, but they just have no label.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.