I have managed to get a custom grid on the print layout to convert northing and eastings (XY) to ESPG:27700 grid references i.e NS00 through to NS99.

The problem I am coming across is when when NS99 crosses into NT00 (see image)

enter image description here

As you can see the x axis will change, but the Y axis on the right hand side should change to NT rather than NS, I know why it isn't - the expression based annotation is reading the NS query first and thus overring the NT query. The same happens on the X axis when you move down from NS to NX (it will read the NS query first).

Is there any way of getting the grid sidings to read independently from each other? Because this has been a real head scratcher for me...

Right now I have 55 different print layouts for each 100km square across the UK, but would love to just have one, and not have to fudge in labels when I have to map across a boundary!

Edit: expressions

when @grid_axis = 'x' and
(@grid_number >=200000) and (@grid_number <300000)   
then'NS' + left(right(@grid_number,5),2)  
when @grid_axis = 'y' and (@grid_number >=600000) and (@grid_number <700000)   
then 'NS' + left(right(@grid_number,5),2)  
when @grid_axis = 'x' and (@grid_number >=300000) and (@grid_number <400000)   then 'NT' + left(right(@grid_number,5),2)  
when @grid_axis = 'y' and (@grid_number >=600000) and (@grid_number <700000)   
then'NT' + left(right(@grid_number,5),2)  

1 Answer 1


Your conditions for the y axis labels are identical. They both cover @grid_number values between 600000 and 700000. Presumably one of them should be for a different @grid_number range.

when @grid_axis = 'y' and (@grid_number >=600000) and (@grid_number <700000)

then 'NS' + left(right(@grid_number,5),2)


when @grid_axis = 'y' and (@grid_number >=600000) and (@grid_number <700000)

then 'NT' + left(right(@grid_number,5),2)

  • Hi csk, thanks for your reply, They have to be Identical; see Image, imgur.com/a/RokNaZU The problem I'm coming across is my fairly limited knowlege of QGIS sql. Is there a way to tell the grid to hone in on specific 1km squares and relabel the sides according to the 100km square grid ref, - or is this a limitation of QGIS layout girds? Cheers Sam Feb 15, 2019 at 9:22
  • A map item in the print composer has a variable called 'map_extent' which contains the map extent as a polygon geometry. I think you can call the 'map_extent' variable like this: item_variables( 'map name', 'map_extent'). Maybe you can use this variable with the geometry functions to test which N- square(s) are within the map extent.
    – csk
    Feb 15, 2019 at 18:42
  • no luck yet unforntunately @csk :( Feb 20, 2019 at 16:12
  • I couldn't quite get there with expressions (hence why I posted the suggestion as a comment, not a full answer). If you can't make that work either, maybe it's time to try a different approach. If you create the grid as a polygon vector layer, you can add the cell names as attributes and label it on the map.
    – csk
    Feb 20, 2019 at 17:46
  • Yeah, that was my back up approach...I also have 60 odd map layouts for each square! I wanted to get around using polygons so other users can just load up the map layout and it works without them having to faff around with other layers and symbologies etc! Thanks for you help though, much appreciated. Feb 25, 2019 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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