Add a service that clip based on several overlays
This commit is contained in:
parent
321b9f4ff5
commit
b0e94b114b
35
services_scripts/clip_with_several_overlays.py
Normal file
35
services_scripts/clip_with_several_overlays.py
Normal file
@ -0,0 +1,35 @@
|
||||
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
import processing
|
||||
from services_scripts.basic_functions import create_folders
|
||||
|
||||
clipped_layers_folder = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/clip_all'
|
||||
num_clipped_layers = 21
|
||||
create_folders(clipped_layers_folder, num_clipped_layers)
|
||||
|
||||
# Set the path to QGIS installation
|
||||
QgsApplication.setPrefixPath("C:/Program Files/QGIS 3.34.1/apps/qgis", True)
|
||||
|
||||
# Initialize QGIS application
|
||||
qgs = QgsApplication([], False)
|
||||
qgs.initQgis()
|
||||
|
||||
# Add native algorithms provider
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
|
||||
input_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/uniteevaluationfonciere/uniteevaluationfonciere.shp'
|
||||
|
||||
for each in range(num_clipped_layers):
|
||||
clipping_layer = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/divided_all/layer_{each}/layer_{each}.shp'
|
||||
clipped_layer = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/clip_all/layer_{each}/layer_{each}.shp'
|
||||
|
||||
params = {'INPUT': input_layer, 'OVERLAY': clipping_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_layer}
|
||||
processing.run("native:clip", params)
|
||||
|
||||
# Creating spatian index for each new layer
|
||||
create_spatial_indext_params = {'INPUT': clipped_layer, 'OUTPUT': 'Output'}
|
||||
processing.run("native:createspatialindex", create_spatial_indext_params)
|
||||
|
||||
print("Clipping is completed.")
|
||||
|
||||
qgs.exitQgis()
|
Loading…
Reference in New Issue
Block a user