Add split a layer

This commit is contained in:
Alireza Adli 2024-03-26 19:21:15 -04:00
parent ed5d972d60
commit ecc668f719

View File

@ -81,8 +81,35 @@ class ScrubLayer:
'OUTPUT': singleparts_layer_path} 'OUTPUT': singleparts_layer_path}
processing.run("native:multiparttosingleparts", params) processing.run("native:multiparttosingleparts", params)
def split_layer(self): def split_layer(self, number_of_layers, splitted_layers_dir, app_path):
pass number_of_layers -= 1
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
create_folders(splitted_layers_dir, number_of_layers)
intervals = self.data_count // number_of_layers
for part in range(number_of_layers):
output_layer_path = \
splitted_layers_dir + f'/layer_{part}/layer_{part}.shp'
params = {'INPUT': self.layer,
'EXPRESSION': f'$id >= {part * intervals} '
f'AND $id < {(part + 1) * intervals}\r\n',
'OUTPUT': output_layer_path}
processing.run("native:extractbyexpression", params)
new_layer = ScrubLayer(app_path, output_layer_path, 'Temp Layer')
new_layer.create_spatial_index()
remaining_features = number_of_layers
os.makedirs(splitted_layers_dir + f'/layer_{remaining_features}')
output_layer_path = splitted_layers_dir + \
f'/layer_{remaining_features}/layer_{remaining_features}.shp'
params = {'INPUT': self.layer,
'EXPRESSION': f'$id >= {number_of_layers * intervals}\r\n',
'OUTPUT': output_layer_path}
processing.run("native:extractbyexpression", params)
new_layer = ScrubLayer(app_path, output_layer_path, 'Temp Layer')
new_layer.create_spatial_index()
def delete_duplicates(self, deleted_duplicates_layer): def delete_duplicates(self, deleted_duplicates_layer):
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())