Important update is commenting two lines in the constructor to experiment

This commit is contained in:
Alireza Adli 2024-04-12 11:18:35 -04:00
parent adee45be00
commit edce488e2a

View File

@ -14,9 +14,9 @@ class ScrubLayer:
# Set the path to QGIS installation # Set the path to QGIS installation
QgsApplication.setPrefixPath(self.qgis_path, True) QgsApplication.setPrefixPath(self.qgis_path, True)
# Initialize QGIS application # # Initialize QGIS application
qgs = QgsApplication([], False) # qgs = QgsApplication([], False)
qgs.initQgis() # qgs.initQgis()
self.layer_path = layer_path self.layer_path = layer_path
self.layer_name = layer_name self.layer_name = layer_name
@ -77,10 +77,8 @@ 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 clip_by_multiple(self, number_of_partitions, overlay_layer_path, overlay_layers_dir, clipped_layers_dir): def clip_by_multiple(self, number_of_partitions, overlay_layers_dir, clipped_layers_dir):
# overlay_layer = ScrubLayer(self.qgis_path, overlay_layer_path, 'Original Overlay Layer') create_folders(clipped_layers_dir, number_of_partitions)
# overlay_layer.split_layer(number_of_partitions, overlay_layers_dir)
# create_folders(clipped_layers_dir, number_of_partitions)
for layer in range(number_of_partitions): for layer in range(number_of_partitions):
overlay = overlay_layers_dir + f'/layer_{layer}/layer_{layer}.shp' overlay = overlay_layers_dir + f'/layer_{layer}/layer_{layer}.shp'
clipped = clipped_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 = ScrubLayer(self.qgis_path, output_layer_path, 'Temp Layer')
new_layer.create_spatial_index() 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): def multipart_to_singleparts(self, singleparts_layer_path):
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
params = {'INPUT': self.layer, params = {'INPUT': self.layer,