Create a custom reference grid in qgis composer part 2
Posted by: Admire Nyakudya | in QGIS | 1 year, 10 months ago | Comments

This is a follow-up post on

This post outlines how to make dynamic grids that are aligned to the lat long graticule.

Create one grid to show the lines with intervals in decimal degrees.

Create another grid to show the labels in the center of the visible grid cells.  Note the offset is set to half the interval and we don't draw the lines.

Navigate to the label setting for the second grid and choose the following.

Click expression builder on custom.

Click on the function editor and create a new function. Populate the contents with following  and save your changes.

Click on the expression and enter the following:

@GRID_NUMBER - TO_INT(MAP_Y_MIN( 'A4 portrait', 'main') / 0.016666666667)*0.016666666667 + 0.008333333000
/ 0.016666666667, 1)
@GRID_NUMBER - TO_INT( MAP_X_MIN( 'A4 portrait', 'main') / 0.016666666667)*0.016666666667 + 0.008333333000
) / 0.016666666667, 2)

The parameters for the map labels are explained below:

* A = Composer title

* B = Item ID for the map

* C = Grid Interval in lat long (calculated as (1/60) to get a minute grid)

* D = Grid offset in lat long ( calculated as half of the Grid interval)

* E = Custom python function ( Copied from )

Your map will be labelled accordingly now.

NB: The script for labelling assumes that your map CRS is 3857. So it will transform the bounding box from EPSG:3857 to EPSG:4326. If your map is using another CRS you can change the following

The script also assumes the map has an item id assigned. Many users do not know the significance of adding the Item ID for each map element.

Currently unrated


Have any questions? Contact us.
We would love to hear from you!
Subscribe to our Mailing list (spam-free, industry-relevant occasional emails)

Subscribe to our mailing list

* indicates required