GIS data has two parts - features and attributes. Attributes are structured data about each feature. This tutorial shows how to view the attributes of a GIS vector layer and do basic queries on them in QGIS.
The dataset for this tutorial contains information about populated places of the world. The task is to query and find all the capital cities in the world that have a population greater than 1 million and save the resulting subset as a GeoJSON file.
Natural Earth provides a Populated Places dataset. Download the simple (less columns) dataset
For convenience, you may directly download a copy of datasets from the link below:
ne_10m_populated_places_simple.zip
Data Source [NATURALEARTH]
ne_10m_populated_places_simple.zip
file in the QGIS Browser and expand it. Select the ne_10m_populated_places_simple.shp
file and drag it to the canvas.ne_10m_populated_places_simple
will now be loaded in QGIS and you will see many points representing the populated places of the world. The default view in the QGIS canvas shows the geometry of the GIS layer. Each point also has associated attributes. Let’s view them. Locate the Attributes Toolbar. This toolbar contains many useful tools to inspect, view, select, and modify attributes of a layer.Note
If you do not see the toolbar, you can enable it from
ne_10m_populated_places_simple
layer and select Open Attribute Table.pop_max
label. You will notice that it is added to the expression section at the bottom. If you aren’t sure about the field values, you can click the All Unique button to see what the attribute values are present in the dataset. For this exercise, we are looking to find all features that have a population greater than 1 million. So complete the expression as below and click Select Features and then Close."pop_max" > 1000000
Note
In the QGIS Expression engine, text with double-quotes refers to a field and text with single-quotes refer to a string value.
pop_max
attribute value greater than 1000000
.1
indicates that the place is a capital. We can add this criteria to our previous expression using the and operator. Enter the expression as below and click Select features and then Close."pop_max" > 1000000 and "adm0cap" = 1
ne_10m_populated_places_simple
layer and go to GeoJSON
. GeoJSON is a text-based format that is used widely in web mapping. Click the ... button next to File name and enter populated_capitals.geojson
as the output file.name
and pop_max
columns. Click OK.populated_capitals
will be loaded in QGIS. You can un-check the ne_10m_populated_places_simple
layer to hide it and view the points from the newly exported layer.This work is licensed under a Creative Commons Attribution 4.0 International License