Replace load_layer module with load_layer function in the main workflow file
This commit is contained in:
parent
1c77eb0115
commit
f1bd10921e
13
.gitignore
vendored
13
.gitignore
vendored
@ -1,6 +1,19 @@
|
||||
# Folders
|
||||
data/
|
||||
ignored_data/
|
||||
drafts/
|
||||
|
||||
# Python Modules
|
||||
standalone_charm.py
|
||||
*_test.py
|
||||
|
||||
# Other Files
|
||||
setting_up_standalone_pyqgis.docx
|
||||
|
||||
|
||||
.idea/.name
|
||||
__pycache__/
|
||||
services_scripts/__init__.py
|
||||
services_scripts/__pycache__/
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
<module type="PYTHON_MODULE" version="4">
|
||||
<component name="NewModuleRootManager">
|
||||
<content url="file://$MODULE_DIR$" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.11 (gisPy)" jdkType="Python SDK" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.9 (hydroquebec_archetype_gispy) (2)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (gisPy)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (hydroquebec_archetype_gispy) (2)" project-jdk-type="Python SDK" />
|
||||
</project>
|
@ -1,8 +1,17 @@
|
||||
from qgis.core import QgsApplication, QgsVectorLayer, QgsProcessingFeedback
|
||||
from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, QgsProcessingFeedback
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
from services_scripts.load_layer import load_layer
|
||||
import processing
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# Set the path to QGIS installation
|
||||
QgsApplication.setPrefixPath('C:/Program Files/QGIS 3.34.1/apps/qgis', True)
|
||||
|
||||
@ -14,32 +23,32 @@ 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')
|
||||
nrcan_0 = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/nrcan/Autobuilding_QC_VILLE_MONTREAL.shp'
|
||||
nrcan, nrcan_name = load_layer(nrcan_0, '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'
|
||||
fixed_nrcan_0 = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/new_tests/python_fixed_05/py_fixes_05.shp'
|
||||
|
||||
params_fixing_nrcan = {'INPUT': nrcan, 'METHOD': 0, 'OUTPUT': fixed_nrcan}
|
||||
params_fixing_nrcan = {'INPUT': nrcan_0, 'METHOD': 0, 'OUTPUT': fixed_nrcan_0}
|
||||
fixed_layer_nrcan = processing.run('native:fixgeometries', params_fixing_nrcan)['OUTPUT']
|
||||
|
||||
fixed_nrcan, fixed_nrcan_name = load_layer(fixed_layer_nrcan, 'Fixed NRCan')
|
||||
print(f'{fixed_nrcan_name} data count: {fixed_nrcan.featureCount()}')
|
||||
|
||||
|
||||
montreal_boundary_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/montreal_boundary|layername=Montreal_boundary'
|
||||
clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan/clipped_nrcan.shp'
|
||||
clipping_montreal_boundary_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/montreal_boundary|layername=Montreal_boundary'
|
||||
clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/new_tests/clipped_nrcan_1/clipped_nrcan_1.shp'
|
||||
|
||||
params_clipping_nrcan = {'INPUT': fixed_nrcan, 'OVERLAY': montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_layer}
|
||||
processing.run("native:clip", params_clipping_nrcan)
|
||||
params_clipping_nrcan = {'INPUT': fixed_nrcan_0, 'OVERLAY': clipping_montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_nrcan_layer}
|
||||
clipped_layer_nrcan = processing.run("native:clip", params_clipping_nrcan)['OUTPUT']
|
||||
|
||||
print(f'Clipping of {fixed_nrcan_name} is completed.')
|
||||
|
||||
clipped_nrcan, clipped_nrcan_name = load_layer(clipped_nrcan_layer, 'Clipped NRCan')
|
||||
clipped_nrcan, clipped_nrcan_name = load_layer(clipped_layer_nrcan, 'Clipped NRCan')
|
||||
print(f'{clipped_nrcan_name} data count: {clipped_nrcan.featureCount()}')
|
||||
|
||||
|
||||
@ -48,9 +57,35 @@ indexed_layer = processing.run("native:createspatialindex", params_create_index_
|
||||
|
||||
print(f'Creating spatial index for {clipped_nrcan_name} is completed.')
|
||||
|
||||
geoindex_unclipped_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/Geoindex_81670/mamh_usage_predo_2022_s_poly.shp'
|
||||
geoindex_unclipped, geoindex_unclipped_name = load_layer(geoindex_unclipped_layer, 'GeoIndex Unclipped')
|
||||
geoindex_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/Geoindex_81670/mamh_usage_predo_2022_s_poly.shp'
|
||||
geoindex, geoindex_name = load_layer(geoindex_layer, 'GeoIndex')
|
||||
|
||||
print(f'{geoindex_unclipped_name} data count: {geoindex_unclipped.featureCount()}')
|
||||
print(f'{geoindex_name} data count: {geoindex.featureCount()}')
|
||||
|
||||
print(f'Fixing {geoindex_name} geometries')
|
||||
|
||||
fixed_geoindex_0 = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/new_tests/fixed_geoindex_9/fix_geo_9.shp'
|
||||
|
||||
params_fixing_geoindex = {'INPUT': geoindex, 'METHOD': 0, 'OUTPUT': fixed_geoindex_0}
|
||||
fixed_layer_geoindex = processing.run("native:fixgeometries", params_fixing_geoindex)['OUTPUT']
|
||||
|
||||
fixed_geoindex, fixed_geoindex_name = load_layer(fixed_layer_geoindex, 'Fixed NRCan')
|
||||
print(f'{fixed_geoindex_name} data count: {fixed_geoindex.featureCount()}')
|
||||
|
||||
|
||||
clipped_geoindex_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/new_tests/clipped_geo_3/clipped_geo_3.shp'
|
||||
|
||||
params = {'INPUT': fixed_geoindex, 'OVERLAY': clipping_montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_geoindex_layer}
|
||||
processing.run("native:clip", params)
|
||||
|
||||
print(f'Clipping {fixed_geoindex_name} is completed.')
|
||||
|
||||
clipped_geoindex, clipped_geoindex_name = load_layer(clipped_nrcan_layer, 'Clipped GeoIndex')
|
||||
print(f'{clipped_geoindex_name} data count: {clipped_geoindex.featureCount()}')
|
||||
|
||||
params_create_index_geoindex = {'INPUT': clipped_geoindex, 'OUTPUT': 'Output'}
|
||||
processing.run("native:createspatialindex", params_create_index_geoindex)
|
||||
|
||||
print(f'Creating spatial index for {clipped_geoindex_name} is completed.')
|
||||
|
||||
qgs.exitQgis()
|
@ -12,9 +12,9 @@ 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'
|
||||
input_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_05/py_fixes_05.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'
|
||||
clipped_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan_10/clipped_nrcan_10.shp'
|
||||
|
||||
params = {'INPUT': input_layer, 'OVERLAY': clipping_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_layer}
|
||||
processing.run("native:clip", params)
|
||||
|
@ -13,8 +13,8 @@ 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')
|
||||
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan_10/clipped_nrcan_10.shp'
|
||||
layer, layer_name = load_layer(layer, 'NRCan')
|
||||
|
||||
print(f'{layer_name} data count: {layer.featureCount()}')
|
||||
|
||||
|
@ -11,7 +11,7 @@ qgs.initQgis()
|
||||
|
||||
# Add native algorithms provider
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/fixed_geoindex/fix_geo.shp'
|
||||
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/fixed_geoindex_3/fix_geo.shp'
|
||||
|
||||
params = {'INPUT': layer, 'OUTPUT': 'Output'}
|
||||
processing.run("native:createspatialindex", params)
|
||||
|
@ -11,8 +11,8 @@ 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'
|
||||
layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/Geoindex_81670/mamh_usage_predo_2022_s_poly.shp'
|
||||
fixed_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/fixed_geoindex_7/py_fixes_07.shp'
|
||||
|
||||
params = {'INPUT': layer, 'METHOD': 0, 'OUTPUT': fixed_layer}
|
||||
fix_layer = processing.run("native:fixgeometries", params)['OUTPUT']
|
||||
|
Loading…
Reference in New Issue
Block a user