From 9929b918a23bd281e01f566237def602db9c30a5 Mon Sep 17 00:00:00 2001 From: gounux Date: Fri, 7 Mar 2025 06:13:53 +0100 Subject: [PATCH] Make basemap export not fail anymore when package already exists Update libqfieldsync/offline_converter.py Co-authored-by: Ivan Ivanov Update libqfieldsync/offline_converter.py Co-authored-by: Ivan Ivanov Update libqfieldsync/offline_converter.py Co-authored-by: Ivan Ivanov Apply suggestion from @suricactus --- libqfieldsync/offline_converter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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: