1

I was commissioned to create a simple print layout. The basic-layout is very simple, it just contains one map with OopenStreetMap-layer.

I want to add the Xmin, Xmax, Ymin and Ymax of this map (like all the values in the extention-tab) as text field. The text field should then display the coordinates of the map's corners, and should automatically adjust when I zoom in or out, so copy&paste is not an option.

Taras
  • 32,823
  • 4
  • 66
  • 137
J. R.
  • 11
  • 1
  • 1
    I think what you want is to add a coordinate grid to the map. You can check this part of the documentation for more info: https://docs.qgis.org/testing/en/docs/user_manual/print_composer/composer_items/composer_map.html#grids – JonasV Aug 19 '20 at 12:06

1 Answers1

3

To get the coordinates of the upper right corner of your map, use the following expression:

round(x_max(map_get(item_variables('Karte'),'map_extent')))||', '||round(y_max(map_get(item_variables('Karte'),'map_extent')))

item_variables('Karte') points at the item you want to work with. You need to replace Karte with the name you gave your map item.

map_get([...],'map_extent') grabs the extent of the item you're pointing at. In this case you're returned a geometry.

Once you get the geometry, the rest is rather easy:

Use y_min, y_max, x_min and x_max followed by the geometry you need the coordinates of to grab said coordinates. Combine min/max and x/y in order to create the fitting coordinate pairs. ||', '|| concatenates these coordinates.

I added the round function since I tried this using a UTM-zone and didn't want unnecessarily long numbers. If you're working with DMS-coordinates, please remove round since it'd probably break the expression.

Erik
  • 16,269
  • 1
  • 24
  • 43