TransWikia.com

Adding bbox of my map with Expression Builder into text field

Geographic Information Systems Asked on December 14, 2020

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.

One Answer

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.

Answered by Erik on December 14, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP