Introduction to layers in QGIS
Introduction
This module is designed to introduce you to the basics of layers in QGIS. This includes loading different kinds of layers in QGIS and connecting different data sources to QGIS as well as examples of what you can do with layers once you’ve loaded them in QGIS.
By the end of this module, you should know: the different data sources and file formats that can be loaded in QGIS, the different ways that data can be loaded in QGIS, and some common file formats used in GIS. You should also be able to: load layers (both vectors and rasters) using the Browser Panel and the Data Source Manager, connect QGIS to remote services, work with temporary and virtual layers, install some plugins that will load other datasets in QGIS, show layer properties such as metadata information, and save and export layers.
What you should already know
Since this is a beginner module, no previous knowledge of GIS or QGIS is required. However, familiarity with the QGIS interface—as discussed in Introduction to QGIS—is preferred.
Data formats and data sources
One of the most powerful features of QGIS is its ability to connect, load, and use different spatial and non-spatial data from a variety of sources. QGIS can open local files, local databases, files and databases on the internet via their uniform resource identifier (URI) or uniform resource locator (URL), web services, tile services, data portals, etc. QGIS can also connect to other services like NASA’s SRTM data, Planet imagery, SentinelHub, and Google Earth Engine through the power of plugins.
This makes QGIS an integral component for any spatial data infrastructure or workflow.
What kind of layers can we load in QGIS?
QGIS allows you to load:
- Local and remote files
- rasters, vectors, delimited text files (CSV, TSV), meshes, point clouds, tiles
- Databases (both spatial and non-spatial)
- GeoPackage, SpatiaLite PostgreSQL, MSSQL, SAP HANA
- Web and remote services
- OGC-compliant services (WMS, WFS)
- Raster (XYZ) and vector tiles
- GeoNode
- ArcGIS REST Servers
- Learn more: https://bnhr.xyz/2018/10/12/connecting-qgis-to-remote-services.html
Common data types and file formats
One of the most common file formats for vector data is the shapefile. However, as discussed in the previous modules, there are limitations to the format that are addressed by other formats such as geopackage, geojson, flatgeobuf, geoparquet, and others.
As for rasters, any format that can be represented as a grid of pixels or cells can be read by QGIS as raster data. This includes image formats such as PNG (.png) and JPEG (.jpg). It’s worth noting that although all image file formats can be read as rasters, not all of them are georeferenced or contain geospatial information that allows us to locate them properly on the earth. For instances like this, we can use what’s known as a world file (https://en.wikipedia.org/wiki/World_file). A world file is a separate, plaintext data file whose name is the same as the raster file it pertains to and whose file extension has the letter w added to the end. For example, the world file for world.png will be named world.pngw or world.pgw.
Some image file formats contain explicit georeferencing and information and do not need a world file. Some examples are GeoTIFFs (.tif or tiff) and ERDAS Imagine file format (.img).
For more information about file formats you can also refer to: https://saylordotorg.github.io/text_essentials-of-geographic-information-systems/s09-03-file-formats.html
Geospatial data can also come in the form of geospatial databases. These can come in the form of enterprise-ready databases like the free and open source Postgres with PostGIS extension (https://postgis.net/) or ESRI’s proprietary ArcSDE. They can also be file geodatabases that can store different types of data (e.g. vectors and rasters) inside them. Some examples are the free and open OGC GeoPackage (.gpkg) (https://www.geopackage.org/) and the proprietary File Geodatabase format by ESRI (.gdb).
How to load data in QGIS
There are several ways to load data in QGIS. Examples of which include:
- Drag-and-drop
- If QGIS knows the file format, it will load it as such.
- For example, vector and raster file formats can simply be dragged to the QGIS UI and it will be loaded.
-
Data Source Manager
- One-stop shop for loading all kinds of layers.
- Can be accessed via:
- Layer ‣ Data Source Manager
- CTRL + L
- Data Source Manager Toolbar
-
Menu Bar
- From the Layer Menu
-
Browser Panel
- Shows the local filesystem and connections to services such as databases, web services (tiles, OGC web services), and other layer services.
- Layers can be loaded and connected to QGIS from the Browser Panel by:
- Drag-and-drop
- Right-click on the layer ‣ Add Layer to Project
-
Using Plugins
- Some plugins will allow you to load or download data such as:
- QuickOSM: download OpenStreetMap data into QGIS
- OpenTopography DEM Downloader: download topography data (e.g. Digital Elevation Models) from OpenTopography
- SRTM-Downloader: download SRTM DEM data
- Spreadsheet Layers: load spreadsheets as layers in QGIS
- Open Hazards PH: load hazard data for the Philippines from available sources online
- QGIS GeoNode: adds GeoNode functionality to QGIS
- Some plugins will allow you to load or download data such as:
The Browser Panel
The Browser Panel displays a file tree that shows your computer’s files and folders as well as connections to databases and web servers.
By default, it is docked on the left side of the QGIS user interface together with the Layers Panel.
The Browser Panel exposes a lot of functionalities to connect, load, and show information about layers. It also allows you to create and access Browser Favorites and Spatial Bookmarks.
Favorites
Browser Favorites is a feature that allows users to save frequently used directories and services for quick access. This feature is helpful when you are working with data that are stored in different locations, as you can easily switch between them without having to navigate through multiple directories.
To add a directory or location to the Favorites list, simply right-click on the directory ‣ Add to Favorites. You can then give it a name and it will appear in the Favorites list. You can also directly add an item to your Favorites list by right-clicking on Favorites ‣ Add a Directory…
Spatial bookmarks
Spatial bookmarks in QGIS allow users to save specific locations in a project for quick and easy navigation. They are essentially saved views of a specific area of the map that can be easily accessed at any time. Users can create bookmarks by zooming in to a specific area and then saving that view as a bookmark. Once a spatial bookmark is saved, it can be easily accessed through the spatial bookmarks menu or by using a keyboard shortcut. This can save time and make it easier to navigate through a project, especially when working with large or complex data sets.
Exercise 3.1. Getting to know the Browser Panel
- Open QGIS
- Make sure that the Browser Panel is active and visible. If not, activate it from the View menu.
- Go to the Browser Panel, notice how the drives and folders can be expanded to show the subfolders inside them
- Locate the BNHR_QGIS-Essentials_Module_3 folder file tree (note where you saved or downloaded the file). You should be able to see the necessary data for this workbook. In my example below, I linked the aforementioned folder as one of my Favorites so I can easily go to it from the Browser Panel (Figure 2). You can do the same if you prefer.
-
Check the files inside the data folder. There are several of them. From the file tree itself, we can already get an idea of the files and layers that we can load in QGIS. The icons on the left of the names indicate whether the data is a vector, a raster, or a database.
-
There are 5 files under the data folder:
- NCR_admin_boundary.shp – a shapefile
- NCR_data.gpkg – a geopackage that contains a raster and vector file
- NCR_districts.geojson – a geojson
- NCR_municities.fgb – a flatgeobuf
- NCR_McDonalds.csv – a csv (comma-separated value) file
- Right click on and click Layer Properties (Figure 3). This opens the layer properties window (Figure 4). Notice the information provided in the window. What is the geometry of the layer? What CRS is used? How many features are in the layer?
-
Aside from providing metadata on the layers, you can also preview the geometry and attributes of the layer in the layer properties window.
-
You can load the layer from the Browser Panel by
- double-clicking the layer,
- drag-and-drop the layer to the map canvas, or
- right-click ‣ Add Layer to Project.
-
Do this for the shapefile and geojson. You should have have the two layers appear on the Layers Panel and the map canvas (Figure 5).
-
Expand the NCR_data.gpkg file. Notice that it contains two other files: a vector and a raster. A .gpkg file or a GeoPackage is a spatial database format based on the SQLite database and has several advantages over shapefile format.
-
Right-click on NCR_Jollibee ‣ Layer Properties. Check the information provided by the Layer Properties window.
-
Do the same for NCR_SRTM_DEM.
The Data Source Manager
The release of QGIS 3.X also saw the introduction of the Data Source Manager. The Data Source Manager is a “one-stop-shop” for adding and loading layers from different data sources in QGIS. Prior to its introduction, there were separate windows for loading different data sources (i.e. one for rasters, one for vectors, etc.).
The Data Source Manager helps you add, edit, and organize your spatial data. It allows you to connect to various types of data sources, such as files, databases, and web services, and preview their contents before adding them to your project. The manager also enables you to search for data sources, filter them by type, and save your favorite ones as bookmarks for quick access.
The Data Source Manager can be accessed via Layers ‣ Data Source Manager or CTRL + L.
Exercise 3.2. Getting to know the Data Source Manager
- Open the Data Source Manager
- Go to the Vector Tab and add the following parameters
- Source Type: File
- Source: NCR_data.gpkg
- Click Add
- Go to the Raster Tab and add the following parameters
- Source Type: File
- Source: NCR_data.gpkg
- Click Add
- The NCR_Jollibee and NCR_SRTM_DEM layers should be loaded in QGIS. You can rename the layers by right-clicking on layer in the Layers Panel ‣ Rename layer (n).
Loading delimited text files and spreadsheets
Aside from vectors and rasters, another common file used by GIS people are delimited text files (such as CSVs) and spreadsheets. Luckily, it’s relatively easy to load these files in QGIS.
CSVs and other delimited text files can be loaded via the Delimited Text tab in the Data Source Manager, adding them from the Browser Panel, and even just dragging them into the Map Canvas. However, a few things should be considered if the CSV you have contains geometry information (i.e. point locations). The rule of thumb is:
- Use the Data Source Manager for loading CSVs whether or not they contain geometry information.
- If CSVs will be loaded via the Browser Panel or by dragging, make sure that there is a corresponding CSVT file to preserve the field data types.
Meanwhile, spreadsheets (.xlsx, .ods) can be loaded via the Spreadsheet Layers plugin. For more information about the plugin, refer to: https://bnhr.xyz/2018/07/27/plugin-fridays-spreadsheet-layers-plugin.html
There is a CSV file in the data folder named NCR_McDonalds.csv which contains point locations of McDonald’s branches in NCR based on OpenStreetMap data. Let’s try to load it.
Exercise 3.3. Loading CSVs
- Open the Data Source Manager
- Go to the Delimited Text Tab and add the following parameters
- File name: NCR_McDonalds.csv
- File Format: CSV
- Geometry Definition: Point Coordinates
- X field: lon
- Y filed: lat
- Geometry CRS: EPSG: 4326
- Click Add.
- Open layer Properties and go to the Fields tab. Notice the type and type name of the fields.
- Try to load the NCR_McDonalds file from the Browser Panel or dragging the file to QGIS. What happens?
- Open layer Properties and go to the Fields tab. Notice the type and type name of the fields.
Connecting to remote services
Aside from vector and raster files, QGIS can also connect to remote services such as tile servicers, OGC Web Services (WMS, WFS), and even ESRI ArcGIS Web Services. This connection can be created from the Browser Panel or the Data Source Manager.
This allows users to easily connect and utilize data from different sources without the need to download and store the data locally on their computer. For example, users can easily access and use satellite imagery or topographic maps from remote services for their mapping projects.
Connecting to XYZ Tiles
XYZ tiles are usually used as basemaps and are utilized not just in desktop applications, but more commonly, in web applications. XYZ tiles (or raster tiles) come in the form of image tiles (PNG, JPG) that can be used to render the map on the screen.
In QGIS, you can add XYZ tiles as layers using the Browser Panel or the Data Source Manager. Simply provide the URL of the tile service and QGIS will automatically fetch and display the tiles. This is a great way to add context to your maps by using a variety of basemaps from different providers such as OpenStreetMap.
Exercise 3.4. Connecting to XYZ Tiles
- Go to the Browser Panel
- Right-click XYZ Tiles ‣ New Connection and add the following parameters:
- Name: Philippine GeoPortal Basemap
- URL:
https://basemapserver.geoportal.gov.ph/tiles/v2/PGP/{z}/{x}/{y}.png
- Click OK.
- You should then find an entry under XYZ Tiles in the Browser named Philippine GeoPortal Basemap. You can load this layer as you would any other layer in QGIS.
- Load the Philippine GeoPortal Basemap in your project.
- Try to add Bing VirtualEarth as well:
- URL:
http://ecn.t3.tiles.virtualearth.net/tiles/a{q}.jpeg?g=1
- URL:
Connecting to WMS/WMTS and WFS
WMS or Web Map Service is an Open Geospatial Consortium (OGC) (https://www.ogc.org/) complaint web service standard for serving images over the internet. This means that you can access maps from a server over the web and view them in your QGIS project. However, you cannot edit or modify the data underneath the images.
Meanwhile, WFS or Web Feature Services is another OGC-compliant web service for serving features (vectors) over the internet. When data is served via WFS, the user has access to the underlying attributes and geometry thus allowing him to style, edit, and use the layer for vector analysis.
Exercise 3.5. Connecting to WMS/WMTS
- Go to the Browser Panel
- Right-click WMS/WMTS ‣ New Connection and add the following parameters:
- Name: LiPAD 100-year Flood Hazard
- URL:
https://api.mapbox.com/styles/v1/osmph/cjqrynb300m522sper0emmgs6/wmts?access_token=sk.eyJ1Ijoib3NtcGgiLCJhIjoiY2pxbjF6czN2MGllbTQ4bXVuOW44ZDlpbSJ9.pUqHal3xOR1yZUaM6LbLkg
- Click OK
- This should add a LiPAD 100-year Flood Hazard item under the WMS/WMTS connections in the Browser Panel.
- Load the 100yr-Flood raster from this connection.
Connecting to GeoNode
GeoNode is an open-source Geospatial Content Management System built with a mature FOSS4G stack that includes PostGIS, GeoServer, MapStore, etc. You can think of GeoNode as a geospatial data portal.
You can connect to GeoNode by first installing the QGIS GeoNode plugin and accessing it via the Data Source Manager.
Connecting to Cloud Storage
New in QGIS 3.40 is the ability to directly connect and browse supported vector and raster data stored in cloud storage providers (e.g. AWS S3, Google Cloud Storage, Microsoft Azure Blob Storage) within the QGIS browser panel.
This adds to the many features that make QGIS an incredibly powerful tool for accessing and exploring remotely-stored geospatial data.
You can watch the video below if you speak Filipino.Save and load Browser connections
You can also save and load Browser connections directly.
To save a Browser connection:
- Go to the Browser Panel.
- Right click on the connection type you want to save.
- Click Save Connections…
The Browser connections are saved as XML files.
To load a Browser connection:
- Go to the Browser Panel.
- Right click on the connection type you want to save.
- Click Load Connections…
- Select the XML file that has the saved Browser connections.
Additional layer features
The Layers Panel
The Layers Panel lists all the current layers in the project. It helps manage their visibility, order, and can be used to show Layer Properties. The Layers Panel can be activated from View ‣ Panels ‣ Layers Panel or using the shortcut CTRL+1. It is also called the Map Legend.
Layer visibility and ordering
In QGIS, you can easily control the visibility of layers by checking or unchecking the box located on the left of the Layer Name in the Layers Panel. You can also change the order in which layers are drawn by dragging them up or down. It’s important to note that the layer order in the Layers Panel affects the Z-ordering of the layers in the Map Canvas, which means layers listed at the top will be drawn on top of layers listed lower down. This is similar to image manipulation software like GIMP or Photoshop.
It’s worth mentioning that if you can’t see a layer in QGIS, it might be hidden or covered by another layer on top of it. So, make sure to check the layer order in the Layers Panel if you’re having trouble viewing a layer in the Map Canvas.
Renaming layers, removing layers, and other layer functions
The Layers Panel provides more than just the ability to control the visibility and order of layers. It also offers a range of powerful tools to help you manage and organize your layers.
For example, you can rename layers to make them easier to identify, or remove layers that are no longer needed. Additionally, the panel lets you filter the visibility of layers based on certain criteria, such as whether they are currently visible or not. This can be particularly useful when working with complex maps containing many layers.
Another useful feature of the Layers Panel is the ability to create and manage layer groups. Layer groups are simply collections of layers that are grouped together for ease of use. This is especially handy when you have many layers that belong to the same category, such as roads, buildings, or water bodies. You can create a group from the Layer panel toolbar or by selecting the layers you want to group, right-click ‣ select Group ‣ Group Selected. Once a group is created, you can add more layers by dragging them inside the group.
There is also the Zoom to Layer(s) function that allows you to quickly zoom in to a specific layer or a group of selected layers in the Layers Panel. To use this function, simply right-click on the layer(s) you want to zoom to in the Layers Panel ‣ Zoom to Layer(s) from the drop-down menu.
You can also create map views, which are simply saved sets of layers and their associated styles, that allow you to easily switch between different map layouts. Map views are discussed further in the QGIS: Working with Maps and Layouts course.
Opening attribute tables
An attribute table is the set of data and information that describes the features in a layer. It contains information such as feature names, values, and descriptions. To open the attribute table in QGIS you can:
- Right-click on the layer you want to view on the Layers Panel.
- Click on the layer to select it and then click on the Open Attribute Table button (which looks like a table) on the Attributes toolbar.
- Use the shortcut F6.
You should see a window open with a table showing all the attributes of the layer, which you can sort, select, filter, and do other things.
Exporting layers from QGIS
Exporting layers is an essential part of any GIS workflow. In QGIS, exporting layers can be done easily through the Layers panel by right-clicking on a layer ‣ Export. QGIS provides different options for exporting layers through this approach: you can save a new copy of the layer, save just the selected features, save a Layer Definition file (QLR) or a Layer Style file (QML).
Layers in memory / temporary layers
Sometimes, we don’t need or want to physically save the layers we use in our analysis in our computers, especially if they are just temporary. QGIS understands this and allows users to create temporary / scratch layers. These layers can be used similar to regular vector layers but do not need to be permanently saved into a file in our storage drives because QGIS stores them in memory or RAM. Temporary layers are marked in the Layer Panel by the Temporary layer symbol to their right.
The downside of temporary layers is that QGIS “forgets” these “layers in memory” when QGIS is closed. You will know that a layer is temporary because it as the Temporary layer symbol on the right of its name in the layer panel. When hovering over this icon, QGIS will warn you that the layer is only temporary and will disappear once QGIS is closed. Clicking on the icon will ask you to save/export the temporary layer to make it permanent.
Aside from exporting temporary layers, another way to make them persistent is through the Memory Layer Saver plugin. When saving a QGIS project that uses temporary layers, it is good practice to run/activate the Memory Layer Saver plugin first. To use the Memory Layer Saver plugin, simply go to Plugins ‣ Memory Layer Saver before saving and closing your QGIS project. The next time you open your QGIS project, the temporary layers (or layers in memory) should still be present.
Virtual layers
A virtual layer in QGIS is a special type of layer that is created on-the-fly based on a query or data from another layer. This other layer is often referred to as the base layer. The virtual layer is updated whenever the base layer changes. However, this does not happen automatically. You need to refresh the map display by panning or zooming to show the virtual layer update.
The dynamic feature of virtual layers help you save disk space and reduce data duplication because they don’t require new files to be created. For example, say you are doing a field survey of trees and are recording the canopy radius of each tree. You can create a virtual layer that creates a buffer around the location of the tree—with the canopy radius being the buffer radius—thus automatically creating a layer of tree canopies together with the layer of point locations.
When using virtual layers, it is also important to remember that they are dependent on the base layer, so it’s important not to move or rename the base layer.
To define a virtual layer, you can use SQL-like constructs. Although quite powerful, virtual layers can be slower if complex queries or operations are used.
Other things you can do with layers
Aside from the topics discussed in this module, other things that you can do with layers include:
- Joining and relating data. You can join tabular data to vector layers based on a common attribute. You can also join two vector layers based on their spatial relationship. This allows you to perform analysis and create new layers based on the combined attributes of multiple datasets.
- Filtering and selecting features based on attributes and spatial relationships. Filtering and selecting features is an important part of data analysis in GIS. By selecting features based on specific attributes or spatial relationships, you can answer specific questions and derive new information. For example, you can select all the houses in a city that have a certain number of rooms or select all the streets that intersect with a particular road.
- Creating new vectors through the process of digitizing. Digitizing is the process of converting analog data into digital form, and in the context of GIS, it usually refers to the process of creating new vector features by tracing them from a scanned map or aerial photo. Digitizing is important when working with historical maps or when there is no digital version of a dataset available.
- Putting rasters and vectors in their correct location using the process of georeferencing. Georeferencing is the process of aligning spatial data to real-world coordinates so that it can be overlaid with other layers in a GIS. This is important when working with datasets, such as scanned maps, aerial photos, old maps, or vector files that have no spatial information attached to them.
Certification and support
Contact us or sign-up to our courses if you are interested in having this as an instructor-led or self-paced course.