diff --git a/libqfieldsync/offline_converter.py b/libqfieldsync/offline_converter.py index f8b9cd5..21ba481 100644 --- a/libqfieldsync/offline_converter.py +++ b/libqfieldsync/offline_converter.py @@ -607,7 +607,6 @@ def _export_basemap_as_mbtiles( """ Exports a basemap to mbtiles format. This method handles several zoom levels. - This should be preferred over the legacy `_export_basemap_as_tiff` method. Args: extent (QgsRectangle): extent of the area of interest @@ -623,12 +622,14 @@ def _export_basemap_as_mbtiles( .createAlgorithmById("native:tilesxyzmbtiles") ) + basemap_export_path = self._export_filename.with_name("basemap.mbtiles") + params = { "EXTENT": extent, "ZOOM_MIN": self.project_configuration.base_map_tiles_min_zoom_level, "ZOOM_MAX": self.project_configuration.base_map_tiles_max_zoom_level, "TILE_SIZE": 256, - "OUTPUT_FILE": str(self._export_filename.with_name("basemap.mbtiles")), + "OUTPUT_FILE": str(basemap_export_path), } # clone current QGIS project @@ -686,6 +687,10 @@ def _export_basemap_as_mbtiles( # we use a try clause to make sure the feedback's `progressChanged` signal # is disconnected in the finally clause. try: + # if the basemap file already exists on target destination, + # the `native:tilesxyzmbtiles` alg will throw an error. + basemap_export_path.unlink(missing_ok=True) + results, ok = alg.run(params, context, self._feedback) if not ok: