From 8dc94b1d389534516ad041ce6ba9be257a6fc404 Mon Sep 17 00:00:00 2001 From: Alireza Adli Date: Mon, 19 Feb 2024 10:52:36 -0500 Subject: [PATCH] Remove pairwise clip (clip) to replace it with the new procedure --- mtl_buildings_workflow.py | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/mtl_buildings_workflow.py b/mtl_buildings_workflow.py index 47bc168..43e4876 100644 --- a/mtl_buildings_workflow.py +++ b/mtl_buildings_workflow.py @@ -24,34 +24,33 @@ qgs.initQgis() # Add native algorithms provider QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) -# Reading Automatically Extracted Buildings layer (NRCan) and counting its data records +# Reading Automatically Extracted Buildings Footprints layer (NRCan) and counting its data records 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()}') -# Fixing geometries of the Automatically Extracted Buildings layer +# Fixing geometries of the NRCan layer print(f'Fixing {nrcan_name} geometries') 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_0, 'METHOD': 0, 'OUTPUT': fixed_nrcan_0} processing.run('native:fixgeometries', params_fixing_nrcan) fixed_nrcan, fixed_nrcan_name = load_layer(fixed_nrcan_0, 'Fixed NRCan') print(f'{fixed_nrcan_name} data count: {fixed_nrcan.featureCount()}') -# Removing unnecessary parts of the layer (outside of Montreal) using +# Removing unnecessary parts of the NRCan layer (outside of Montreal) using # Administrative boundaries of the Montreal agglomeration data 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_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'] +processing.run("native:clip", params_clipping_nrcan) print(f'Clipping of {fixed_nrcan_name} is completed.') # After each step, data records are counted -clipped_nrcan, clipped_nrcan_name = load_layer(clipped_layer_nrcan, 'Clipped NRCan') +clipped_nrcan, clipped_nrcan_name = load_layer(clipped_nrcan_layer, 'Clipped NRCan') print(f'{clipped_nrcan_name} data count: {clipped_nrcan.featureCount()}') @@ -60,58 +59,42 @@ print(f'{clipped_nrcan_name} data count: {clipped_nrcan.featureCount()}') # Without the index, most of the processes cannot be run (smoothly and efficiently) params_create_index_nrcan = {'INPUT': clipped_nrcan, 'OUTPUT': 'Output'} processing.run("native:createspatialindex", params_create_index_nrcan) - print(f'Creating spatial index for {clipped_nrcan_name} is completed.') +# Reading Shared platform of geospatial data and aerial photographs (GeoIndex) layer 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_name} data count: {geoindex.featureCount()}') +# Fixing the GeoIndex layer geometries 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()}') - +# Removing unnecessary parts of the GeoIndex layer (outside of Montreal) using +# Administrative boundaries of the Montreal agglomeration data 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()}') +# Creating spatial index fo the GeoIndex layer 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.') -# Adding the Property Assessment (uniteevaluation) dataset - +# Reading the Property Assessment (uniteevaluationfonciere) dataset uniteevaluationfonciere_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/uniteevaluationfonciere/uniteevaluationfonciere.shp' loaded_uniteevaluationfonciere_layer, uniteevaluationfonciere_layer_name = load_layer(uniteevaluationfonciere_layer, 'uniteevaluationfonciere') print(f'{uniteevaluationfonciere_layer_name} data count: {loaded_uniteevaluationfonciere_layer.featureCount()}') -clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan_10/clipped_nrcan_10.shp' -clipped_uniteevaluation_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_uniteevaluation/clipped_uniteevaluation.shp' - -params_clip_uniteevaluation = {'INPUT': uniteevaluationfonciere_layer, 'OVERLAY': clipped_nrcan_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_uniteevaluation_layer} -processing.run("native:clip", params_clip_uniteevaluation) - -print(f'Clipping the {uniteevaluationfonciere_layer_name} is completed.') - -params_create_index_uniteevaluationfonciere = {'INPUT': clipped_uniteevaluation_layer, 'OUTPUT': 'Output'} -indexed_layer = processing.run("native:createspatialindex", params_create_index_uniteevaluationfonciere) - -print(f'Creating spatial index for {uniteevaluationfonciere_layer_name} is completed.') - qgs.exitQgis() \ No newline at end of file