Importante

Translation is a community effort you can join. This page is currently translated at 68.75%.

17.11. Calculadora vetorial

Nota

Nesta lição, veremos como adicionar novos atributos a uma camada vetorial baseado em uma expressão matemática, usando a calculadora vetorial.

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

Nota

Nas versões mais recentes do Processamento, a interface mudou consideravelmente, está mais poderosa e fácil de usar.

Aqui estão alguns exemplos de utilização desse algoritmo.

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

O diálogo de parâmetros deve ser preenchido como mostrado abaixo.

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

This will generate a new field named WHITE_DENS

Agora vamos calcular a proporção entre os campos “MASCULINOS” e “FEMININOS” para criar um novo que indique que a população masculina é numericamente predominante sobre a população feminina.

Entre a fórmula seguinte

"MALES" / "FEMALES"

Desta vez, a janela de parâmetros deve ficar assim antes de pressionar o botão 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.

Podemos utilizar funções condicionais para ter um novo campo com “macho” ou “fêmea” em vez desses valores de proporção, utilizando a seguinte fórmula:

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

A janela de parâmetros deve ser parecida com esta.

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

Uma calculadora de campo python está disponível em Calculadora de campo avançada Python,que não será detalhada aqui.

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