3

I am using QGIS v2.18.7. In the Print Composer I have turned on the "Draw coodinates" option "Decimal with suffix" to add these to my map.

However, I need to add a space between the degrees symbol and the suffix.

For example, the default for "Decimal with suffix" is 10°S while I would like (due to journal requirements) to have: 10° S.

I see there is a custom option, but it I can't figure out how to get this output?

3 Answers 3

5

In the print composer, after having added a map and enable the grid display under grids-->Draw grid-->Draw coordinates, you can select the custom option to specify the formatting. To enter your particular specifications for the coordinates, you need to click on the greek letter e symbol (epsilon) on the right.

enter image description here

You would then make use of the @grid_number and @grid_axis variables. Let's remember that for each coordinate to be printed, the custom format function will be called. @grid_number contains the value (number) to be printed while @grid_axis indicates if it is on the x or y axis. So, a negative value means South (for y) or West (for x). A positive means North or East.

The format function would start by displaying the absolute value with 2 decimals (it's up to you) - if any -, then adds the space and degree sign. It then forks it logic depending on whether the function is called for the X or Y axis (written as a case statement for readability). For each case, it again forks it logic depending on whether it is a negative or positive value. Finally, for each of the 4 combination (axis + sign), it adds the N/S/E/W letter to the label to be returned.

abs(format_number( @grid_number ,2)) 
|| ' °' 
|| CASE 
    WHEN  @grid_axis = 'x' 
       THEN 
         IF (@grid_number > 0, 'E' , 'W')
       ELSE
           IF (@grid_number > 0, 'N' , 'S')
       END

custom grid format

1

Although the code provided by JGH works perfectly, here is a minor change to omit the suffix when dealing with 0°.

abs(format_number( @grid_number ,2)) 
|| ' °' 
|| CASE 
    WHEN  @grid_axis = 'x' 
       THEN 
         IF(@grid_number=0, ' ' , IF (@grid_number > 0, 'E' , 'W')) 
       ELSE
           IF(@grid_number=0, ' ', IF (@grid_number > 0, 'N' , 'S'))

       END
0

The answers by @JGH and @Gabriel Bragion didn't work for me because abs() refused to parse "0,00" (because comma is not a valid separator for a floating point number)

Reordering helps (first abs() then format_number()), as done below:

format_number( abs(@grid_number) ,2) 
|| ' °' 
|| CASE 
    WHEN  @grid_axis = 'x' 
       THEN 
         IF(@grid_number=0, ' ' , IF (@grid_number > 0, 'E' , 'W')) 
       ELSE
           IF(@grid_number=0, ' ', IF (@grid_number > 0, 'N' , 'S'))

       END

Your Answer

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

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