Skip to content

Latest commit

 

History

History
917 lines (723 loc) · 41.3 KB

File metadata and controls

917 lines (723 loc) · 41.3 KB
.. index:: Attribute table

Working with the Attribute Table

The attribute table displays information on features of a selected layer. Each row in the table represents a feature (with or without geometry), and each column contains a particular piece of information about the feature. Features in the table can be searched, selected, moved or even edited.

.. only:: html

   .. contents::
      :local:

.. index:: Non Spatial Attribute Tables, Geometryless Data

Foreword: Spatial and non-spatial tables

QGIS allows you to load spatial and non-spatial layers. This currently includes tables supported by GDAL and delimited text, as well as the PostgreSQL, MS SQL Server, SpatiaLite and Oracle providers. All loaded layers are listed in the :guilabel:`Layers` panel. Whether a layer is spatially enabled or not determines whether you can interact with it on the map.

Non-spatial tables can be browsed and edited using the attribute table view. Furthermore, they can be used for field lookups. For example, you can use columns of a non-spatial table to define attribute values, or a range of values that are allowed, to be added to a specific vector layer during digitizing. Have a closer look at the edit widget in section :ref:`vector_attributes_menu` to find out more.

Introducing the attribute table interface

To open the attribute table for a vector layer, activate the layer by clicking on it in the :ref:`label_legend`. Then, from the main :menuselection:`Layer` menu, choose openTable :menuselection:`Open Attribute Table`. It is also possible to right-click on the layer and choose openTable :menuselection:`Open Attribute Table` from the drop-down menu, or to click on the openTable :guilabel:`Open Attribute Table` button in the Attributes toolbar. If you prefer shortcuts, F6 will open the attribute table. Shift+F6 will open the attribute table filtered to selected features and Ctrl+F6 will open the attribute table filtered to visible features.

This will open a new window that displays the feature attributes for the layer (figure_attributes_table). According to the setting in :menuselection:`Settings --> Options --> Data sources` menu, the attribute table will open in a docked window or a regular window. The total number of features in the layer and the number of currently selected/filtered features are shown in the attribute table title, as well as if the layer is spatially limited.

img/vectorAttributeTable.png

Attribute Table for regions layer

The buttons at the top of the attribute table window provide the following functionality:

Available Tools
Icon Label Purpose Default Shortcut
toggleEditing Toggle editing mode Enable editing functionalities Ctrl+E
multiEdit Toggle multi edit mode Update multiple fields of many features  
saveEdits Save Edits Save current modifications  
refresh Reload the table    
newTableRow :menuselection:`-->` ([1]) Add feature Add new geometryless feature  
:menuselection:`-->` newTableRow Add feature via attribute table Inserts a new empty row in the attribute table to be filled in  
:menuselection:`-->` formSelect Add feature via attribute form Opens the feature attributes form for data entry  
deleteSelectedFeatures Delete selected features Remove selected features from the layer  
editCut Cut selected features to clipboard   Ctrl+X
copySelected Copy selected features to clipboard   Ctrl+C
editPaste Paste features from clipboard Insert new features from copied ones Ctrl+V
expressionSelect Select features using an Expression    
selectAll Select All Select all features in the layer Ctrl+A
invertSelection Invert selection Invert the current selection in the layer Ctrl+R
deselectActiveLayer Deselect all Deselect all features in the current layer Ctrl+Shift+A
filterMap Filter/Select features using form   Ctrl+F
selectedToTop Move selected to top Move selected rows to the top of the table  
panToSelected Pan map to the selected rows   Ctrl+P
zoomToSelected Zoom map to the selected rows   Ctrl+J
newAttribute New field Add a new field to the data source Ctrl+W
deleteAttribute Delete field Remove a field from the data source  
editTable Organize columns Show/hide fields from the attribute table  
calculateField Open field calculator Update field for many features in a row Ctrl+I
conditionalFormatting Conditional formatting Enable table formatting  
dock Dock attribute table Allows to dock/undock the attribute table  
actionRun Actions Lists the actions related to the layer  
[1]Press and hold to select whether to add the feature via the attribute table or form.

Attention!

Depending on the format of the data and the GDAL library built with your QGIS version, some tools may not be available.

Below these buttons is the Quick Field Calculation bar (enabled only in :ref:`edit mode <sec_edit_existing_layer>`), which allows to quickly apply calculations to all or part of the features in the layer. This bar uses the same :ref:`expressions <vector_expressions>` as the calculateField Field Calculator (see :ref:`calculate_fields_values`).

