TransWikia.com

QGIS 3.18: Listing visible features in print composer

Geographic Information Systems Asked by Szymon Piotr Jerzy Czwart on June 16, 2021

I’m trying to achieve auto-listing of features visible (ie rendered and in Map’s extents) in a text field rendered as HTML. My idea is:

  1. Adding attribute’s table to print composer, setting it to show only features visible (this would be just good enough),
    but I have to format it kinda in this way (ie all values should go as a into cell labeled as Befundnummer):

enter image description here

  1. Getting all the values from said table into the concatenated string and importing it to the text field with some cleaver expression like those I already have for map scale and coordinate sys:
<td>Maßstab:</td><td>1:[%round(map_get(item_variables('Mapa 1'), 'map_scale'),0)%]</td>
</tr>
<tr>
<td>Koordinatensystem:</td><td>[% @project_crs %]</td>
</tr>
  1. Hiding the attribute table so it doesn’t interfere with the final export.

Is this possible without writing any elaborate functions?

//Edit: I’m adding some more info about data structure
Table of attributes of that layer is quite simple, as it only has 2 columns, ID (the befund number, integer) and a class (type of feature, string data).

enter image description here

I’m adding a table of attributes in print composer, linking it with polygonal layer with those Befunds. After checking box at ‘show only features visible on map’ and getting rid of header I’m pretty much good.
enter image description here

And table object is rendered like that with constant update:

enter image description here

The point is, that I’d like to fit it into the label mentioned above, optimally as a self-updating string that would resemble ‘id’, ‘id’, ‘id’. At this point I’m thinking about really painful workaround (ie splitting the table into one-cell-frames and modify integers to have commas)…

One Answer

You plan to use the attribute table in the layout and then extract it content in a text field, it is smart but I think it will not be easy to do as features in your layout are very independent.

The solution I proposed is based on an expression that will calculate directly the result you want. The result could be integrated in a text field as you have done for Maßstab or Koordinatensystem.

This process is doing an intersection joining "on the fly" so you need to have the same CRS for atlas layer and target layer. If you don't then you have to add an expression to handle it and it is getting even more complicated.

First to extract features that cross the current atlas feature :

array_to_string(
  aggregate(
    'poly plan 2', 
    aggregate:='array_agg', 
    expression:="id", 
    filter:= intersects( 
      @atlas_geometry,
      $geometry
    )
  )
)

To extract features that cross the map extent in your layout, then you have to change the geometry used by the intersect. The CRS need to be the same in your target layer and in the map integrated in your layout.

array_to_string(
  aggregate(
    'poly plan 2', 
    aggregate:='array_agg', 
    expression:="id", 
    filter:= intersects(
      map_get(item_variables('Mapa 1'),'map_extent'),
      $geometry
    )
  )
)

Note : If your map item in the layout have another name, then you must change the text Mapa 1.

Answered by Corentin Lemaitre on June 16, 2021

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