QGIS – Practical 2

Attribute Queries

-Vector layers in GIS have two parts – features (each geographical element in the layer is a feature) and attributes (tabular information about each of the features, which are stored in what’s called the attribute table). You will carry out some basic operations on the attribute table using QGIS. Using the layer peru_highway, the task is to find all tertiary roads which are one-way in the Peru road network.

-Right-click on the layer name and select Open Attribute Table.

-We are interested in the type of each feature, so TYPE is one of the fields we are looking for and the other is ONEWAY – it has information whether a road is one-way or not.

(Note: Should you wish, you can click on the field header to sort the column in ascending or descending order.)

-From the Attribute table menu, select the option to Select features using an expression

(Note: You can hover your mouse of the various menu options to see what they do.)

-In the Select by expression window, we will build the expression to select all tertiary roads that are also one way. To build the expression:
1. Click the left bracket [(] button to add it to the Expression panel.
2. In the Logic panel in the middle, expand the Fields and Values options by clicking the plus icon next to it and double click TYPE to add it to the Expression panel.
3. Click the equals [=] button to add that to the Expression panel.
4. With TYPE selected from Fields and Values, click the button in the bottom right next to Load values for “all unique”. Scroll down and double click the value “tertiary” to add it to the Expression panel.
5. Click the right bracket [)] button to add it to the Expression panel.
6. In the Logic panel in the middle, expand the Operators options by clicking the plus icon next to it and double click “AND” to add that to the Expression panel.
7. Click the left bracket [(] button to add it to the Expression panel.
8. In the Logic panel in the middle, in Fields and values, double click ONEWAY to add it to the Expression panel.
9. Click the equals [=] button to add that to the Expression panel.
10. With ONEWAY selected from Fields and Values, click the button in the bottom right next to Load values for “all unique”. Scroll down and double click the value “yes” to add it to the Expression panel.
11. Click the right bracket [)] button to add it to the Expression panel.

With that, you will have constructed the following expression:
(“TYPE” = ‘tertiary’) AND (“ONEWAY” = ‘yes’)

If your expression matches this, click Select to select the features that match the expression, or delete the expression and try again.

(Note: You can also type the expression into the Expression panel, but it must be EXACT)

(Note: You may wish to expand the Select by expression window to better see the selection options.)

-After the selection operation is complete, click Close to close the Select by expression window. You should see a number next to “selected” in the top of the Attribute table window. You may also select the option to Move selection to top from the Attribute table window to see the selected records.

-If you look at the map, you may also see the selected features, which will be highlighted in yellow by default.

(Note: It may be difficult to see the highlighted features, in which case, you may wish to switch some layers off to better see them. Should you not see them, but it says in the attribute table that they are selected, do not worry, as they are selected.)

-Now let’s export this selection to a new file. Right click on the layer and select “Save as”.

-In the Save vector layer as window, be sure to tick the box next to Save only selected features and Add saved file to map, to add it to your map after its been created. Click Browse to navigate to an appropriate directory and name the output file as tertiary_oneway_roads.shp and click Save, then click OK.

-The new layer should automatically be added to the map and you should be able to see the concentration of one-way tertiary roads is along the coastline of Peru.

(Note: You may need to change the symbology to see the layer properly or turn off some layers)

QGIS – Practical 2

Leave a Reply

Your email address will not be published. Required fields are marked *