2

I can already create lat/lon or UTM grid in Print Composer but I was also asked about possibility to have a mix of both:

1) standard map grid using UTM - I can do this :-)

and

2) latitude/longitude (EPSG:4326) coordinates of map item corners.

The reason is to have UTM grid to easily see the distance on printed map, but also the lat/lon coordinates for a GPS.

I would probably be able to get close to this solution with Map Corners Coordinates Plugin

https://ctu-geoforall-lab.github.io/qgis-map-coords-plugin/

and copy the coordinates from resulting text file in a text object in Print Composer.

But the plugin is still QGIS2 only and the map canvas corners might be quite different from the map item extent in Print composer.

The item properties in composer also displays some coordinates so I might be able to copy it from there but would probably need to switch to EPSG:4326 for map canvas which would distort my maps.

any idea how to do it?

PS: if there is no direct solution, does Print Composer support some sort of custom scripts or plugins we could make someone create?

2 Answers 2

5

You can retrieve the extent coordintes of map item via variables, and use them in text box.

x_min - [% to_dms(x_min(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326')),'x',2)%]
y_max - [% to_dms(y_max(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326')),'y',2)%]

enter image description here

Expression explained step by step:

To get the geometry of map item use (map item name is map):

map_get(item_variables('map'),'map_extent')

Retrieve the corner coordinate with y_max, y_min, x_max or x_min

y_max( map_get(item_variables('map'),'map_extent'))

For getting WGS84, use transform function. Example of transfrom from EPSG:3857:

y_max(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))

To change degrees format to DMS just use to_dms function

to_dms(y_max(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326')),'y',2)

Adjust the text in box, add both corner coordinates and format as needed. Repeat the process for rest corners. Values will be automatically updated when you move the map extent.

6
  • thanks, that works nice: Corners - EPSG:4326 WGS 84 (GPS), decimal degrees Upper left: latitude [%y_max(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))%]; longitude [%x_min(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))%] Lower right: latitude [%y_min(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))%]; longitude [%x_max(transform( map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))%]
    – Juhele
    Commented Oct 10, 2019 at 10:20
  • 1
    can I somehow limit number of decimal places in the result? I first thought the ",'x',2" and ",'y',2" part does this but seems not to work in my case or I might write something wrong...
    – Juhele
    Commented Oct 10, 2019 at 10:24
  • Yes exactly, this should work. The digit is precission - number of decimals. Syntax is 'to_dms(coordinate,axis,precision[,formatting])`
    – Oto Kaláb
    Commented Oct 10, 2019 at 12:20
  • hmm, so the first one should work, but does not: 1) latitude [%y_max(transform(map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326')),'y',2)%] while the second works.. 2) latitude [%y_max(transform(map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326'))%]
    – Juhele
    Commented Oct 10, 2019 at 13:05
  • 1
    I got the point :). It depend what format of coordinats you need: DMS (degree,minutes,seconds) - in my answer, or for DD (decimal degrees) you don't have to use to_dms, you can just round the number with round: [% round( y_max(transform(map_get(item_variables('map'),'map_extent'),'EPSG:3857','EPSG:4326')),2)%]
    – Oto Kaláb
    Commented Oct 10, 2019 at 15:06
3

Yes it is possible without plugins. You need to create two grids: one for the UTM Coordinates and the other for WGS84.

Here is an image that shows both of the grids.

enter image description here

The black grid is UTM and the red is WGS 84. For UTM, I think you know how to do it since the data is in UTM. Now, When adding additional grid for WGS 84, you need to change the CRS to WGS 84 as in the image below:

enter image description here

When you define the appropriate x and y spacings, enable add labels and it will show them in geographic coordinates.

2
  • Yeah, but getting the coordinates of the map corners might be difficult as you would have to somehow force the second grid to only show coordinates at the corners and also to fit the corners of the map.
    – Juhele
    Commented Oct 9, 2019 at 14:32
  • My current map item in Composers seems to have Range set in Pseudo Mercator (as I am using some map from OpenLayers) so maybe I would only need to convert the Xmin, Ymin and Xmax, Ymax to EPSG:4326 using some converter like this one: epsg.io/transform#s_srs=3857&t_srs=4326
    – Juhele
    Commented Oct 9, 2019 at 14:36

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.