Add basic functions module & add merge layers to the workflow class (scrub_mtl_class)

This commit is contained in:
Alireza Adli 2024-03-26 17:30:47 -04:00
parent bd6431c912
commit ed5d972d60
3 changed files with 27 additions and 3 deletions

14
basic_functions.py Normal file
View File

@ -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

View File

@ -3,6 +3,7 @@ from qgis.core import QgsApplication, QgsField, QgsProject, \
QgsExpressionContext, QgsExpressionContextUtils, edit QgsExpressionContext, QgsExpressionContextUtils, edit
from qgis.PyQt.QtCore import QVariant from qgis.PyQt.QtCore import QVariant
from qgis.analysis import QgsNativeAlgorithms from qgis.analysis import QgsNativeAlgorithms
from basic_functions import *
import processing import processing
@ -74,9 +75,6 @@ class ScrubLayer:
processing.run("native:clip", clip_layer_params) processing.run("native:clip", clip_layer_params)
print(f'Clipping of {self.layer_name} is completed.') 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): def multipart_to_singleparts(self, singleparts_layer_path):
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
params = {'INPUT': self.layer, params = {'INPUT': self.layer,

View File

@ -1,4 +1,5 @@
from scrub_layer_class import * from scrub_layer_class import *
from basic_functions import *
class ScrubMTL: class ScrubMTL:
@ -9,6 +10,17 @@ class ScrubMTL:
"""Can be a part of the constructor""" """Can be a part of the constructor"""
pass 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): def generate_output_paths(self):
pass pass