From edce488e2a9298a437c38c3a1c249914b73ae2a7 Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Fri, 12 Apr 2024 11:18:35 -0400 Subject: [PATCH] Important update is commenting two lines in the constructor to experiment --- scrub_layer_class.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/scrub_layer_class.py b/scrub_layer_class.py index 05eeddf..0120f01 100644 --- a/scrub_layer_class.py +++ b/scrub_layer_class.py @@ -14,9 +14,9 @@ class ScrubLayer: # Set the path to QGIS installation QgsApplication.setPrefixPath(self.qgis_path, True) - # Initialize QGIS application - qgs = QgsApplication([], False) - qgs.initQgis() + # # Initialize QGIS application + # qgs = QgsApplication([], False) + # qgs.initQgis() self.layer_path = layer_path self.layer_name = layer_name @@ -77,10 +77,8 @@ class ScrubLayer: processing.run("native:clip", clip_layer_params) print(f'Clipping of {self.layer_name} is completed.') - def clip_by_multiple(self, number_of_partitions, overlay_layer_path, overlay_layers_dir, clipped_layers_dir): - # overlay_layer = ScrubLayer(self.qgis_path, overlay_layer_path, 'Original Overlay Layer') - # overlay_layer.split_layer(number_of_partitions, overlay_layers_dir) - # create_folders(clipped_layers_dir, number_of_partitions) + def clip_by_multiple(self, number_of_partitions, overlay_layers_dir, clipped_layers_dir): + create_folders(clipped_layers_dir, number_of_partitions) for layer in range(number_of_partitions): overlay = overlay_layers_dir + f'/layer_{layer}/layer_{layer}.shp' clipped = clipped_layers_dir + f'/layer_{layer}/layer_{layer}.shp' @@ -119,6 +117,17 @@ class ScrubLayer: new_layer = ScrubLayer(self.qgis_path, output_layer_path, 'Temp Layer') new_layer.create_spatial_index() + @staticmethod + def merge_layers(layers_path, mergeded_layer_path): + merging_layers = find_shp_files(layers_path) + QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) + + params = {'LAYERS': merging_layers, + 'CRS': None, + 'OUTPUT': mergeded_layer_path} + + processing.run("native:mergevectorlayers", params) + def multipart_to_singleparts(self, singleparts_layer_path): QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) params = {'INPUT': self.layer,