diff --git a/basic_functions.py b/basic_functions.py new file mode 100644 index 0000000..a6c040a --- /dev/null +++ b/basic_functions.py @@ -0,0 +1,14 @@ +import os +import glob +import time + + +def find_shp_files(root_folder): + shp_files = [] + # Sort folders alphabetically + for foldername, _, _ in sorted(os.walk(root_folder)): + for filename in sorted(glob.glob(os.path.join(foldername, '*.shp'))): + new_file_name = filename.replace('\\', r'/') + shp_files.append(new_file_name) + return shp_files + diff --git a/scrub_layer_class.py b/scrub_layer_class.py index ad7107b..5309d47 100644 --- a/scrub_layer_class.py +++ b/scrub_layer_class.py @@ -3,6 +3,7 @@ from qgis.core import QgsApplication, QgsField, QgsProject, \ QgsExpressionContext, QgsExpressionContextUtils, edit from qgis.PyQt.QtCore import QVariant from qgis.analysis import QgsNativeAlgorithms +from basic_functions import * import processing @@ -74,9 +75,6 @@ class ScrubLayer: processing.run("native:clip", clip_layer_params) print(f'Clipping of {self.layer_name} is completed.') - def merge_layers(self, layers_path, mered_layer_path): - pass - def multipart_to_singleparts(self, singleparts_layer_path): QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) params = {'INPUT': self.layer, diff --git a/scrub_mtl_class.py b/scrub_mtl_class.py index 347481e..39120f8 100644 --- a/scrub_mtl_class.py +++ b/scrub_mtl_class.py @@ -1,4 +1,5 @@ from scrub_layer_class import * +from basic_functions import * class ScrubMTL: @@ -9,6 +10,17 @@ class ScrubMTL: """Can be a part of the constructor""" pass + @staticmethod + def merge_layers(layers_path, mered_layer_path): + merging_layers = find_shp_files(layers_path) + QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) + + params = {'LAYERS': merging_layers, + 'CRS': None, + 'OUTPUT': mered_layer_path} + + processing.run("native:mergevectorlayers", params) + def generate_output_paths(self): pass