I would like to set my custom grid in the QGIS map composer. enter image description here

I tried these threads:

How to create a custom coordinate grid in the QGIS 2.14.2?


but nothing was working. Labels simply disappear.

My initial format looks like this:

   substr('ABCDEFGHIJKLMNOPQRST', (@grid_number - 1) / 0.25 + 0.5, 1)

but I also tried:

 WHEN @grid_axis = 'y'
 WHEN substr('ABCDEFGHIJKLMNOPQRST', (@grid_number + 2.5) / 5 , 1) 
 WHEN @grid_axis = 'x'
 THEN (@grid_number + 2.5) / 5

The effect is exactly the same. No grid at all. Where I am making mistake here?

  • 2
    Have you set the Interval measurement unit of your grids to mm (or cm)? If it is in Map Units then it might be degrees, in which case the grid lines will be very widely spaced and not appear on your map. For the record, I follow the tutorial in the second link and everything was working fine.
    – Matt
    Jan 11 at 20:41
  • Yes, see my answer below. Admittedly I shouldn't steal your solution, but it was not enough for my situation. Anyhow it was a great hint, which has led me to solve this problem. I've included also the interval, which plays a key role here.
    – MKR
    Jan 12 at 15:12
  • No problem :) it was just a guess and therefore I didn't feel it warranted an offical answer. I am glad you figured it out. Don't forget to mark your answer as correct to help others with a similar issue.
    – Matt
    Jan 12 at 16:49

Thanks to this short comment above I was managed to solve it. However, is not as simple as pointing in this comment. Apart from changing the units we also have to play with our formula though. enter image description here

Important is also the grid interval, which is 1 as default. Since I changed it to 100 both for X and Y, then the formula had to be adjusted to it.

So our formula for the interval 100 might look like this:

 WHEN @grid_axis = 'y'
 THEN substr('ABCDEFGHIJKLMNOPQRST', (@grid_number + 0) / 100 , 1) 
 WHEN @grid_axis = 'x'
 THEN (@grid_number + 0) / 100

In this case, we start from 0 and our first graticule falls at unit 100, because we set interval 100. Next we should divide this unit by our interval value, which is 100, therefore 100/100 will give us 1. It means, that our grid will start from 0, then 1, 2, 3... and so forth. The same for the Y-axis, where we defined the letters instead. Our alphabet is over 20 characters (in the formula we defined exactly 20 characters), therefore it won't appear for the 100th unit. The formula should be roughly the same. In this case, the 0 will be our letter A, then 1 - B, etc, etc.

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.