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?
I am guessing I have to edit the following.
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityGet 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.
to_dms
to help about coordinates formatting maybe.
Sep 20, 2021 at 19:53
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')
%]