Table view vs Form view

QGIS provides two view modes to easily manipulate data in the attribute table:

You can switch from one mode to the other by clicking the corresponding icon at the bottom right of the dialog.

You can also specify the :guilabel:`Default view` mode at the opening of the attribute table in :menuselection:`Settings --> Options --> Data Sources` menu. It can be 'Remember last view', 'Table view' or 'Form view'.

img/attribute_table_views.png

Attribute table in table view (top) vs form view (bottom)

.. index:: Sort columns, Add actions
   pair: Attributes; Columns

Configuring the columns

Right-click in a column header when in table view to have access to tools that help you control:

Resizing columns widths

Columns width can be set through a right-click on the column header and select either:

A column size can also be changed by dragging the boundary on the right of its heading. The new size of the column is maintained for the layer, and restored at the next opening of the attribute table.

In the :ref:`Data Source Settings <datasources_options>`, you can choose to checkbox :guilabel:`Autosize all columns by default when opening attribute table`, which will make "Autosize All Columns" the default view every time attribute tables are opened in QGIS.

Hiding and organizing columns and enabling actions

By right-clicking in a column header, you can choose to :guilabel:`Hide column` from the attribute table (in "table view" mode). For more advanced controls, press the editTable Organize columns... button from the dialog toolbar or choose :guilabel:`Organize columns...` in a column header contextual menu.

In the new dialog, you can:

  • check/uncheck columns you want to show or hide: a hidden column will disappear from every instance of the attribute table dialog until it is actively restored. It is also possible to:
  • drag-and-drop items to reorder the columns in the attribute table. Note that this change is for the table rendering and does not alter the fields order in the layer datasource
  • add a new virtual :guilabel:`Actions` column that displays in each row a drop-down box or a button list of enabled actions. See :ref:`actions_menu` for more information about actions.
Sorting rows

By default, the table rows order respects the display :ref:`sort order <maptips>`. The rows can also be sorted by any column, by clicking on the column header. A small arrow indicates the sort order (downward pointing means descending values from the top row down, upward pointing means ascending values from the top row down). You can also choose to sort the rows with the :guilabel:`Sort...` option of the column header context menu. The :guilabel:`Configure Attribute Table Sort Order` dialog opens, filled with the current sort order expression. Check unchecked :guilabel:`Defined sort order in attribute table` and edit the expression to suit your needs. E.g., to sort the rows using multiple columns you can write concat(col0, col1). The sort order is set with unchecked :guilabel:`Sort ascending`.

In form view, features identifier can be sorted using the sort :menuselection:`Sort...-->` menu. The order can be set using a custom expression or the display name.

Note that sorting the rows only affects the table rendering and does not alter the features order in the layer datasource.

Tip

Sorting based on columns of different types

Trying to sort an attribute table based on columns of string and numeric types may lead to unexpected result because of the concat("USE", "ID") expression returning string values (i.e., 'Borough105' < 'Borough6'). You can workaround this by using e.g., concat("USE", lpad("ID", 3, 0)) which returns 'Borough105' > 'Borough006'.

.. index:: Conditional formatting

Formatting of table cells using conditions

Conditional formatting settings can be used to highlight in the attribute table features you may want to put a particular focus on, using custom conditions on feature's:

  • geometry (e.g., identifying multi-parts features, small area ones or in a defined map extent...);
  • or field value (e.g., comparing values to a threshold, identifying empty cells, duplicates, ...).

You can enable the conditional formatting panel clicking on conditionalFormatting Conditional formatting button at the top right of the attributes window in table view (not triggered in form view).

The new panel allows user to add new rules to format rendering of radioButtonOn:guilabel:`Field` or radioButtonOff:guilabel:`Full row`. Adding new rule opens a form to define:

  • the name of the rule;
  • a condition using any of the :ref:`expression builder <vector_expressions>` functions;
  • the formatting: it can be chosen from a list of predefined formats or created based on properties like:
    • background and text colors;
    • use of icon;
    • bold, italic, underline, or strikeout;
    • font.
img/attribute_table_conditional_formating.png

Conditional Formatting of an attribute table

.. index::
   pair: Attributes; Selection

Interacting with features in an attribute table

Selecting features

In table view, each row in the attribute table displays the attributes of a unique feature in the layer. Selecting a row selects the feature and likewise, selecting a feature in the map canvas (in case of geometry enabled layer) selects the row in the attribute table. If the set of features selected in the map canvas (or attribute table) is changed, then the selection is also updated in the attribute table (or map canvas) accordingly.

