17.11. Calculatorul vectorial

Note

În această lecție vom vedea cum se vor adăuga noi atribute în stratul vectorial, pe baza unei expresii matematice, cu ajutorul calculatorului vectorial.

We already know how to use the raster calculator to create new raster layers using mathematical expressions. A similar algorithm is available for vector layers, and generates a new layer with the same attributes of the input layer, plus an additional one with the result of the expression entered. The algorithm is called Field calculator and has the following parameters dialog.

../../../_images/field_calculator.png

Note

În versiunile mai noi de Processing, interfața s-a schimbat considerabil, fiind mult mai puternică și mai ușor de utilizat.

Aici sunt câteva exemple de utilizare ale acestui algoritm.

First, let’s calculate the population density of white people in each polygon, which represents a census. We have two fields in the attributes table that we can use for that, namely WHITE and SHAPE_AREA. We just have to divide them and multiply by one million (to have density per square km), so we can use the following formula in the corresponding field

( WHITE / SHAPE_AREA ) * 1000000

Dialogul parametrilor trebuie completați așa cum se arată mai jos.

../../../_images/density1.png

Acest lucru va genera un nou câmp denumit WHITE_DENS

Now let’s calculate the ratio between the MALES and FEMALES fields to create a new one that indicates if male population is numerically predominant over female population.

Introduceți următoarea formulă

"MALES"  /  "FEMALES"

Fereastra parametrilor ar trebui să arate acest lucru, înainte de a apăsa pe butonul OK.

../../../_images/ratio.png

In earlier version, since both fields are of type integer, the result would be truncated to an integer. In this case the formula should be: 1.0 *  "MALES"  /  "FEMALES", to indicate that we want floating point number a result.

We can use conditional functions to have a new field with male or female text strings instead of those ratio value, using the following formula:

CASE WHEN  "MALES" > "FEMALES"  THEN 'male' ELSE 'female' END

Fereastra parametrilor ar trebui să arate acest lucru.

../../../_images/predominance.png

Un calculator de câmpuri python este disponibil în Advanced Python field calculator, care nu va fi detaliat aici

../../../_images/advanced.png