qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.32k stars 2.97k forks source link

Expose layout map_extent while in map canvas #44058

Open antoniolocandro opened 3 years ago

antoniolocandro commented 3 years ago

I don't know if there is another way to do this but for a project I wanted to only label those features that are within the layout print area which you can see when the layout is open and the decoration is enabled (would be great to have an option to have it enable without the layout open also but that's a different request)

image

When I used @map_extent variable it returned the map canvas which is to be expected so I would think a new variable layout_extent would be more appropriate? I got the idea from here https://kartoza.com/en/blog/getting-map-intersection-with-vector-layers-dynamically-in-qgis/

Since it didn't work my workaround was a bit convoluted to go to the layout, add a text box and get the geometry as WKT and convert the label to static to be able to copy the contents, then I could defined the Show label option with Data defined as shown here. use case is not spending time on labels that will not be seen on the final print layout. If there is already a possible way of doing something like this in a simpler way then I will just bang my head on the desk

https://user-images.githubusercontent.com/4627073/124517893-6393c080-dda2-11eb-9743-184e38364d16.mp4

roya0045 commented 3 years ago

And how does that work when you have multiple layouts opened or layouts with multiple maps? The map extent of the layout is specific to the scope of the layout. Accessing the scope of a potential item is hazardous, the closest we have is the getter which resides in a dedicated layout, not the level above. You would need to getter.

antoniolocandro commented 3 years ago

each layout shall have a unique identifier by default an incremental map0...map n that can be manually overridden should solve it, of course a test for manual override to see the same id is not used would also be needed.

In any case I am not talking about showing the dashed magenta line in the map canvas that is another thing that would be useful and I mentioned, I am talking of being able to get the layout extent geometry to use for functions, if you want to avoid issues something like layout_extent("layout_id") this should provide the extent geometry. Technically it is possible right now but very convoluted

For the magenta dashed line you could enable decorations and have a checkbox to turn layout extents on/off, you may want to see something like this for example

image

image

antoniolocandro commented 3 years ago

I would be happy to access the layout extent by item id as mentioned in the Kartoza blog post I referenced

antoniolocandro commented 2 years ago

There is a processing algorithm that allows to get the extent but the idea to have it as a variable is that then more data-driven cartography can be achieved through the use of data-defined fields and geometry generators