I like the idea of Virtual Layers, but when they are too big and constructed from complex queries, QGIS takes a lot of time to redraw it (it seems like it recalculates the entire layer at every zoom/pan/etc).

My workaround is to export Virtual Layer to GeoPackage format and continue to work with that.

In my case, Virtual Layer is often just an intermediate to be processed with further tools and I do not need it long term. I would rather save it as "Temporary scratch layer", just like many Processing tools do.

Is there a way to do so?


I usually just run the fix geometries processing tool on any layer to make a temporary copy of it. And try the memory layer saver plugin for persistence.


You are absolutely right that Virtual Layers are useful only to a certain extend.

What you can do is to create a Virtual Layer by means of PyQGIS and saving it as a GeoPackage or working with it as a temporary vlayer.

vlayer = QgsVectorLayer("?query=SELECT * FROM 'your_layer'", "vlayer", "virtual")

writer = QgsVectorFileWriter.writeAsVectorFormat(vlayer, r"C:/.../output.gpkg", "GeoPackage")

if writer[0] == QgsVectorFileWriter.NoError:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.