Add clipping a layer service

This commit is contained in:
Alireza Adli 2024-02-13 15:35:45 -05:00
parent d1c8f24cdf
commit 1c77eb0115

View File

@ -0,0 +1,24 @@
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback
from qgis.analysis import QgsNativeAlgorithms
import processing
# 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/tests/python_fixed_04/py_fixes_04.shp'
clipping_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/montreal_boundary|layername=Montreal_boundary'
clipped_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan/clipped_nrcan.shp'
params = {'INPUT': input_layer, 'OVERLAY': clipping_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_layer}
processing.run("native:clip", params)
print("Clipping is completed.")
qgs.exitQgis()