[Qgis-developer] Value relations in QgsExpression

Matthias Kuhn matthias.kuhn at gmx.ch
Mon Jul 28 03:02:50 PDT 2014

Hi Marco,

On 28.07.2014 11:57, Marco Hugentobler wrote:
> Hi
> In QgsVectorLayer, it is possible to define the edittype 'value
> relation' where a key is replaced by a value in a related layer. Now
> I'd like to make a function in QgsExpression that behaves similarly
> and returns the value in the related table.
> My idea is to create a function 'valueRelation( value, layer_id,
> key_field, value_field )' to return that value, where layer_id is the
> id of the related layer, key_file and value_field the column names in
> the related layer.
> One disadvantage of this approach is that if the relation in
> vectorlayer changes, the one in an expression needs to be changed as
> well. On the other hand it can be an advantage in certain situations
> to have a different relation in expression than in vector layer. I
> figured out it would be difficult to take the value relation
> dynamically from vectorlayer, as QgsExpression does not know its
> vectorlayer. A possibility would be to create a special column for the
> current layer id. However that seems not nice and it is too easy to
> forget to set that id when using the expression.
> What are your opinions on that? Are there better ways to accomplish
> the value relation function in QgsExpression?
> Regards,
> Marco
Does this introduce any additional functionality compared to defining a
layer join and using the fields appended to the vector layer be this?

Do you think it would be possible to introduce this via a JOIN syntax in
QgsExpression? This way we would stay closer to SQL standard.

Another possibility I was thinking of was via the relations, with the
possibility to check some fields of a related layer as "hard joined"
which would then be available the same way that JOINED fields are now.


More information about the Qgis-developer mailing list