How to load and interact with data in QGIS
In recent years, QGIS has become the most popular open source desktop geographic information system (GIS) software. Some people are using it just to view and query data, while others are using it for much deeper analyses. Maybe you are an ecologist or a town planner needing to use GIS as part of your job. Maybe you have a background in proprietary GIS software and want to migrate some of your common workflows to open source. Or maybe you are a student that needs to use GIS for a project.
At the core of any GIS is data. Without it, we cannot create maps or perform spatial analysis. If you are familiar with GIS, then you will already know that we often work with vector data, namely points, lines, polygons, and raster data, as pixels. Vector and raster data are the core data types that we use in a GIS. However, text files, databases, and web services can also be integrated into GIS. We can use a location associated with a file (such as a coordinate), or we can perform joins to extend or spatially enable our existing data.
This article is taken from the book Learn QGIS – Fourth Edition by Anita Graser and Andrew Cutts. By the end of the book, you will have become proficient in geospatial analysis using QGIS and Python. To follow along with the examples implemented in this article, you can download the code from the book’s GitHub repository.
In this article, we will first briefly have a look at the data formats supported by QGIS 3.4. We will then learn how to load and interact with data within QGIS.
QGIS supports many GIS data formats. It makes use of the OGR library for vector data and the GDAL library for raster data. Shapefiles are the most common form of vector data today, and QGIS supports this format. Similarly, GeoTIFF are probably the most common form of raster data, and QGIS also supports these.
3 has chosen GeoPackage as its default format. This is an open format, unlike
the Shapefile, which is proprietary. GeoPackage also supports rasters. It is
built on a
SpatiaLite database, has no file size limitations,
and works as one file. The format was developed by the Open
Geospatial Consortium and is increasingly being adopted by
organizations around the world. A GeoPackage has a
.gpkg extension, which unlike the Shapefile
has several extensions.
We are going to start by loading data into QGIS 3.4. You may have some of your own data that you wish to use, but all of the techniques are applicable to any GIS data you have. We will use the QGIS sample data for these examples.
the QGIS sample data from QGIS
download data page and
look for the
qgis_sample_data.zip file. Download and extract this data to a folder on
Getting data into QGIS
Loading data into QGIS can be done in several ways. The three most common ways are as follows:
- You can drag data directly from a folder straight into the map.
- You can drag data from the browser panel onto the map.
- You can
Add Layerand choose what type of layer to add.
In the following screenshot, we are choosing to load a Vector Layer, which can also be doneusing the Ctrl + Shift + V shortcut:
choosing this method, the
Data Source Manager window will appear, with
Vector highlighted, as follows:
on the ellipsis for
Vector Dataset(s) and navigate to the layer you wish to
load. In the following example, the
alaska Shapefile is selected. You can load
more than one layer at the same time by holding down the Ctrl button and clicking on multiple files:
you then click the
Add button at the bottom of the
Manager window, the
Mapwindow as well as the
Data Source Managerwindow will remain open, and you can also load other layers. Close the window and your Shapefile will appear in the map, as follows:
In the next section, we will look at how to interact with the data to zoom in and inspect its attributes.
Interacting with data
When you loaded the Alaska layer, you probably noticed that the data appeared as a relatively small object. In this section, we will cover some of the basic interactions we can perform with data. Let’s start with zooming in.
Later, we will show you how to zoom in on a layer to look at it in more detail. But first, let’s remind ourselves of the project and navigation toolbar:
These tools are the workhorse of the GIS. They allow us to move around, inspect, measure, and select data. All are critical in any GIS, and if you have used mapping software before, you should be familiar with them.
Start by clicking on the zoom-in icon (a magnifying glass icon with a + in it). When this option is selected, it will be highlighted in a different shade, just like any other interactive button in QGIS. This is demonstrated in the following screenshot:
Left-click and draw around the Alaska shape. The map window will quickly refresh around the shape you have drawn. You can then click on the white hand to pan around the map to adjust to your preference. You can also use the scroll button on your mouse to zoom in and out of the map. Some of these navigational tools are grayed out; this is because a setting or event has not happened yet to enable them.
The bookmark tool is shown in the following screenshot and highlighted in the red box:
Spatial Bookmarks allow you to save your current map
extent. This means that you can return to this bookmarked view later, or in
another project. In the preceding example, I have created a bookmark
Data attributes toolbar
Here is the attributes toolbar:
This contains tools to inspect, measure, and select data, among other tools. In order to be able to use these tools, we need to have a layer selected in the layers window. Left-click once on the Alaska layer and this toolbar will have all of its options available.
Inspecting the data
on the blue
in the attributes toolbar and then click on the layer in the map.
This will display the feature attributes in a new panel, which will
dock by default. Like all panels, you can move them around and resize as
needed. Your QGIS project should look similar to the following diagram:
new panel is called identify
results. In this case,
attributes include a
Name, and an
The measure tool does not require a layer to be selected in the layer panel in order for it to work. This means that it is independent of a layer(s). The measure tool can measure length, area, or angle, and you can use the drop-down button next to the tool to select the required option. In this example, let’s measure length. Select the measure line option and then left-click on the map to begin the measurement. After doing this, left-click again to measure the segment. Continue to left-click to measure segments of the line or right-click on the end point to finish measuring.
The following diagram shows a series of left clicks on the Alaska layer:
the drop-down boxes to adjust the units of measurement you require. The default
is set to
meters; we have changed ours to
kilometers to obtain a more usable distance unit.
you expand the arrow next to
Info in the
Measure toolbox, you will get more information
about how the measure tool is calculating the distance/area. An example is
shown in the following screenshot:
Selecting data is very useful in GIS. We can create a new layer from a selection, or we could add new data specific to that selection. QGIS allows multiple ways of selecting data, and we will cover some of these here. The data attributes toolbar allows selecting by area (this means drawing on the map by hand) and selecting by value (this means passing a query to select the data). The selection tools are highlighted in the following screenshot:
Working from left to right, the tools are Select by Area, Select by Attribute, and Clear Selection. Click on the Select by Location button and click on the largest area associated with the Alaska layer. It will change to yellow to highlight the selected layer. The following screenshot shows the other Select by Area options in the drop-down list:
Clear Selection to remove any selections from the layer.
Select by Value button is the second button on the
toolbar described previously. Click on this button to open a new window:
Select Features by Value window, we have clicked on the
Exclude field button associated with
AREA_MI and selected
Less than or
equal to (<=). As a
parameter, we have typed
1000 into the box. We then clicked
Select features and QGIS selected the features that
match this expression. At the top of the screen, a notification tells us how
many features have been selected. In this case, it is
we click on close and then press F6 or
click on the button immediately to the right of the
Clear Selection button, the attribute table will
appear with the selected rows highlighted. This attribute table for the
Alaska layer is shown as follows:
When you are finished inspecting this table, close it down by clicking the close button, on Windows this is an Χ symbol in the top-right corner.
is one more very useful tool worth mentioning, and that is the
Field Calculator tool. This button looks like an abacus
and is next to the
Attribute Table button. We will use this tool next to begin creating
our own data.
This article walked you through the steps for loading and interacting with data in QGIS. If you found this post useful, do check out the book, Learn QGIS – Fourth Edition on Packt Publishing. This book will help you get started on your QGIS journey, guiding you to develop your own processing pathway. You will explore the user interface, loading your data, editing, and then creating data. QGIS often surprises new users with its mapping capabilities; you will discover how easily you can style and create your first map.