0

Status bar in QGIS can display min/max of x/y for extents of the map view when panning and zooming. How can these values be extracted and used in expressions? The manual’s expression page doesn’t seem to have variables for current map view extents.

2
  • Welcome to GIS.SE. You can use the python console with this command to extract the bounds of the map extent: extent = iface.mapCanvas().extent() – swiss_knight Apr 18 '20 at 22:07
  • Thank you. Can this method be used in label creation? – Россарх Apr 18 '20 at 22:13
4

Do you mean the extent of the canvas (the view in the main window)?

This can be accessed using the @map_extent variable in Expression Builder which returns a polygon of the current canvas map extent.

You can then use min_x(), min_y() etc. to extract bounding box coordinates for use in your labels, or to guide your label placement using data defined override.

See below for an example of labels that update based on the map canvas extent. The expression uses min_x(@map_extent) and min_y(@map_extent) and then the distance from the point $geometry to the SW corner of the canvas (make_point() of the min_x/min_y values).

enter image description here

1
  • Marvellous! I used z_max(@map_extent) ≶ # and it’s working great. For the record, the order in the variable is z_min(), which is what you might want to change to in your answer. – Россарх Apr 20 '20 at 16:33

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.