Rows can be selected by clicking on the row number on the left side of the row. Multiple rows can be marked by holding the Ctrl key. A continuous selection can be made by holding the Shift key and clicking on several row headers on the left side of the rows. All rows between the current cursor position and the clicked row are selected. Moving the cursor position in the attribute table, by clicking a cell in the table, does not change the row selection. Changing the selection in the main canvas does not move the cursor position in the attribute table.

In form view of the attribute table, features are by default identified in the left panel by the value of their displayed field (see :ref:`maptips`). This identifier can be replaced using the drop-down list at the top of the panel, either by selecting an existing field or using a custom expression. You can also choose to sort the list of features from the drop-down menu.

Click a value in the left panel to display the feature's attributes in the right one. To select a feature, you need to click inside the square symbol at the left of the identifier. By default, the symbol turns into yellow. Like in the table view, you can perform multiple feature selection using the keyboard combinations previously exposed.

Beyond selecting features with the mouse, you can perform automatic selection based on feature's attribute using tools available in the attribute table toolbar, such as (see section :ref:`automatic_selection` and subsequent for more information and use case):

It is also possible to :ref:`select features using forms <filter_select_form>`.

Filtering features

Once you have selected features in the attribute table, you may want to display only these records in the table. This can be easily done using the :guilabel:`Show Selected Features` item from the drop-down list at the bottom left of the attribute table dialog. This list offers the following filters:

It is also possible to :ref:`filter features using forms <filter_select_form>`.

Note

Filtering records out of the attribute table does not filter features out of the layer; they are simply momentaneously hidden from the table and can be accessed from the map canvas or by removing the filter. For filters that do hide features from the layer, use the :ref:`Query Builder <vector_query_builder>`.

Tip

Update datasource filtering with Show Features Visible on Map

When for performance reasons, features shown in attribute table are spatially limited to the canvas extent at its opening (see :ref:`Data Source Options <tip_table_filtering>` for a how-to), selecting :guilabel:`Show Features Visible on Map` on a new canvas extent updates the spatial restriction.

.. index:: Expression filter

Storing filter expressions

Expressions you use for attribute table filtering can be saved for further calls. When using :guilabel:`Field Filter` or :guilabel:`Advanced Filter (expression)` entries, the expression used is displayed in a text widget in the bottom of the attribute table dialog. Press the handleStoreFilterExpressionUnchecked Save expression with text as name next to the box to save the expression in the project. Pressing the drop-down menu next to the button allows to save the expression with a custom name (:guilabel:`Save expression as...`). Once a saved expression is displayed, the handleStoreFilterExpressionChecked button is triggered and its drop-down menu allows you to :guilabel:`Edit the expression` and name if any, or :guilabel:`Delete stored expression`.

Saved filter expressions are saved in the project and available through the :guilabel:`Stored filter expressions` menu of the attribute table. They are different from the :ref:`user expressions <user_expressions_functions>`, shared by all projects of the active user profile.

Filtering and selecting features using forms

Clicking the filterMap Filter/Select features using form or pressing Ctrl+F will make the attribute table dialog switch to form view and replace each widget with its search variant.

From this point onwards, this tool functionality is similar to the one described in :ref:`select_by_value`, where you can find descriptions of all operators and selecting modes.

img/tableFilteredForm.png

Attribute table filtered by the filter form

When selecting / filtering features from the attribute table, there is a :guilabel:`Filter features` button that allows defining and refining filters. Its use triggers the :guilabel:`Advanced filter (Expression)` option and displays the corresponding filter expression in an editable text widget at the bottom of the form.

If there are already filtered features, you can refine the filter using the drop-down list next to the :guilabel:`Filter features` button. The options are:

To clear the filter, either select the :guilabel:`Show all features` option from the bottom left pull-down menu, or clear the expression and click :guilabel:`Apply` or press Enter.

More actions on features

Users have several possibilities to manipulate feature in an attribute table. Right-click in a cell and you can:

img/copyCellContent.png

Copy cell content button

If you want to use attribute data in external programs (such as Excel, LibreOffice, or a custom web application), select one or more row(s) and use the copySelected Copy selected rows to clipboard button or press Ctrl+C. Moreover, in :menuselection:`Settings --> Options --> Data Sources` menu you can define the format to paste to with the :guilabel:`Copy features as` option. More details at :ref:`datasources_options`.

.. index:: Field Calculator, Derived Fields, Virtual Fields, Fields edit

Editing attribute values

