3

I have a line layer containing sections of paths. Sections with the same ID (WID) form a hiking trail. Many of these trails are circular routes, which often have access/exit paths starting from a parking lot. I want to create a sort of "route book" using the QGIS Atlas, with the hiking trails (not the individual sections) serving as coverage layers. On each atlas page, I would like to display the length of the main route and the length of the access/exit paths or sub-routes.

I can create the atlas features for the hiking trails using a virtual layer and the ST_Union function (group by WID), but then I cannot access the access/exit paths or sub-routes anymore. How can I display the length of the main route and the sub-routes for each complete hiking trail on each atlas page?

The Linelayer with selection: The Linelayer with selection

The Atlas-Page: The Atlas-Page

8
  • 1
    Would be good to have more information about your data structure or sample data to test. How can you distinguish access/exit paths? Do they have a special attribute value? Then you could use aggretgate functions to group these features and calculate cumulated length.
    – Babel
    Commented Apr 5, 2023 at 15:17
  • of course! I added some information
    – MartinMap
    Commented Apr 5, 2023 at 15:38
  • What code did you use for the length box information?
    – gvanhavre
    Commented Apr 5, 2023 at 15:46
  • This is just a attribute table. The length comes from a virtual field ($length) in the virtual layer. The '-,--' is just a string as "place holder"
    – MartinMap
    Commented Apr 5, 2023 at 15:49
  • If your access paths had a different column name for length (like, laenge2) when merging, wouldn't you get the information straight from the coverage layer?
    – gvanhavre
    Commented Apr 5, 2023 at 16:10

1 Answer 1

6

Assuming your virtual layer uses a query like

SELECT WID, ST_UNION(geometry) AS geometry
FROM
Routen
GROUP BY
WID

i.e. it has the UNIONed geometry and the WID, I would suggest using the virtual layer geometry just for your coverage layer extents, but use the WID in the virtual layer data to lookup the lengths from the original data and return the result in a textbox in your print layout.

Example data:

enter image description here

Virtual layer:

enter image description here

Example expression in textbox to look up main and subroute lengths separately, joined by WID from virtual layer (=atlas coverage layer)

array_to_string(
    aggregate('Routen',
              'array_agg',
              "Category"||': '||"length"||' m',
              "WID"=attribute(@atlas_feature,'WID')
             ),
'\n ')

You can of course modify the expression in so many ways:

  • to only show length instead of "Category"||': '||"length"||' m'
  • add an extra condition to the filter such as AND "Category" = 'Subroute' so that you can have a text box only showing subroute lengths
  • use sum instead of array_agg as the aggregator
  • get total lengths by summing up lengths without the category filter...

Result:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.