Hi Matthias

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.

That's a good idea, I also think JOIN syntax is better.
The return of a JOIN operation is probably a tuple, so by using that as a QVariant, it might be possible to use something like 'JOIN( layer_id) ON (fieldA = fieldB).$attribute'

>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.

Would that basically be a join limited to certain attributes or would the handling be totally different to the layer join mechanism?

Regards,
Marco

On 28.07.2014 12:02, Matthias Kuhn wrote:
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.

Regards,
Matthias


--
Dr. Marco Hugentobler
Sourcepole -  Linux & Open Source Solutions
Weberstrasse 5, CH-8004 Zürich, Switzerland
[email protected] http://www.sourcepole.ch
Technical Advisor QGIS Project Steering Committee

_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer

Reply via email to