In order to modify data in an attribute table, you should first toggle the layer into edit. Press the toggleEditing Toggle Editing button. Depending on the layer geometry type and the clipboard state, a few more tools are enabled in the attribute table top toolbar.

Editing attribute values can then be done by:

Putting the layer into edit mode will also allow you to editPaste Paste features from clipboard (Ctrl+V) editCut Cut selected rows to clipboard (Ctrl+X) or deleteSelectedFeatures Delete selected features. More details at :ref:`clipboard_feature`.

Using the Field Calculator

The calculateField 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 used to update an existing field, or written to a new field (that can be a :ref:`virtual <virtual_field>` one).

The field calculator is available on any layer that supports edit. When you click on the field calculator icon the dialog opens (see :numref:`figure_field_calculator`). The layer will be put in edit mode (if not already) after the calculation is made.

Based on the :ref:`Expression Builder <expression_builder>` dialog, the field calculator dialog offers a complete interface to define an expression and apply it to an existing or a newly created field. To use the field calculator dialog, you must select whether you want to:

  1. apply calculation on the whole layer or on selected features only
  2. create a new field for the calculation or update an existing one.

You can also access the field calculator by right-clicking on a column header to directly edit that field. The field calculator dialog will open with the :guilabel:`Update existing field` option already checked and the selected column automatically chosen in the field dropdown.

img/fieldcalculator.png

Field Calculator

If you choose to add a new field, you need to enter a field name, a field type (integer, real, date or string) and if needed, the total field length and the field precision. For example, if you choose a field length of 10 and a field precision of 3, it means you have 7 digits before the dot, and 3 digits for the decimal part.

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

  1. Load the shapefile :file:`railroads.shp` in QGIS and press openTable Open Attribute Table.
  2. Click on toggleEditing Toggle editing mode and open the calculateField Field Calculator dialog.
  3. Select the checkbox :guilabel:`Create a new field` checkbox to save the calculations into a new field.
  4. Set :guilabel:`Output field name` to length_km
  5. Select Decimal number (real) as :guilabel:`Output field type`
  6. Set the :guilabel:`Output field length` to 10 and the :guilabel:`Precision` to 3
  7. Double click on $length in the :guilabel:`Geometry` group to add the length of the geometry into the Field calculator expression box (you will begin to see a preview of the output, up to 60 characters, below the expression box updating in real-time as the expression is assembled).
  8. Complete the expression by typing / 1000 in the Field calculator expression box and click :guilabel:`OK`.
  9. You can now find a new :guilabel:`length_km` field in the attribute table.

Creating a Virtual Field

A virtual field is a field based on an expression calculated on the fly, meaning that its value is automatically updated as soon as an underlying parameter changes. The expression applies to all the features in the layer and is set once; you no longer need to recalculate the field each time underlying values change. For example, you may want to use a virtual field if you need area to be evaluated as you digitize features or to automatically calculate a duration between dates that may change (e.g., using now() function).

Creating a virtual field is done through the calculateField :guilabel:`Field calculator` dialog and follows the :ref:`same procedure <vector_field_calculator>` as for regular fields. Simply remember to check the checkbox :guilabel:`Create virtual field` option and use a field type compatible with the data your expression would generate.

Editing a virtual field is done through the sourceFields :guilabel:`Fields` tab of the layer properties dialog (see :ref:`vector_fields_menu`). The expression defining the field is exposed in the :guilabel:`Comment` column, and pressing the expression button next to it opens an expression editor window for update.

Note

Use of Virtual Fields

  • A field can be set virtual only at its creation.
  • Virtual fields are not permanent in the layer attributes, meaning that they're only saved and available in the project file they've been created.

Using the Quick Field Calculation Bar

While Field calculator is always available, the quick field calculation bar on top of the attribute table is only visible if the layer is in edit mode. Thanks to the expression engine, it offers a quicker access to edit an already existing field:

  1. Select the field to update in the drop-down list.
  2. Fill the textbox with a value, an expression you directly write or build using the expression expression button.
  3. Click on :guilabel:`Update All`, :guilabel:`Update Selected` or :guilabel:`Update Filtered` button according to your need.
img/fieldcalculatorbar.png

Quick Field Calculation Bar

.. index:: Multi edit

Editing multiple fields

Unlike the previous tools, multi edit mode allows multiple attributes of different features to be edited simultaneously. When the layer is toggled to edit, multi edit capabilities are accessible:

Note

Unlike the tool from the attribute table, hitting the :menuselection:`Edit --> Modify Attributes of Selected Features` option provides you with a modal dialog to fill attributes changes. Hence, features selection is required before execution.

