Workaround for: qgis2web freezes while changing map type
Fellow researchers and open-source GIS enthusiasts,
Welcome to my blog!
I’d like to start with a disclaimer – I may be a researcher of this very area but that doesn’t mean everything I do or write here will work for you, in your own desktop configurations and package versions. I have no responsibility if you lose data or mess up your installation. I also do not authorize any copies of my content.
One of my favorite plugins for QGIS is qgis2web, that generates maps to be published online based on the current QGIS project. It is available on the plugin repository of QGIS.
Today, I am showing a workaround for one of the most annoying issues for legacy computer users of qgis2web plugin. Sometimes you want to export a map with heavy data and you click the qgis2web button. So far, so good, but then you try to change the type of map between the available options (currently, OpenLayers, Leaflet and Mapbox GL JS) QGIS freezes and you have to close the application via Windows Task Manager.
I observed the occurrence on QGIS 3.20 Odense and on QGIS 3.16 Hannover, version of qgis2web 3.16.
Why does it happen?
While QGIS was freezing, I went on to the Task Manager to see the processes being executed.
What I saw was that QGIS alternates between the statuses “Not Responding” and “Responding”. While “Not responding”, I looked what are the processes called by qgis2web. And there it is, GDAL Translate executable, gdal_translate.exe
GDAL Translate algorithm is used, among other applications, to convert raster data between different formats. Because the project I opened includes raster layers, I believe these layers are being translated to another format, and qgis2web typically transforms raster data into PNG images to be used on the web map.
I waited long enough, and eventually QGIS “unfroze”. In the qgis2web export window, the preview is loaded. Most probably the freezing was qgis2web loading the preview of the map, and because the project is heavy this takes a long time. The fact that QGIS freezes and unfreezes constantly during the generation of the preview, and that gdal_translate is being called, makes me think that qgis2web can be exporting the layers of the project. In my case, it is probably exporting raster layers of the project as PNG files to use on the map preview. In qgis2web source code, it is possible to see that the preview shown on the dialog is a file loaded from a given directory.
OK, but what if I want to use a different option than the one that is selected by default, without having to wait for the preview to update, each time?
Open the project you want to export
Open qgis2web exporting window
Unmark all layers.
- Change the type of exported map freely
Mark the layers you want to export
Click in Export.
Do not click in “Update Preview”.
Wait potentially a long time. QGIS may freeze and unfreeze many times during export.
- Done! Enjoy your map.
- A draggable Truesize Leaflet map of the Brazilian states, and how to do the same for your own country or region
- Splitting many polygons into (almost) equal parts using a simple script in PyQGIS, the Python Console of QGIS
- The wedge tool: drawing circular quadrants, rings, and related geometries in QGIS
- Saving temporary scratch layers using PyQGIS and visualizing them in your QGIS Project