.

Calculatorul Câmpurilor

The mActionCalculateField Field Calculator button in the attribute table allows you to perform calculations on the basis of existing attribute values or defined functions, for instance, to calculate length or area of geometry features. The results can be written to a new attribute field, a virtual field, or they can be used to update values in an existing field.

Tip

Câmpuri Virtuale

  • Câmpurile virtuale nu sunt permanente și nu sunt salvate.

  • Un câmp poate fi făcut virtual la momentul creării lui.

The field calculator is now available on any layer that supports edit. When you click on the field calculator icon the dialog opens (see figure_attributes_3). If the layer is not in edit mode, a warning is displayed and using the field calculator will cause the layer to be put in edit mode before the calculation is made.

The quick field calculation bar on top of the attribute table is only visible if the layer is editable.

In quick field calculation bar, you first select the existing field name then open the expression dialog to create your expression or write it directly in the field then click on Update All button.

Fila expresiilor

In the field calculator dialog, you first must select whether you want to only update selected features, create a new attribute field where the results of the calculation will be added or update an existing field.

Figure Attributes 3:

../../../_images/fieldcalculator.png

Calculatorul Câmpurilor nix

If you choose to add a new field, you need to enter a field name, a field type (integer, real or string), the total field width, and the field precision (see figure_attributes_3). For example, if you choose a field width of 10 and a field precision of 3, it means you have 6 digits before the dot, then the dot and another 3 digits for the precision.

A short example illustrates how field calculator works when using the Expression tab. We want to calculate the length in km of the railroads layer from the QGIS sample dataset:

  1. Load the shapefile railroads.shp in QGIS and press mActionOpenTable Open Attribute Table.
  2. Clic pe mActionToggleEditing Toggle editing mode, apoi deschideți dialogul mActionCalculateField Field Calculator.

  3. Selectați caseta de bifare checkbox Create a new field pentru a salva calculele într-un nou câmp.

  4. Add length as Output field name and real as Output field type, and define Output field width to be 10 and Precision, 3.
  5. Acum, faceți dublu clic pe funcția $length din grupul Geometry pentru a-l adăuga în câmpul calculatorului de expresii.

  6. Completați expresia introducând ‘’/ 1000’’ în caseta de expresii a Calculatorului de Câmpuri, și făcând clic pe [Ok].

  7. Acum, puteți găsi noul câmp length în tabelul de atribute.

Funcțiile disponibile sunt enumerate în capitolul Expresii.

Fila Editorului de Funcții

With the Function Editor you are able to define your own Python custom functions in a comfortable way. The function editor will create new Python files in qgis2pythonexpressions and will auto load all functions defined when starting QGIS. Be aware that new functions are only saved in the expressions folder and not in the project file. If you have a project that uses one of your custom functions you will need to also share the .py file in the expressions folder.

Here’s a short example on how to create your own functions:

@qgsfunction(args="auto", group='Custom')
def myfunc(value1, value2 feature, parent):
    pass

The short example creates a function ‘myfunc’ that will give you a function with two values. When using the args=’auto’ function argument the number of function arguments required will be calculated by the number of arguments the function has been defined with in Python (minus 2 - feature, and parent).

This function then can be used with the following expression:

myfunc('test1', 'test2')

Funcția va fi implementată în Funcțiile ‘Personalizate’ ale filei Expresie, după utilizarea butonului Run Script.

Mai multe informații despre crearea de cod Python pot fi găsite la http://www.qgis.org/html/en/docs/pyqgis_developer_cookbook/index.html.

The function editor is not only limited to working with the field calculator, it can be found whenever you work with expressions. See also Expresii.