From 920f7e52672a618381133f3c71a283dffd77ebfb Mon Sep 17 00:00:00 2001 From: Jeff Osundwa Date: Thu, 19 Sep 2024 02:08:57 +0300 Subject: [PATCH] updated create grids function to remove lock files --- src/qgis_gender_indicator_tool/jobs/create_grids.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/qgis_gender_indicator_tool/jobs/create_grids.py b/src/qgis_gender_indicator_tool/jobs/create_grids.py index 1b97fe10..24d4902b 100644 --- a/src/qgis_gender_indicator_tool/jobs/create_grids.py +++ b/src/qgis_gender_indicator_tool/jobs/create_grids.py @@ -31,9 +31,7 @@ def create_grids(self, layer, output_dir, crs, merged_output_path): # Check if the merged grid already exists if os.path.exists(merged_output_path): print(f"Merged grid already exists: {merged_output_path}") - return QgsVectorLayer( - merged_output_path, "merged_grid", "ogr" - ) # Load the existing merged grid layer + return merged_output_path layer = QgsVectorLayer(layer, "country_layer", "ogr") if not layer.isValid(): @@ -118,4 +116,12 @@ def create_grids(self, layer, output_dir, crs, merged_output_path): print(f"Merging grids into: {merged_output_path}") merge_params = {"LAYERS": all_grids, "CRS": crs, "OUTPUT": merged_output_path} merged_grid = processing.run("native:mergevectorlayers", merge_params)["OUTPUT"] + lock_files = [ + f"{merged_output_path}-journal", + f"{merged_output_path}-wal", + f"{merged_output_path}-shm", + ] + for lock_file in lock_files: + if os.path.exists(lock_file): + os.remove(lock_file) return merged_grid