Author: Ben Hur
This module will teach you the basic concepts of layers in QGIS and how to load them. At the end of this module, learners should be familiar with:
They should also be able to:
The required tools and resources for this module are:
Figure 2.1. A map overlay containing different layers and data types (https://saylordotorg.github.io/text_essentials-of-geographic-information-systems/s11-02-multiple-layer-analysis.html)
We learned from the previous modules that spatial data models such as vectors and rasters are models of real-world objects and phenomena and while it is perfectly okay to have a single layer that models one thing (e.g. elevation, temperature, household locations, zoning, etc.), in practice if we want to perform useful analysis or create a model that reflects the real-world better then we would need to use several data and layers together. Overlaying multiple thematic maps of the same area by putting them on top of each other is one of the oldest and most common geographic analysis techniques.
The picture above gives us a simple and concrete example of this. Imagine being a GIS consultant tasked with finding the best location for a new franchise restaurant (e.g. Jollibee or McDonalds). In order to do this, you would need to gather the relevant information that would help you decide. This can include information on the city streets, parcels of land, location and distribution of possible customers, the topography of the area, land use, etc.
These datasets can come in different types and formats. Some could be vector files while others can be rasters. Some can be in the same coordinate reference system while others can be in different coordinate reference systems. Some can be local files found in your computer while others can only be loaded via the internet. Because of the many possibilities as to what kind of data you would need for your spatial analysis, a good GIS should be able to handle and manage a variety of data sources.
Aside from the spatial data models (rasters and vectors) discussed in the first module, familiarity with geospatial file formats and their pros and cons is also important for anyone doing spatial analysis.
Most people who are new to GIS usually get introduced to spatial data via shapefiles. Most people never outgrow this and use shapefile to mean all types and forms of vector data. This is similar to how a specific brand like Coca Cola starts to get used as the general term for soft drinks. This isn’t necessarily wrong but is rather unfortunate since shapefiles are but one of the many kinds of vector data format. In fact, in some cases, other vector formats like geopackage, geojson, topojson, and flatgeobuf. The shapefile format, while ubiquitous, has some significant limitations such as:
Other data formats such as GeoPackage, GeoJSON, TopoJSON, and flatgeobuff remedy these limitations of shapefiles. In fact, QGIS and GRASS GIS have switched to GeoPackage as the default vector file format when importing or exporting layers and although GeoPackage also has some limitations, being a completely open format allows the community to help shape the future of the format.
So, if not shapefiles, what should you use?
There’s nothing wrong with using shapefiles especially if it fits your use-case. If you don’t need a dataset that goes beyond 2GB; if you’re okay with having a limit of 10 characters to your field names; or if you’re working with a small number of files locally, a shapefile is completely fine.
However, if you want to package your QGIS project together with all the layers (vectors, rasters), styling, and models; or you want to share multiple types of layers and spatial data in a single file, a GeoPackage is worth a look. GeoPackages and GeoJSONs are also web-friendly and can be used directly by web mapping libraries such as Mapbox and Leaflet.
You can read more in the link below: https://bnhr.xyz/2018/12/12/i-choose-geopackage.html
Meanwhile, 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 check out: 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 be enterprise-level databases like the free and open source Postgres with PostGIS extension (https://postgis.net/) or ESRI’s proprietary ArcSDE. There are also 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).
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:
QGIS can also connect and load data from services such as NASA’s SRTM data, Planet imagery, SentinelHub, Google Earth Engine, and OpenStreetMap through the power of plugins.
This makes QGIS an integral component for any spatial data infrastructure or workflow.
There are several ways to load layers in QGIS. These include:
NOTE: When loading layers, the default colors of your layers may be different than the default colors shown in this module.
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. You can also create connections to Favorite directories and Spatial Bookmarks in the Browser Panel.
To learn more about the Browser Panel, go to: https://docs.qgis.org/3.16/en/docs/user_manual/introduction/browser.html
Figure 2.2. The Browser Panel
Figure 2.3. The Module files in the Browser Panel
There are 5 files under the data folder:
Right click on BGD_admin_boundary.shp and click Layer Properties (Figure 2.4). This opens the layer properties window (Figure 2.5). 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?
Figure 2.4.Checking Layer Properties
Figure 2.5. Layer Properties from Browser Panel
You can load a layer from the Browser Panel by:
Figure 2.6. The vector layers loaded in QGIS
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. If you’ve loaded all the vectors from the previous exercise, your Layers Panel should appear like below:
Figure 2.7. The Layers Panel
The visibility of a layer can be controlled by checking or unchecking the box on the left of the Layer Name. By dragging the layers up or down in the Layers Panel, their Z-ordering can be changed. Similar to image manipulation software like GIMP or Photoshop, the layers listed near the top are drawn over layers listed lower down. So if two layers show the same area, the layer that is higher in the Layers Panel will be drawn on top of the lower layer and may not make the lower layer visible in the Map Canvas. This is worth noting because there can be instances where we think a layer does not appear in QGIS when in reality it is being covered or hidden by a layer on top of it.
NOTE: The Z-ordering of layers in the Layers Panel can be overridden by the Layer Order Panel.
The Layers Panel also allows the user to rename and remove layers, filter layer visibility, create and manage layer groups and map views.
The attribute table of a vector layer can also be opened from the Layers Panel by right-clicking on the layer ‣ Open attribute table.
To learn more about the Layers Panel, go to: https://docs.qgis.org/3.16/en/docs/user_manual/introduction/general_tools.html#layers-panel
Right-clicking on a layer in the Layers Panel and selecting Layer Properties will open the Layer Properties dialog.
Figure 2.8. The Layer Properties dialog
There are several tabs in the Layer Properties dialog that allows the user to see information and even edit/modify properties related to the layer.
The Information tab shows a read-only representation of summarized information and metadata on the current layer, including:
The Source tab shows general settings for a vector layer.
Tabs such as Symbology, Labels, Masks, and 3D View allows the user to modify the symbology and style of the layer.
Other tabs allow users to perform joins with the Layer (Join), get information about the attribute fields (Fields), add custom Forms for adding new data (Attribute Forms), and many more.
Another tab worth mentioning is the Metadata tab that provides the user with the ability to create and edit a metadata report on the layer. This includes information on:
A summary of the filled information is provided in the Validation tab and helps identify potential issues related to the metadata form. Currently, metadata is saved in the project file but they can also be saved in a separate .qmd file alongside the file based layers or in a local .sqlite database for remote layers.
To learn more about vector layer properties, go to: https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/vector_properties.html
To learn more about raster layer properties, go to: https://docs.qgis.org/3.16/en/docs/user_manual/working_with_raster/raster_properties.html
Metadata is simply data about the data. It answers the who, what, when, where and how of the dataset and comes in all shapes and sizes. For GIS purposes, we are usually concerned with geospatial metadata. Geospatial metadata is described the the U.S. Federal Geographic Data Committee (FGDC) as:
“a file of information, usually presented as an XML document, which captures the basic characteristics of a data or information resource. It represents the who, what, when, where, why and how of the resource. Geospatial metadata commonly document geographic digital data such as Geographic Information System (GIS) files, geospatial databases, and earth imagery but can also be used to document geospatial resources including data catalogs, mapping applications, data models and related websites. Metadata records include core library catalog elements such as Title, Abstract, and Publication Data; geographic elements such as Geographic Extent and Projection Information; and database elements such as Attribute Label Definitions and Attribute Domain Values.”
The importance of metadata is that it not only promotes transparency but also facilitates data and information sharing. This is why it is important to always add metadata to our datasets. When adding metadata, it is equally important to follow standards – widely promoted, accepted, and followed rules and practices – so that the metadata we create are interoperable. One such standard is the ISO 19115:2014 “Geographic Information – Metadata” from ISO/TC 211 (https://www.iso.org/obp/ui/#iso:std:iso:19115:-1:ed-1:v1:en)
Figure 2.9. Information properties of the BGD_admin_boundary layer
Figure 2.10. Editing some metadata
Figure 2.11. The Information tab after editing some metadata
True or False:
If you don’t want to use the Browser Panel to load layers, you can always use the Data Source Manager.
The Data Source Manager was introduced with the release of QGIS 3. It 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.). It can be accessed via Layers ‣ Data Source Manager or CTRL + L.
Figure 2.12. The Data Source Manager
Loading Vectors
Let’s load the vector file (hospitals) found inside the bangladesh geopackage. This layer is a point layer of the locations of hospitals in Bangladesh.
Figure 2.13. Loading a vector inside a GeoPackage
Loading Rasters
To load a raster, go to the Raster tab. Files and remote files via a Protocol like HTTP, cloud, etc can be loaded. There is a raster (bangadesh) inside the bangladesh geopackage. This raster is a digital elevation model of the country. To load it:
Figure 2.14. Loading a raster inside a GeoPackage
Loading CSV and other Delimited Text Files
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:
There is a CSV file in the data folder named schools.csv which contains point locations of schools in Bangladesh. To load it:
Geometry definition:
Layer settings: Check Watch file and Use spatial index
Figure 2.15. Loading a CSV file
Once all the layers in the previous exercises are loaded, the Layers Panel should look something like below:
Figure 2.16. Layers Panel with all layers loaded
The Map Canvas should look something like:
Figure 2.17. QGIS Interface with all layers loaded
Feel free to rearrange the layers in the Layer Panel.
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.
XYZ tiles are usually used as basemaps and are utilized not just in desktop applications, but more commonly, in web applications.
To connect to a tile server:
Name: ESRI World Imagery
URL: https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}
Figure 2.18. Adding an XYZ connection in QGIS
Figure 2.19. ESRI World Imagery Tile server added to the Browser Panel
Figure 2.20. ESRI World Imagery layer loaded in QGIS
Name: ESRI World Imagery
URL: https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}
BONUS: If you want to add several basemaps under XYZ Tiles in the Browser Panel, you can follow the instructions in this post: https://bnhr.xyz/2018/10/07/basemaps-in-qgis.html
BONUS #2: You can add the URLs of the tileservers found in the Leaflet Providers website (https://leaflet-extras.github.io/leaflet-providers/preview/) as XYZ Tiles in the Browser Panel.
WMS or Web Map Service is an Open Geospatial Consortium (OGC) (https://www.ogc.org/) complaint web service standard for serving images (raster tiles) over the internet. When data is served via WMS, the user cannot directly edit the information underneath it nor style it.
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.
To connect to a WMS:
Name: EOX Sentinel-2
URL: https://tiles.maps.eox.at/wms
Figure 2.21. Creating a new WMS/WMTS Connection
Figure 2.22. The EOX Sentinel-2 WMS added in the Browser Panel
Figure 2.23. Mosaic of Snetinel-2 imagery without clouds from WMS loaded in QGIS
True or False:
Exporting layers (or saving layers to files) is straightforward in QGIS. Simply Right-click on the layer ‣ Export to view the export options for the layer.
Figure 2.24. Exporting a layer from QGIS
Save Features As… allows you to save the raster or vector layer.
When exporting a layer, QGIS gives you the option to select the output file format, the fields to include (if a vector file), the output coordinate reference system, and other options. This means that you can perform coordinate projection by exporting a layer.
Figure 2.25. Save Vector Layer dialog
For more information on how to save a layer from an existing file, go to: https://docs.qgis.org/3.16/en/docs/user_manual/managing_data_source/create_layers.html#save-layer-from-an-existing-file
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 shown in the Layer Panel with this icon .
The outputs of processing algorithms are stored as temporary layers by default.
The downside of temporary layers is that QGIS “forgets” these “layers in memory” when it is closed. To remedy this, we can use the Memory Layer Saver plugin to allow our temporary layers to be persistent. 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.
Of course you can also just make the temporary layer permanent by exporting the layer to a file. Clicking the icon will automatically open an export layer dialog.
A virtual layer is a special type of vector layer that is created “on the fly” as a result of a query or data from another layer.
For example, we can create a virtual layer that creates a buffer around another feature layer. Whenever a new feature is added to the source feature layer, the virtual layer will be updated accordingly.
Currently, virtual layers don’t seem to work with source layers in memory.
Virtual layers are dynamic. This means that when the base/source layer is updated, the virtual layer is updated as well. This can save space and reduce data duplication since the virtual layer data will simply get data from the base layer without needing to save anything to your disk although there can be some performance overhead if complex queries or operations are used to define the virtual layer.
SQL-like constructs are used to define the virtual layer.
Virtual layers are dependent on other layers so it is important that the base layers are not moved or renamed.
When the base layer is updated, you need to refresh the map display by panning or zooming the map to show the virtual layer update.
True or False:
Some plugins provide the functionality to load data into QGIS. These include vector data, satellite imagery, raster files, basemaps, etc. Try to install the following plugins and find out what kind of data they load in QGIS:
P.S. Some of these plugins require you to sign up for an account with the data provider.
GeoNode (https://geonode.org/) 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 easily connect QGIS to a GeoNode instance via the GeoNode connector in the Browser Panel or the Data Source Manager.
Name: UNESCO IHP-WINS
URL: [http://ihp-wins.unesco.org/](http://ihp-wins.unesco.org/)
You can learn more about connecting QGIS to remote services at: https://bnhr.xyz/2018/10/12/connecting-qgis-to-remote-services.html
When you are prompted that the file already exists, select Add New Layer.
select fid, buffer(geometry, radius), species from Trees
Add a new point then refresh the map display (by zooming or panning the map canvas) to see the update in the virtual layer. What did you notice?
Aside from local binary files (vectors, rasters), QGIS can also load vectors and rasters found on the internet. Use the Data Source Manager to load the data from the following URL:
https://raw.githubusercontent.com/benhur07b/stomp-covid19-data/master/spatial/stompcovidph_regions.geojson
Install the Spreadsheet Layers plugin and try to load a spreadsheet in QGIS. The plugin accepts Open Document Standard formats (.ods) and Microsoft Excel files (.xls, .xlsx).
Read here: https://bnhr.xyz/2018/07/27/plugin-fridays-spreadsheet-layers-plugin.html