Sunday, 29 January 2017

print composer - Adding a space in the "draw coordinates" "decimal with suffix" in QGIS v2.18.7


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?



Answer



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


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...