4

I have two shapefile files "A" and "B" loaded in QGIS 3.22.

I would like to use a variable from one shapefile in the field calculator of another shapefile.

For file "A" I would like to use the variables ident, x1, y1, end1x and end1y to calculate a determinant (matrix) if the feature of "B" has the value of ident equal to "A" (B=A), in this case I want to use x2 and y2 from "B" in field calculator within A.

attribute table A

enter image description here

attribute table B

enter image description here

field calculator try enter image description here

expression

if ident@B=ident@B then (x1*end1y*1)+(y1*1*x2)+(end1x*y2*1)-(x2*1*end1y)-(y2*1*x1)-(end1x*y1*1) 

1 Answer 1

6

This expression returns the attribute value from the x2 field of layer B, where layer B's ident is equal to layer A's ident.

attribute( get_feature('B', 'ident', "ident"), 'x2' ) 

See the help pane in the field calculator for a more detailed explanation of the functions.

Note the use of single and double quotes - the second argument of get_feature is a field name and the third argument is a field value, in this case taken from layer A.

For readability of your final expression, you could set the layer B values to variables and call them with the @ operator, like this:

with_variable('x2', attribute(get_feature('B', 'ident', "ident"), 'x2'), with_variable('y2', attribute(get_feature('B', 'ident', "ident"), 'y2'), (x1*end1y*1)+(y1*1*@x2)+(end1x*@y2*1)-(@x2*1*end1y)-(@y2*1*x1)-(end1x*y1*1) )) 
0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.