3

I am using QGIS 3.8.1.

The intervals of my grid are 1.2cm and the labels are set at a 0.6cm offset so they are placed in the middle. I used the draw coordinates custom option to enter my own coordinates rather than from a coordinate reference system. The code I used is as follows and the problem I am encountering can be seen in the image below.

CASE 
WHEN @grid_axis = 'y'    
THEN substr('ONMLKJIHGFEDCBA', (@grid_number + 0.6 ) / 1.2 , 1)     
WHEN @grid_axis = 'x'    
THEN (@grid_number + 0.6) / 1.2    
END

enter image description here

6

You can use the round() function to make sure no decimal shows:

Modify your expression like this:

CASE 
WHEN @grid_axis = 'y'    
THEN substr('ONMLKJIHGFEDCBA', (@grid_number + 0.6 ) / 1.2 , 1)     
WHEN @grid_axis = 'x'    
THEN (round(@grid_number,0) + 0.6) / 1.2    
END

The values should be rounded to the nearest integer.

enter image description here

3
  • Ok this took off the decimal places but now replaced all my grid labels to 1 – Tony Brown Mar 4 '20 at 20:43
  • 1
    @TonyBrown There has to be something else going on with your expression. I tried your setup with two grids, one offset 0.6cm for the labels, and I had to use THEN round(@grid_number,0) for the X axis. Check screenshot in edited answer. – Gabriel C. Mar 4 '20 at 20:48
  • You are correct and I fixed it to be identical to yours. It is now missing every number which is a multiple of 6 for some reason. – Tony Brown Mar 4 '20 at 22:27

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.