Please see Working with Attributes for an updated version of this tutorial.
GIS data has two parts - features and attributes. Attribute Table contains data about each feature. Here I will show you how to carry out some basic operations on the attribute table using Quantum GIS.
The example here contains a point shapefile of populated places around the world. These are from Natural Earth public domain dataset. The task is to find ‘all capital cities in the world that have a population greater than 1000000’.
- Download the dataset and extract the files to a folder on your harddrive.
- Open QGIS. Click on Layer → Add Vector Layer.
- Locate the shapefile 10m_populated_places.shp in your computer and click ‘Open’.
- The data will be displayed in the QGIS Canvas.
- Right-click on the layer name and select ‘Open Attribute Table’.
- Explore the various attributes and their values.
- We are interested in the population of each feature, so the POP_MAX is the field we are looking for. You can click on the field header to sort the column in ascending or descending order.
- Click on ‘Advanced Search’ at the bottom on the attribute table.
- Type in your query as ‘POP_MAX > 1000000’. You can also click on the field value and various operators to form your query. Click OK.
- You will see the selected records highlighted in the attribute table. You can click the ‘Move selection to top’ button on bottom-left to bring all selected records to the top.
- If you look at the map area, the selected records will be highlighted in yellow.
- Now, let’s refine the query to select only those cities which are capitals. The field containing this data is ADM0CAP. In the attribute table, check the box ‘Search selected records only’ and click ‘Advanced search’.
- Type in the query ‘ADM0CAP = 1’. Click OK.
- You can see that the selection changes to highlight only those cities that are both capitals and have population greater than 1000000.
- Now let’s export this selection to a new file. Right click on the layer and select ‘Save selection as...’.
- Browse to appropriate directory and name the output file as ‘10m_large_capital_cities.shp’.
- Once the export is complete, load the layer into QGIS via Layer → Add Vector Layer. Your final map showing all capital cities having a population greater than 1000000 is ready!