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 visualisation 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 visualisation 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.
How to build a virtual raster in QGIS
- Open QGIS and add the raster layers that you want to include in the virtual raster to your map canvas.
- Select the Raster menu and then choose the Miscellaneous option.
- From the submenu, choose the Build Virtual Raster option.
- In the Build Virtual Raster dialog, 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.
- Set the Output file by clicking the Browse button and selecting a location for the virtual raster file.
- Set any additional options, such as the Resampling method and the Output format.
- Click the OK button to create the virtual raster.
- 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
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, follow these steps:
- Open a terminal or command prompt window and navigate to the directory where the source raster layers are located.
- Run the
gdalbuildvrtcommand, 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
- Optionally, you can specify additional options to control how the virtual raster is created. For example, you can use the
-separateoption to store each source raster in a separate band of the virtual raster, or the-resolutionoption to specify the resolution of the virtual raster. You can see a full list of available options by runninggdalbuildvrt --help. - Press Enter to run the command. The
gdalbuildvrtutility will create a VRT file with the specified name and add the source raster layers to it. - 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, go to Layer > Add Layer > Add Raster Layer and 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 a virtual raster to QGIS
To add a virtual raster to QGIS that has been created using the gdalbuildvrt command-line utility, follow these steps:
- Open QGIS and go to the Layer menu.
- Choose Add Layer > Add Raster Layer.
- In the Add Raster Layer dialog, navigate to the location of the virtual raster file (which should have a
.vrtfile extension) and select it. - Click the Add button to add the virtual raster to your map canvas.
- 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 drag and drop the virtual raster file from a file explorer window onto the QGIS map canvas to add it to your project.






