@@ -607,7 +607,6 @@ def _export_basemap_as_mbtiles(
607607 """
608608 Exports a basemap to mbtiles format.
609609 This method handles several zoom levels.
610- This should be preferred over the legacy `_export_basemap_as_tiff` method.
611610
612611 Args:
613612 extent (QgsRectangle): extent of the area of interest
@@ -623,12 +622,14 @@ def _export_basemap_as_mbtiles(
623622 .createAlgorithmById ("native:tilesxyzmbtiles" )
624623 )
625624
625+ basemap_export_path = self ._export_filename .with_name ("basemap.mbtiles" )
626+
626627 params = {
627628 "EXTENT" : extent ,
628629 "ZOOM_MIN" : self .project_configuration .base_map_tiles_min_zoom_level ,
629630 "ZOOM_MAX" : self .project_configuration .base_map_tiles_max_zoom_level ,
630631 "TILE_SIZE" : 256 ,
631- "OUTPUT_FILE" : str (self . _export_filename . with_name ( "basemap.mbtiles" ) ),
632+ "OUTPUT_FILE" : str (basemap_export_path ),
632633 }
633634
634635 # clone current QGIS project
@@ -686,6 +687,10 @@ def _export_basemap_as_mbtiles(
686687 # we use a try clause to make sure the feedback's `progressChanged` signal
687688 # is disconnected in the finally clause.
688689 try :
690+ # if the basemap file already exists on target destination,
691+ # the `native:tilesxyzmbtiles` alg will throw an error.
692+ basemap_export_path .unlink (missing_ok = True )
693+
689694 results , ok = alg .run (params , context , self ._feedback )
690695
691696 if not ok :
0 commit comments