← All tutorials · GISela

Tutorial 4 of 6

Attribute table, filters and the field calculator

Intermediate 8 min

Sort and edit attributes, filter features with expressions, compute new fields such as density, and join a CSV table by a key.

The attribute table shows one row per feature and one column per field. Select a layer and press T, or choose Layer → Attribute table. It opens below the map.

Sort, select and edit

Click a column heading to sort, click it again to reverse. The button in the first column selects the feature and moves the map to it; Shift adds to the selection. Edit opens all attributes of a feature in a dialog; a double-click on a value edits it in place (Enter saves, Escape cancels). Add field… and Delete field… change the columns; Export CSV downloads the table.

Filters

A filter hides features that do not match an expression. Choose Filter… in the table or Layer → Filter features… and write, for example:

zone = 'residential' AND population > 1000

The filter dialog with the expression and the opened expression help

The map, the feature list, the table and exports by default then only show the matching features. In Town districts, three of six districts match: Seefeld, Moosmatt and Rebhalde. The layer list shows 3 of 6.

The attribute table with three residential districts and the filtered map above

The expression language

Expressions work like SQL or QGIS:

  • text in single quotes ('mixed'), field names as they are or in double quotes ("Name with space");
  • + - * / % ^, || joins text, comparisons = != < <= > >=;
  • AND, OR, NOT, LIKE 'A%', ILIKE, IN ('a', 'b'), IS NULL, BETWEEN 1 AND 3;
  • functions: abs, round, floor, ceil, sqrt, ln, exp, pow, min, max, upper, lower, trim, length, substr, replace, concat, coalesce, if, to_number, to_string and pi;
  • geometry values $area (m²), $length (m), $perimeter (m), $x, $y and $id.

Empty values are NULL: NULL + 1 is NULL, and a comparison with NULL is neither true nor false. Expressions never run JavaScript; an unknown field or function is reported with its position.

Field calculator

Field calculator… writes the result of an expression into a new or existing field. For population per square kilometre:

round(population / ($area / 1000000))

The dialog shows the first five results before you calculate; for Altstadt that is 3650. $area is measured on the WGS 84 ellipsoid, so the result is correct in any coordinate system. Tick Only the selected features to update part of a layer.

Join a CSV table

Join CSV… adds columns from a table to the features whose key matches — for example mayors or school counts per district name. Choose the key field of the layer and the key column of the CSV; numbers are recognised, and the status line says how many features matched and how many did not.

Ready to try it?

Launch GISela →