0% found this document useful (0 votes)
75 views

Working With Attributes (QGIS3) - QGIS Tutorials and Tips

This tutorial shows how to view attribute data of features in a GIS vector layer in QGIS and perform basic queries on the attributes. The tutorial uses a dataset containing information on populated places worldwide. It demonstrates how to select features that are capital cities with a population over 1 million people and export the results as a new GeoJSON layer. Key steps include opening the attribute table, using expressions to query attributes, selecting matching features, and saving the selection. The skills learned are selecting by expression, using the attributes toolbar, and exporting selected features.

Uploaded by

mp dc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
75 views

Working With Attributes (QGIS3) - QGIS Tutorials and Tips

This tutorial shows how to view attribute data of features in a GIS vector layer in QGIS and perform basic queries on the attributes. The tutorial uses a dataset containing information on populated places worldwide. It demonstrates how to select features that are capital cities with a population over 1 million people and export the results as a new GeoJSON layer. Key steps include opening the attribute table, using expressions to query attributes, selecting matching features, and saving the selection. The skills learned are selecting by expression, using the attributes toolbar, and exporting selected features.

Uploaded by

mp dc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Author

Ujaval Gandhi

Follow @spatialthoughts

Check out more QGIS learning materials, including free full-length QGIS courses from Spatial Thoughts Academy
(https://spatialthoughts.com/resources).

Subscribe to my list

Email address

Subscribe

Change Language

English

Working with Attributes (QGIS3)


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.

Overview of the task


The dataset for this tutorial contains information about populated places of the world. The task is to query and nd all
the capital cities in the World that have a population greater than 1 million and save the resulting subset as a GeoJSON
le.

Other skills you will learn


Select features from a layer using expressions.
Using the Attributes toolbar.
Exporting selected features in a layer.

Get the data


Natural Earth provides a Populated Places (http://www.naturalearthdata.com/downloads/10m-cultural-vectors/10m-pop-
ulated-places/) dataset. Download the simple (less columns) dataset
(http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_populated_places_simple.zip).

For convenience, you may directly download a copy of datasets from the link below:

ne_10m_populated_places_simple.zip (http://www.qgistutorials.com/downloads/ne_10m_populated_places_simple.zip)

Data Source [NATURALEARTH] (../credits.html#naturalearth)

Procedure
1. Locate the ne_10m_populated_places_simple.zip le in the QGIS Browser and expand it. Select the
ne_10m_populated_places_simple.shp le and drag it to the canvas.

2. A new layer ne_10m_populated_places_simple will now be loaded in QGIS and you will see many points represent-
ing 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 View ‣ Toolbars ‣ Attributes Toolbar.

3. Click the Identify button on the Attributes Toolbar. Once the tool is selected, click on any point on the canvas. The as-
sociated attributes of that point will be displayed in a new Identify Results panel. Once you are done exploring at-
tributes of di erent points, you can click the Close button.

4. Rather than viewing the attribute one feature at a time, we can view them all together as a table. Click the Open
Attribute Table button on the Attributes Toolbar. You can also right-click the ne_10m_populated_places_simple layer
and select Open Attribute Table.
5. You can scroll horizontally and locate the pop_max column. This eld contains the population of the associated
place. You can click twice on the eld header to sort the column in descending order.

6. Now we are ready to perform our query on these attributes. QGIS uses SQL-like expressions to perform queries.
Click Select features using an expression button.
7. In the Select By Expression window, expand the Fields and Values section and double-click the pop_max label. You
will notice that it is added to the expression section at the bottom. If you aren’t sure about the eld 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 nd 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 eld and text with single-quotes refer to a string
value.

8. You will notice that some rows in the attribute table are now selected. The label window also changes and shows
the count of selected features.
9. Close the attribute table window and return to the main QGIS window. You will notice that a subset of points is
now rendered in yellow. This is the result of our query and the selected points are the ones having pop_max attrib-
ute value greater than 1000000 .
10. Let’s update our query to include a condition that the place should also be a capital in addition to having a popula-
tion greater than 1 million. To quickly get to the expression editor, you can use the Select Features by Expression
button in the Attributes Toolbar.

11. The eld containing data about capitals is adm0cap. The value 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 Fea-
tures and then Close.
"pop_max" > 1000000 and "adm0cap" = 1

12. Return to the main QGIS window. Now you will see a smaller subset of the points selected. This is the result of the
second query and shows all places from the dataset that are country capitals as well as have population greater
than 1 million.
13. Now we will export the selected features as a new layer. Right-click the ne_10m_populated_places_simple layer and
go to Export ‣ Save Selected Features As…
14. You may choose any format of your liking as the Format. For this exercise, we will choose 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 le.

15. The input data has many columns. You are able to choose only a subset of the original columns for export. Expand
the Select fields to export and their export options section. Click Deselect All and check the name and pop_max
columns. Click OK.
16. A new layer 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.
19 Comments QGIS Tutorials and Tips 🔒 Disqus' Privacy Policy 
1 Login

 Recommend 6 t Tweet f Share Sort by Best

Join the discussion…

LOG IN WITH
OR SIGN UP WITH DISQUS ?

Name

Poonam Verma • a year ago


How can i keep the outline of the world map in this along with the points depicting the
populated capitals of the world?
1△ ▽ • Reply • Share ›

Ujaval Gandhi Mod > Poonam Verma • a year ago


You can download the Admin0-Countries and add it to the map.
https://www.naturalearthdat...
2△ ▽ • Reply • Share ›

Poonam Verma > Ujaval Gandhi • a year ago


Thank you so much for the quick response!
1△ ▽ • Reply • Share ›

Jamal Almuallem • a year ago • edited


Thank you Ujival. Great tutorials. I look forward to see your book on Qgis. It would be an
excellent addition on the market.
1△ ▽ • Reply • Share ›

Kai Reinacher • a year ago


Can you help troubleshooting as well? When I am in the "Select by Expression" window and I
double click on pop max so it appears in the expression box no matter what else I put after it

You might also like