2

I have a CSV-Layer with multiple columns (e.g. ID, owner_name) and well-known text data to contain information about polygons. One ID can be owned by to owners which would cause the feature to appear twice in the attribute table. I further created a virtual field which concentrates all owners into it.

The code of the virtual field looks like this

concatenate("owner_name" ,group_by:= "ID",concatenator:=', ',order_by:= "owner_name")

This results in a attribute table as follows

ID owner_name all_owners [virtual field]
1 Simon Simon
2 Erica Erica, Peter
2 Peter Erica, Peter
3 Simon Simon

Now I want to the atlas to iterate through all unique values in the all_owners column. In this case:

  1. Simon
  2. Erica, Peter

Important: I do not want to create new (static) layers and use the dissolve function as the data in the "CSV"-Layer might get changed later on and everything shall get updated.

Note: The answer to this similar question (look here) does not work, as Virtual Layers cannot get access to virtual fields as far as I tried.

gissurfer
  • 75
  • 7

1 Answers1

1

What I would do, is create a virtual layer that selects the distinct values of the "all_owners" column and join the geom's to that table. You could then build the atlas on that derivative virtual layer.

This is really doing in qgis with virtual layers what I would do permanently in postgres but I think would work.

I don't work a ton with virtual layers but based on my understanding, they would update automatically when the source data is updated.

This is not pulling from a csv with a virtual column but you should be able to import your csv layer and access your virtual column by name.

The query i just tested was:

enter image description here

Hugh_Kelley
  • 747
  • 1
  • 6
  • 19
  • Thanks for your answer. However I couldn't make that work: How Do select distinct values from a virtual field? The list of distinct values in the virtual layer would be enough as I can show the features of the original layer using a rule-based style pointing to the "atlas_pagename" – gissurfer Mar 23 '23 at 15:27
  • start by just select * from my_csv_layer and check that the virtual layer was pulled through and then just switch to selecting distinct column_name – Hugh_Kelley Mar 23 '23 at 15:30
  • This does not work. I get a promt: "Query preparation error on PRAGMA table_info(_tview): no such column: all_owners"

    I guess this happens because the virtual layer accesses the original CSV-file (which is not containing the virtual field) and not the imported CSV-layer (which contains the virtual field)

    – gissurfer Mar 23 '23 at 15:37
  • are you "adding" the csv file or "importing" the layer – Hugh_Kelley Mar 23 '23 at 16:57
  • I am "importing" the layer. It also shows me the field name as a hint/autocomplete when beginning to type. However the above error is shown as soon as I want to add the layer. With static fields it works just fine. Is there maybe another work around to achieve the outcome described in the question? – gissurfer Mar 24 '23 at 07:56
  • 1
    Can you edit your question to include the code that creates your virtual field? I'd recommend taking this off s/o and joining then emailing qgis-user@lists.osgeo.org. you can join here https://lists.osgeo.org/mailman/listinfo/qgis-user – Hugh_Kelley Mar 24 '23 at 12:24
  • Thanks for the hint. I edited the question as you suggested. – gissurfer Mar 24 '23 at 15:57
  • I was not able to solve this issue yet. Also the signhup to the mailinglist, was somehow not succesful (I tried over the course of the last weeks, but did not receive any info back). Do you have any advice for me? – gissurfer Apr 06 '23 at 10:01