From 7289f82d1aa3c4a46939a6880b0cfad6fc42adad Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Mon, 26 Feb 2024 12:06:18 -0500 Subject: [PATCH] Add merge_layers --- services_scripts/merge_layers.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 services_scripts/merge_layers.py diff --git a/services_scripts/merge_layers.py b/services_scripts/merge_layers.py new file mode 100644 index 0000000..cc33617 --- /dev/null +++ b/services_scripts/merge_layers.py @@ -0,0 +1,26 @@ +from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback +from qgis.analysis import QgsNativeAlgorithms +import processing +from services_scripts.basic_functions import find_shp_files + + +root_folder = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/clip_all' +layers_path = find_shp_files(root_folder) + +# Set the path to QGIS installation +QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.34.1/apps/qgis", True) + +# Initialize QGIS application +qgs = QgsApplication([], False) +qgs.initQgis() + +# Add native algorithms provider +QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) + +merged_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/merged_all/merge_divisions.shp' + +params = {'LAYERS': layers_path, + 'CRS': None, + 'OUTPUT': merged_layer} + +processing.run("native:mergevectorlayers", params)