[GIS] Adding latitude/longitude coordinates of a map item in QGIS3 Print composer

coordinatesprint-composerqgis

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?

Best Answer

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.

Related Question