In order to edit multiple fields in a row:

  1. Select the features you want to edit.

  2. From the attribute table toolbar, click the multiEdit button. This will toggle the dialog to its form view. Feature selection could also be made at this step.

  3. At the right side of the attribute table, fields (and values) of selected features are shown. New widgets appear next to each field allowing for display of the current multi edit state:

    • multiEditMixedValues The field contains different values for selected features. It's shown empty and each feature will keep its original value. You can reset the value of the field from the drop-down list of the widget.
    • multiEditSameValues All selected features have the same value for this field and the value displayed in the form will be kept.
    • multiEditChangedValues The field has been edited and the entered value will be applied to all the selected features. A message appears at the top of the dialog, inviting you to either apply or reset your modification.

    Clicking any of these widgets allows you to either set the current value for the field or reset to original value, meaning that you can roll back changes on a field-by-field basis.

    img/attribute_multiedit.png

    Editing fields of multiple features

  4. Make the changes to the fields you want.

  5. Click on Apply changes in the upper message text or any other feature in the left panel.

Changes will apply to all selected features. If no feature is selected, the whole table is updated with your changes. Modifications are made as a single edit command. So pressing undo Undo will rollback the attribute changes for all selected features at once.

Note

Multi edit mode is only available for auto generated and drag and drop forms (see :ref:`customize_form`); it is not supported by custom ui forms.

Exploring features attributes through the Identify Tool

The identify :ref:`Identify features <identify>` tool can be used to display all attributes of a feature in the map canvas. It is a quick way to view and verify all data without having to search for it in the attribute table.

To use the :guilabel:`Identify features` tool for vector layers, follow these steps:

  1. Select the vector layer in the Layers panel.
  2. Click on the :guilabel:`Identify features` tool in the toolbar or press Ctrl+Shift+I.
  3. Click on a feature in the map view.
../introduction/img/identify_features.png

Identify Results dialog

The :guilabel:`Identify results` panel will display different features information in a tree view. There are two columns in the panel: :guilabel:`Feature` and :guilabel:`Value`. The first item is the name of the layer and its children are its identified feature(s). Each feature is identified by the :ref:`display name <maptips>` field along with its value. Other information about the feature follows:

  • Derived section - those are the information calculated or derived from other information in the layer. For example, the area of a polygon or the length of a line. General information that can be found in this section:

    • Depending on the geometry type, the cartesian measurements of length, perimeter or area in the layer's CRS units. For 3D line vectors, the cartesian line length is available.
    • Depending on the geometry type and if an ellipsoid is set in the :guilabel:`Project Properties` dialog (:menuselection:`General --> Measurements`), ellipsoidal values of length, perimeter, or area using the specified units.
    • The count of geometry parts in the feature and the number of the part clicked.
    • The count of vertices in the feature.
    • Coordinate information, using the project properties :guilabel:`Coordinates display` settings:
      • X and Y coordinate values of the clicked point
      • the number of the closest vertex to the clicked point
      • X and Y coordinate values of the closest vertex (and Z/M if applicable)
      • if you click on a curved segment, the radius of that section is also displayed.
      • if both the vector layer and the project have vertical datums set and they differ, the Z value will be displayed for both datums.
  • Actions: Actions can be added to the identify feature windows. The action is run by clicking on the action label. By default, only one action is added, namely View feature form for editing. You can define more actions in the layer's properties dialog (see :ref:`actions_menu`).

  • Data attributes: This is the list of attribute fields and values for the feature that has been clicked.

    Note

    Links in the feature's attributes are clickable from the :guilabel:`Identify Results` panel and will open in your default web browser.

  • When a vector layer has defined :ref:`relations <vector_relations>`, the :guilabel:`Identify Results` panel can display both referenced and referencing related features. To view these relations, ensure that the :guilabel:`Show relations` option is enabled in the :ref:`Identify Settings <identify_toolbar>`. Available information for each related feature include:

    • the name of the relation and the linked layer
    • the entry in the referenced or referencing field, identifying the feature
    • the activated actions
    • the list of attribute fields and values

    You can expand related features to explore connected records through multiple levels, including many-to-many (n:m) and polymorphic relations. Only nodes you explicitly expand are loaded, preventing excessive nesting.

    To focus on a specific related record, right-click it and choose :guilabel:`Identify Feature`. This re-centers the identify results on the selected feature, starting a new identification tree from it and effectively limiting the visible nesting depth. Features already shown in ancestor nodes are automatically omitted to avoid duplicates or circular relations.