1

Intro

I am working on a QGIS project with two layers: a Parent Layer (e.g., Soil Class) and a Child Layer (e.g., Polygons). This is a One-to-Many Relationship: --> Each polygon is assigned to exactly one soil class. Each soil class can be associated with multiple polygons. Here is what I have done so far:

  • Configured the relationship in Project Properties → Relations, linking the key fields (e.g., soil_class_id) in the Soil Class layer with those in the Polygons layer.
  • Added a Relation Reference Widget to the attribute form of the Polygons layer for editing related records

Example

Soil Class Layer (Parent Layer):

soil_class_id soil_class_name
1 Clay
2 Sand
3 Loam

Polygons Layer (Child Layer):

polygon_id soil_class_id area (m2)
101 1 500
102 2 300
103 1 400
104 3 600

results layer after field calculator:

polygon_id soil_class_id area (m2) reference using the relation object itself
101 1 500 Clay
102 2 300 Sand
103 1 400 Clay
104 3 600 Loam

My Question:

How can I display related polygons directly in the attribute table of the Parent Layer (Soil Class), using the relation reference? (Instead of using get_attribute.)

I understand that it’s possible to show a relation column in the attribute form using this expression. However, I am looking for a more efficient solution, especially since I am working with large datasets (more than 10,000 entries) and need a fast processing method.

asked Jan 15 at 11:02
5
  • If you have several orders per customer: how do you want to represent these in the customer's attribute table? As an array? A text string? Can you share your project file with all settings and sample data to see exactly how you did the setup? Not so clear from the description. Commented Jan 15 at 13:18
  • 1
    You might find the relation_aggregate function useful, but as @Babel mentions, you will need to decide how to handle the aggregated data. Commented Jan 15 at 13:35
  • hi, i changed my question. @Babel Commented Jan 16 at 13:55
  • hi, i changed my question. @Matt Commented Jan 16 at 13:56
  • You still did not provide your setting, what would be crucial to understand what went wrong. See, however, the answer how to do setup. Commented Jan 16 at 14:45

1 Answer 1

1

Short answer

Make settings correctly for your relation, than you can use the function represent_value() with the fieldname: represent_value ("soil_class_id")

Detailed answer

Setup everything so that in the polygon layer's attribute table, you can choose directly soil class name. As you don't provide details about how you made the settings, here a step by step description with screenshots:

  1. Define relation in the project properties. Link soil_class_id from SoilCLass Layer to soil_class_id from polygon layer:

    enter image description here

  2. In the polygon's layer properties, go to to Attribute Forms and select soil_class_id field. Set Widget Type to Relation Reference, as display expression select soil_class_name and select the relation you have defined before. enter image description here

  3. Now, if you open the attribute table, your numbers in the field soil_class_id are gone and instead of it, you have the soil class name displayed and you have a dropdown menu to select from the soil class names defined in your Soil Class table/layer.

    enter image description here

The Field soil_class_id is still an integer field, but it is displayed as a textstring with the name of the corresponding entry in the SoilClass layer:

enter image description here

  1. To generate the textstring from the related layer/table for each numer in soil_class_id field, simply use the function represent_value() with the fieldname: represent_value ("soil_class_id")

    enter image description here

answered Jan 16 at 14:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.