I need to update fields in attribute table of a vector using QGIS. I use field calculator for each field, but i have too many fields (and too many vectors also) and i need to program the task. The code that i'm using for each first field is:
segALD00*(((xmin($geometry) – xmax($geometry))^2+(ymin($geometry) –
ymax($geometry))^2)^0.5)*102.47/longkm
to the last field
segALD23*(((xmin($geometry) – xmax($geometry))^2+(ymin($geometry) –
ymax($geometry))^2)^0.5)*102.47/longkm
Then another vector:
segETH00*(((xmin($geometry) – xmax($geometry))^2+(ymin($geometry) –
ymax($geometry))^2)^0.5)*102.47/longkm
to the last field
segETH23*(((xmin($geometry) – xmax($geometry))^2+(ymin($geometry) –
ymax($geometry))^2)^0.5)*102.47/longkm
How can i code this?
Best Answer
Open Python console and show the editor, and paste the following code.
I suppose that segALD00 is the name of a field which you want to update with a derivative of its own value, and that longkm is another field.
The script defines a local function upd_value, which does the calculation of the new value.