Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors
podcast
Filter by Categories
Galleries
Print Category 1
Print Category 2
Uncategorized

Virtual Rasters In QGIS

How to create and use virtual rasters in QGIS

What is a virtual raster?

A virtual raster (VRT) is a special type of file that references one or more existing raster datasets and combines them into a single virtual layer. It is called “virtual” because it does not contain any actual raster data itself but rather serves as a pointer to the source raster layers.

Virtual rasters are often used to simplify the management and visualization of large collections of raster data, as they allow you to treat multiple raster layers as a single entity without the need to create large mosaics or to move data to different locations

Virtual rasters are often used in GIS software, such as QGIS or ArcGIS, to simplify the management and visualization of large collections of raster data. They are also used in other fields, such as remote sensing and image processing, where it is necessary to work with large volumes of raster data.

To build a virtual raster in QGIS, you can follow these steps:

  1. Open QGIS and add the raster layers that you want to include in the virtual raster to your map canvas.
  2. Select the “Raster” menu and then choose the “Miscellaneous” option.
  3. From the submenu, choose the “Build Virtual Raster” option.
  4. In the “Build Virtual Raster” dialogue, select the raster layers that you want to include in the virtual raster. You can use the “Add” and “Remove” buttons to add and remove layers from the list.
  5. Set the “Output file” by clicking the “Browse” button and selecting a location for the virtual raster file.
  6. Set any additional options, such as the “Resampling method” and the “Output format”.
  7. Click the “OK” button to create the virtual raster.
  8. The virtual raster will be added to your map canvas and will be displayed as a single layer, even though it is composed of multiple individual raster layers. You can use the virtual raster just like any other raster layer in QGIS, including styling it, performing analyses on it, and exporting it to different file formats.

Creating a virtual raster using GDAL

Read more about GDAL here

Use the GDAL VRT (Virtual Raster) format: The GDAL library, which is used by QGIS and many other geospatial software packages, includes support for creating virtual rasters using the VRT format.

A VRT file is an XML-based file that describes the structure and properties of a virtual raster, including the source raster layers and any additional processing that should be applied. You can use the gdalbuildvrt command-line utility to create a VRT file, or you can create one manually by writing the XML code.

To build a virtual raster using the gdalbuildvrt command-line utility, you can follow these steps:

  1. Open a terminal or command prompt window and navigate to the directory where the source raster layers are located.
  2. Run the gdalbuildvrt command, followed by the name that you want to give to the virtual raster file and the names of the source raster layers that you want to include, separated by spaces. For example:
gdalbuildvrt virtual_raster.vrt raster_1.tif raster_2.tif raster_3.tif
  1. Optionally, you can specify additional options to control how the virtual raster is created. For example, you can use the -separate option to store each source raster in a separate band of the virtual raster, or the -resolution option to specify the resolution of the virtual raster. You can see a full list of available options by running gdalbuildvrt --help.
  2. Press Enter to run the command. The gdalbuildvrt utility will create a VRT file with the specified name and add the source raster layers to it.
  3. You can now use the virtual raster file in any software that supports the VRT format, such as QGIS or GDAL. To open the virtual raster in QGIS, for example, you can go to the “Layer” menu and choose the “Add Raster Layer” option, and then select the VRT file. The virtual raster will be displayed as a single layer, even though it is composed of multiple individual raster layers.

Adding your Virtual raster to QGIS

To add a virtual raster to QGIS that has been created using the gdalbuildvrt command-line utility, you can follow these steps:

  1. Open QGIS and go to the “Layer” menu.
  2. Choose the “Add Raster Layer” option.
  3. In the “Add Raster Layer” dialogue, navigate to the location of the virtual raster file (which should have a .vrt file extension) and select it.
  4. Click the “Add” button to add the virtual raster to your map canvas.
  5. The virtual raster will be displayed as a single layer, even though it is composed of multiple individual raster layers. You can use the virtual raster just like any other raster layer in QGIS, including styling it, performing analyses on it, and exporting it to different file formats.

Alternatively, you can also drag and drop the virtual raster file from a file explorer window onto the QGIS map canvas to add it to your project.

Related Podcast episodes