Add the workflow and services scripts

This commit is contained in:
Alireza Adli 2024-02-13 12:29:49 -05:00
parent b35a01873e
commit 60dcd3dd94
5 changed files with 125 additions and 0 deletions

39
mtl_buildings_workflow.py Normal file
View File

@ -0,0 +1,39 @@
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback
from qgis.analysis import QgsNativeAlgorithms
from services_scripts.load_layer import load_layer
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())
nrcan = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/nrcan/Autobuilding_QC_VILLE_MONTREAL.shp'
nrcan, nrcan_name = load_layer(nrcan, 'NRCan')
print(f'Loading {nrcan_name}')
print(f'{nrcan_name} data count: {nrcan.featureCount()}')
print(f'Fixing {nrcan_name} geometries')
fixed_nrcan = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_04/py_fixes_04.shp'
params_fixing_nrcan = {'INPUT': nrcan, 'METHOD': 0, 'OUTPUT': fixed_nrcan}
fixed_layer = processing.run("native:fixgeometries", params_fixing_nrcan)['OUTPUT']
fixed_nrcan, fixed_nrcan_name = load_layer(fixed_layer, 'Fixed NRCan')
print(f'{fixed_nrcan_name} data count: {fixed_nrcan.featureCount()}')
params_create_index_nrcan = {'INPUT': fixed_layer, 'OUTPUT': 'Output'}
indexed_layer = processing.run("native:createspatialindex", params_create_index_nrcan)
print("Creating spatial index is completed.")
qgs.exitQgis()

View File

@ -0,0 +1,21 @@
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback
from qgis.analysis import QgsNativeAlgorithms
from load_layer import load_layer
# 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())
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_02/py_fixes_02.shp'
layer, layer_name = load_layer(layer, 'NRCan Fixed')
print(f'{layer_name} data count: {layer.featureCount()}')
qgs.exitQgis()

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())
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_04/py_fixes_04.shp'
indexed_layer_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_04/py_fixes_04.qix'
params = {'INPUT': layer, 'OUTPUT': 'Output'}
indexed_layer = processing.run("native:createspatialindex", params)
print("Creating spatial index is completed.")
qgs.exitQgis()

View File

@ -0,0 +1,23 @@
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())
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/nrcan/Autobuilding_QC_VILLE_MONTREAL.shp'
fixed_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_03/py_fixes_03.shp'
params = {'INPUT': layer, 'METHOD': 0, 'OUTPUT': fixed_layer}
fix_layer = processing.run("native:fixgeometries", params)['OUTPUT']
print("Fixed Geometries is completed.")
# Exit QGIS application
qgs.exitQgis()

View File

@ -0,0 +1,18 @@
from qgis.core import *
# Supply the path to the qgis install location
QgsApplication.setPrefixPath(prefixPath='C:/Program Files/QGIS 3.34.1/apps/qgis', useDefaultPaths=True)
qgs = QgsApplication([], False)
# load providers
qgs.initQgis()
def load_layer(path, layer_name):
the_layer = QgsVectorLayer(path, layer_name, "ogr")
if not the_layer.isValid():
print(f'{layer_name} failed to load!')
else:
QgsProject.instance().addMapLayer(the_layer)
return the_layer, layer_name