O :index: atributo da tabela exibe características de uma camada selecionada. Cada linha na tabela representa um recurso do mapa, e cada coluna contém uma determinada parte das informações sobre o recurso. Recursos na tabela podem ser pesquisados, selecionados, movidos ou mesmo editados.
Para abrir a tabela de atributos de uma camada do vetor, fazer a camada ficar ativa clicando sobre ela na área de legenda do mapa. Então, a partir do principal: menu de seleção: menu de Camada, escolha | mActionOpenTable |: menu de seleção: ‘Abrir Tabela de Atributos`. Também é possível fazer um clique direto sobre a camada e escolha | mActionOpenTable |: menu de seleção: ‘Abrir Tabela de Atributos` a partir do menu suspenso, e clique no | mActionOpenTable |: guilabel: botão Abrir Tabela de Atributos na barra de ferramentas.
This will open a new window that displays the feature attributes for the layer (figure_attributes_1). The number of features and the number of selected features are shown in the attribute table title.
Figure Attributes 1:
Attribute Table for regions layer
The buttons at the top of the attribute table window provide the following functionality:
Below these buttons is the Field Calculator bar (enabled only in editing mode),
which allows calculations to be quickly applied to either all or selected features
attributes in the table. This bar uses the same expressions as the
Field Calculator (see Field Calculator).
Dica
Skip WKT geometry
If you want to use attribute data in external programs (such as Excel), use the
Copy selected rows to clipboard button.
You can copy the information without vector geometries if you deactivate
Settings ‣ Options ‣ Data sources menu
Copy geometry in WKT representation from attribute table.
Each selected row in the attribute table displays the attributes of a selected feature in the layer. If the set of features selected in the main window is changed, the selection is also updated in the attribute table. Likewise, if the set of rows selected in the attribute table is changed, the set of features selected in the main window will be updated.
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.
The table can 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).
For a simple search by attributes on only one column, choose the Column filter ‣ from the menu in the bottom left corner. Select the field (column) on which the search should be performed from the drop-down menu, and hit the [Apply] button. Then, only the matching features are shown in the attribute table.
To make a selection, you have to use the Select features using an Expression
icon on top of the attribute table.
Select features using an Expression allows you
to define a subset of a table using a Function List like in the
Field Calculator (see Field Calculator).
The query result can then be saved as a new vector layer.
For example, if you want to find regions that are boroughs from regions.shp
of the QGIS sample data, you have to open the Fields and Values menu
and choose the field that you want to query. Double-click the field ‘TYPE_2’ and also
[Load all unique values] . From the list, choose and double-click ‘Borough’.
In the Expression field, the following query appears:
"TYPE_2" = 'Borough'
Here you can also use the Function list ‣ Recent (Selection) to make a selection that you used before. The expression builder remembers the last 20 used expressions.
The matching rows will be selected, and the total number of matching rows will appear in the title bar of the attribute table, as well as in the status bar of the main window. For searches that display only selected features on the map, use the Query Builder described in section Query Builder.
To show selected records only, use Show Selected Features from the menu at the bottom left. See next section for more information on filter feature.
The field calculator bar allows you to make calculations on the selected rows only. For example, you can alter the number of the ID field of the layer regions.shp with the expression
ID+5
as shown in figure_attributes_1 .
At the bottom of the attribute table, you have a dropdown list of different filter:
Mostra feições selecionadas;
The first four are self explanatory, the two last are expression filters. Field Filter allows user to choose a column name in the list and add a simple form to the right of the drop-down list to filter with a like expression parameter. This filter will create an expression filter as an Advanced filter. The last kind of filter will open an expression window, see Expressões for more information.
By default the attribute window displays a table layout. In some case one should prefer to use a form layout to help edit some features more easily.
You can switch to form layout by clicking in the bottom right, on
and switch back to table layout with
.
To zoom into a feature, without having to select it, right-click on the feature you want to zoom in, within the attribute table, and select Zoom to feature.
The selected features can be saved as any OGR-supported vector format and
also transformed into another coordinate reference system (CRS). Just open
the right mouse menu of the layer and click on Save
as to define the name of the output file, its format and CRS (see section
Layers Panel). To save the selection ensure that the
Save only selected features is selected.
It is also possible to specify OGR creation options within the dialog.
Features that are on the clipboard may be pasted into a new layer. To do this, first make a layer editable. Select some features, copy them to the clipboard, and then paste them into a new layer using Edit ‣ Paste Features as and choosing New vector layer or New memory layer.
This applies to features selected and copied within QGIS and also to features from another source defined using well-known text (WKT).
The 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.
A virtual field is a field based on an expression calculated on the fly, meaning that its value is automatically updated as soon as the underlying parameter changes. The expression 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).
Nota
Use of Virtual Fields
The field calculator is available on any layer that supports edit. When you click on the field calculator icon the dialog opens (see figure_attributes_2). 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 in edit mode.
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], [Update Selected] or [Update Filtered] button according to your need.
Based on the 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 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 2:
Field Calculator
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_2). 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:
QGIS allows you also to load non-spatial tables. This currently includes tables
supported by OGR and delimited text, as well as the PostgreSQL, MSSQL and Oracle provider.
The tables can be used for field lookups or just generally browsed and edited using the table
view. When you load the table, you will see it in the legend field. It can be
opened with the Open Attribute Table tool and
is then editable like any other layer attribute table.
As an example, you can use columns of the 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 Menu campos to find out more.
You can enable the conditional formatting panel clicking on
at the top right of the attributes window in table
view (not available in form view).
The new panel allows user to add new rules for conditional formatting of field or full row in regard of the expression on field. Adding new rule open a form to define:
Figure Attributes 3:
Conditional Formatting of an attribute table
Relations are a technique often used in databases. The concept is, that features (rows) of different layers (tables) can belong to each other.
As an example you have a layer with all regions of alaska (polygon) which provides some attributes about its name and region type and a unique id (which acts as primary key).
Then you get another point layer or table with information about airports that are located in the regions and you also want to keep track of these. If you want to add them to the region layer, you need to create a one to many relation using foreign keys, because there are several airports in most regions.
Figure Relations 1:
Alaska region with airports
In addition to the already existing attributes in the airports attribute table another field fk_region which acts as a foreign key (if you have a database, you will probably want to define a constraint on it).
This field fk_region will always contain an id of a region. It can be seen like a pointer to the region it belongs to. And you can design a custom edit form for the editing and QGIS takes care about the setup. It works with different providers (so you can also use it with shape and csv files) and all you have to do is to tell QGIS the relations between your tables.
QGIS makes no difference between a table and a vector layer. Basically, a vector layer is a table with a geometry. So can add your table as a vector layer. To demonstrate you can load the ‘region’ shapefile (with geometries) and the ‘airport’ csv table (without geometries) and a foreign key (fk_region) to the layer region. This means, that each airport belongs to exactly one region while each region can have any number of airports (a typical one to many relation).
The first thing we are going to do is to let QGIS know about the relations between the layer. This is done in Project ‣ Project Properties. Open the Relations menu and click on Add.
Figure Relations 2:
Relation Manager
Now that QGIS knows about the relation, it will be used to improve the forms it generates. As we did not change the default form method (autogenerated) it will just add a new widget in our form. So let’s select the layer region in the legend and use the identify tool. Depending on your settings, the form might open directly or you will have to choose to open it in the identification dialog under actions.
Figure Relations 3:
Identification dialog regions with relation to airports
As you can see, the airports assigned to this particular region are all shown in a table. And there are also some buttons available. Let’s review them shortly
If you work on the airport table, a new widget type is available which lets you embed the feature form of the referenced region on the feature form of the airports. It can be used when you open the layer properties of the airports table, switch to the Fields menu and change the widget type of the foreign key field ‘fk_region’ to Relation Reference.
If you look at the feature dialog now, you will see, that the form of the region is embedded inside the airports form and will even have a combobox, which allows you to assign the current airport to another region.
Figure Relations 4:
Identification dialog airport with relation to regions