5

I am customising a layout map to print it in PDF with QGIS. I have a Box where i would like to automatically display the coordinates of the center of the map if possible.

How can I do it?

enter image description here

I am guessing I have to edit the following.

enter image description here

8

Get them with:

map_get(item_variables('Map 1'),'map_extent_center')

which returns a <geometry: Point>. Then extract x and y values as you like, for example:

'X-Centroid: ' ||
x(centroid(map_get(item_variables('Map 1'),'map_extent')))
|| ' - ' ||
'Y-Centroid: ' ||
y(centroid(map_get(item_variables('Map 1'),'map_extent')))

Replace Map 1 with the name of your map in print layout.

2
  • 2
    Correct. You might need to add a to_dms to help about coordinates formatting maybe.
    – etrimaille
    Sep 20 at 19:53
  • Could you please explain me how to get this approach? I am trying like: to_dms (x(centroid(map_get(item_variables('Map 1'),'map_extent')))) But it doesnt work. Thanks.
    – Serggg182
    Sep 21 at 10:24
3

To get the result in DMS, try this expression construction:

[%
'B: ' ||
to_dms(y(transform(centroid(map_get(item_variables('Map 1'),'map_extent')), map_get(item_variables('Map 1'),'map_crs'), 'EPSG:4326')), 'y' , 2, 'aligned')
|| '\n' ||
'L: ' ||
to_dms(x(transform(centroid(map_get(item_variables('Map 1'),'map_extent')), map_get(item_variables('Map 1'),'map_crs'), 'EPSG:4326')), 'x' , 2, 'aligned')
%]
1
  • Thanks a lot, it works perfectly and it is exactly what i wanted :)
    – Serggg182
    Sep 24 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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