diff --git a/mtl_buildings_workflow.py b/mtl_buildings_workflow.py index eb8e779..8e37f12 100644 --- a/mtl_buildings_workflow.py +++ b/mtl_buildings_workflow.py @@ -1,11 +1,14 @@ -from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, QgsProcessingFeedback +from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, \ + QgsProcessingFeedback from qgis.analysis import QgsNativeAlgorithms import processing import os -from services_scripts.basic_functions import create_folders, find_shp_files +from services_scripts.basic_functions import create_folders, \ + find_shp_files -# This function loads a layer. It's used to count the data records +# This function loads a layer. +# It's used to count the data records def load_layer(path, layer_name): the_layer = QgsVectorLayer(path, layer_name, "ogr") if not the_layer.isValid(): @@ -26,46 +29,68 @@ qgs.initQgis() # Add native algorithms provider QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms()) -# Reading the Automatically Extracted Buildings Footprints layer (NRCan) and counting its data records -nrcan_0 = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/input_data/nrcan/Autobuilding_QC_VILLE_MONTREAL.shp' -nrcan, nrcan_name = load_layer(nrcan_0, 'NRCan') +# Reading the Automatically Extracted Buildings Footprints layer (NRCan) +# and counting its data records +nrcan_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'input_data/nrcan/Autobuilding_QC_VILLE_MONTREAL.shp' +nrcan, nrcan_name = load_layer(nrcan_layer, 'NRCan') print(f'Loading {nrcan_name}') print(f'{nrcan_name} data count: {nrcan.featureCount()}') # Fixing geometries of the NRCan layer print(f'Fixing {nrcan_name} geometries') -fixed_nrcan_0 = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/output_data/data/fixed_nrcan/fixed_nrcan.shp' -params_fixing_nrcan = {'INPUT': nrcan_0, 'METHOD': 0, 'OUTPUT': fixed_nrcan_0} +fixed_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/fixed_nrcan/fixed_nrcan.shp' +params_fixing_nrcan = {'INPUT': nrcan_layer, + 'METHOD': 0, + 'OUTPUT': fixed_nrcan_layer} processing.run('native:fixgeometries', params_fixing_nrcan) -fixed_nrcan, fixed_nrcan_name = load_layer(fixed_nrcan_0, 'Fixed NRCan') +fixed_nrcan, fixed_nrcan_name = load_layer(fixed_nrcan_layer, 'Fixed NRCan') print(f'{fixed_nrcan_name} data count: {fixed_nrcan.featureCount()}') # 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/input_data/montreal_boundary|layername=Montreal_boundary' -clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/clipped_fixed_nrcan/clipped_fixed_nrcan.shp' +clipping_montreal_boundary_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'input_data/montreal_boundary/' \ + 'Montreal_boundary.shp' +clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/clipped_fixed_nrcan/clipped_fixed_nrcan.shp' -params_clipping_nrcan = {'INPUT': fixed_nrcan_0, 'OVERLAY': clipping_montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_nrcan_layer} +params_clipping_nrcan = {'INPUT': fixed_nrcan_layer, + 'OVERLAY': clipping_montreal_boundary_layer, + 'FILTER_EXPRESSION': '', + 'FILTER_EXTENT': None, + 'OUTPUT': clipped_nrcan_layer} 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_nrcan_layer, 'Clipped NRCan') +clipped_nrcan, clipped_nrcan_name = \ + load_layer(clipped_nrcan_layer, 'Clipped NRCan') clipped_nrcan_length = clipped_nrcan.featureCount() print(f'{clipped_nrcan_name} data count: {clipped_nrcan_length}') # Creating spatial index is needed for most of the newly built layers. # It adds a file with suffix .qix -# Without the index, most of the processes cannot be run (smoothly and efficiently) -params_create_index_nrcan = {'INPUT': clipped_nrcan_layer, 'OUTPUT': 'Output'} +# Without the index, most of the processes cannot be run +# (smoothly and efficiently) +params_create_index_nrcan = {'INPUT': clipped_nrcan_layer, + '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/input_data/Geoindex_81670/mamh_usage_predo_2022_s_poly.shp' +# Reading Shared platform of geospatial data +# and aerial photographs (GeoIndex) layer +geoindex_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'input_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()}') @@ -74,100 +99,159 @@ processing.run("native:createspatialindex", params_create_index_geo) # Fixing the GeoIndex layer geometries print(f'Fixing {geoindex_name} geometries') -fixed_geoindex = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/fixed_geoindex/fixed_geoindex.shp' -params_fixing_geoindex = {'INPUT': geoindex, 'METHOD': 0, 'OUTPUT': fixed_geoindex} +fixed_geoindex = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/fixed_geoindex/fixed_geoindex.shp' +params_fixing_geoindex = {'INPUT': geoindex, + 'METHOD': 0, + 'OUTPUT': fixed_geoindex} processing.run("native:fixgeometries", params_fixing_geoindex) -params_create_index_fixed_geo = {'INPUT': fixed_geoindex, 'OUTPUT': 'Output'} +params_create_index_fixed_geo = {'INPUT': fixed_geoindex, + 'OUTPUT': 'Output'} processing.run("native:createspatialindex", params_create_index_fixed_geo) -fixed_geoindex_read, fixed_geoindex_name = load_layer(fixed_geoindex, 'Fixed NRCan') -print(f'{fixed_geoindex_name} data count: {fixed_geoindex_read.featureCount()}') +fixed_geoindex_read, fixed_geoindex_name = \ + load_layer(fixed_geoindex, 'Fixed NRCan') +print(f'{fixed_geoindex_name} ' + f'data count: {fixed_geoindex_read.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/output_data/clipped_fixed_geoindex/clipped_fixed_geoindex.shp' -params = {'INPUT': fixed_geoindex, 'OVERLAY': clipping_montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_geoindex_layer} +clipped_geoindex_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/clipped_fixed_geoindex/' \ + 'clipped_fixed_geoindex.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_geoindex_layer, 'Clipped GeoIndex') +clipped_geoindex, clipped_geoindex_name = \ + load_layer(clipped_geoindex_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_layer, 'OUTPUT': 'Output'} -processing.run("native:createspatialindex", params_create_index_geoindex) +params_create_index_clipped_geo = {'INPUT': clipped_geoindex_layer, + 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", params_create_index_clipped_geo) print(f'Creating spatial index for {clipped_geoindex_name} is completed.') # Reading the Property Assessment (AKA uniteevaluationfonciere) dataset -property_assessment_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/input_data/property_assessment/uniteevaluationfonciere.shp' +property_assessment_layer = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'input_data/property_assessment/' \ + 'uniteevaluationfonciere.shp' -property_assessment_read, property_assessment_layer_name = load_layer(property_assessment_layer, 'Property Assesment') -print(f'{property_assessment_layer_name} data count: {property_assessment_read.featureCount()}') +property_assessment_read, property_assessment_layer_name = \ + load_layer(property_assessment_layer, 'Property Assesment') +print(f'{property_assessment_layer_name} ' + f'data count: {property_assessment_read.featureCount()}') # Creating spatial index for the GeoIndex layer -params_create_index_property_assessment = {'INPUT': property_assessment_layer, 'OUTPUT': 'Output'} -processing.run("native:createspatialindex", params_create_index_property_assessment) -print(f'Creating spatial index for {property_assessment_layer_name} is completed.') +params_create_index_property_assessment = {'INPUT': property_assessment_layer, + 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", + params_create_index_property_assessment) +print(f'Creating spatial index for ' + f'{property_assessment_layer_name} is completed.') -# For carrying out pairwise clip (clip in QGIS) on property assessment data with -# Clipped and fixed NRCan data as the overlay, we need to split the latter. -# This is being done to improve the performance of the clipping task. Otherwise, the task crashes the program. -# One can decide on the number of this divisions by assigning a number to num_layers. I assume, a number way bigger than +# For carrying out pairwise clip (clip in QGIS) on +# property assessment data with Clipped and +# fixed NRCan data as the overlay, we need to split the latter. +# This is being done to improve the performance of the clipping task. +# Otherwise, the task crashes the program. +# One can decide on the number of this divisions by assigning +# a number to num_layers. I assume, a number way bigger than # 20 can help the performance even more significantly (Will be tested). -output_layers_folder = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/splitted_clipped_nrcan' +output_layers_folder = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/splitted_clipped_nrcan' num_layers = 20 create_folders(output_layers_folder, num_layers) splitting_intervals = clipped_nrcan_length // num_layers for each in range(num_layers): - output_layer_path = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/splitted_clipped_nrcan/layer_{each}/layer_{each}.shp' + output_layer_path = f'C:/Users/a_adli/PycharmProjects/' \ + f'hydroquebec_archetype_gispy/data/' \ + f'output_data/splitted_clipped_nrcan/' \ + f'layer_{each}/layer_{each}.shp' splitting_params = {'INPUT': clipped_nrcan_layer, - 'EXPRESSION': f'$id >= {each * splitting_intervals} AND $id < {(each + 1) * splitting_intervals}\r\n', + 'EXPRESSION': f'$id >= {each * splitting_intervals} ' + f'AND $id < ' + f'{(each + 1) * splitting_intervals}\r\n', 'OUTPUT': output_layer_path} processing.run("native:extractbyexpression", splitting_params) # Creating spatial index for each new layer - create_index_params = {'INPUT': output_layer_path, 'OUTPUT': 'Output'} - processing.run("native:createspatialindex", create_index_params) + params_create_index_layers = {'INPUT': output_layer_path, + 'OUTPUT': 'Output'} + processing.run("native:createspatialindex", params_create_index_layers) -# Putting the remaining features in one last layer (So, overall we're going to have [num_layers + 1] layers). +# Putting the remaining features in one last layer +# (So, overall we're going to have [num_layers + 1] layers). remaining_features = num_layers -os.makedirs(f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/splitted_clipped_nrcan/layer_{remaining_features}') -output_layer_path = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/splitted_clipped_nrcan/layer_{remaining_features}/layer_{remaining_features}.shp' +os.makedirs(f'C:/Users/a_adli/PycharmProjects/' + f'hydroquebec_archetype_gispy/data/' + f'output_data/splitted_clipped_nrcan/layer_{remaining_features}') +output_layer_path = f'C:/Users/a_adli/PycharmProjects/' \ + f'hydroquebec_archetype_gispy/data/' \ + f'output_data/splitted_clipped_nrcan/' \ + f'layer_{remaining_features}/' \ + f'layer_{remaining_features}.shp' last_splitting_params = {'INPUT': clipped_nrcan_layer, - 'EXPRESSION': f'$id >= {num_layers * splitting_intervals}\r\n', + 'EXPRESSION': + f'$id >= {num_layers * splitting_intervals}\r\n', 'OUTPUT': output_layer_path} processing.run("native:extractbyexpression", last_splitting_params) # Create spatial index for the last partition (layer) -create_index_params = {'INPUT': output_layer_path, 'OUTPUT': 'Output'} -processing.run("native:createspatialindex", create_index_params) +params_create_index_last = {'INPUT': output_layer_path, + 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", params_create_index_last) # Now we clip the property assessment with each of the partitions (layers) # from the last process. The process outputs the pairwise clipped version of -# the Property Assessment data in num_layers (the number is 21 in the first run) number of individual layers +# the Property Assessment data in num_layers (the number is 21 +# in the first run) number of individual layers # First we make the folders for each clipping process -clipped_layers_folder = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/clipped_property_assessment_partitions' -num_clipped_layers = 21 +clipped_layers_folder = 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/clipped_property_assessment_partitions' +num_clipped_layers = num_layers + 1 create_folders(clipped_layers_folder, num_clipped_layers) -# Through a for loop, we clip the Property Assessment layer by all the individual overlays +# Through a for loop, we clip the +# Property Assessment layer by all the individual overlays for each in range(num_clipped_layers): - clipping_layer = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/splitted_clipped_nrcan/layer_{each}/layer_{each}.shp' - clipped_layer = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/clipped_property_assessment_partitions/layer_{each}/layer_{each}.shp' + clipping_layer = f'C:/Users/a_adli/PycharmProjects/' \ + f'hydroquebec_archetype_gispy/data/' \ + f'output_data/splitted_clipped_nrcan/' \ + f'layer_{each}/layer_{each}.shp' + clipped_layer = f'C:/Users/a_adli/PycharmProjects/' \ + f'hydroquebec_archetype_gispy/data/' \ + f'output_data/clipped_property_assessment_partitions/' \ + f'layer_{each}/layer_{each}.shp' - pairwise_clipping_params = {'INPUT': property_assessment_layer, 'OVERLAY': clipping_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_layer} + pairwise_clipping_params = {'INPUT': property_assessment_layer, + 'OVERLAY': clipping_layer, + 'FILTER_EXPRESSION': '', + 'FILTER_EXTENT': None, + 'OUTPUT': clipped_layer} processing.run("native:clip", pairwise_clipping_params) # Creating spatial index for each new layer - create_index_params = {'INPUT': clipped_layer, 'OUTPUT': 'Output'} - processing.run("native:createspatialindex", create_index_params) + params_create_index_clips = {'INPUT': clipped_layer, + 'OUTPUT': 'Output'} + processing.run("native:createspatialindex", params_create_index_clips) print("Pairwise Clipping is completed.") @@ -177,7 +261,10 @@ print("Pairwise Clipping is completed.") # First we extract all the .shp files (clipped layers) from each folder pairwise_clipped_layers_path = find_shp_files(clipped_layers_folder) -pairwise_clipped_property_assessment_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/pairwise_clipped_property_assessment/pairwise_clipped.shp' +pairwise_clipped_property_assessment_layer = \ + 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/pairwise_clipped_property_assessment/pairwise_clipped.shp' merging_params = {'LAYERS': pairwise_clipped_layers_path, 'CRS': None, @@ -186,12 +273,16 @@ merging_params = {'LAYERS': pairwise_clipped_layers_path, processing.run("native:mergevectorlayers", merging_params) # Create spatial index for the pairwise clipped Property Assessment -create_index_params = {'INPUT': pairwise_clipped_property_assessment_layer, 'OUTPUT': 'Output'} -processing.run("native:createspatialindex", create_index_params) +params_create_index_pairwised = \ + {'INPUT': pairwise_clipped_property_assessment_layer, 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", params_create_index_pairwised) -pairwise_clipped_property_assessment, pairwise_clipped_property_assessment_name = \ - load_layer(pairwise_clipped_property_assessment_layer, 'Pairwise Clipped Property Assessment Layer') -print(f'{pairwise_clipped_property_assessment_name} data count: {pairwise_clipped_property_assessment.featureCount()}') +pairwise_clipped_property_assessment, \ + pairwise_clipped_property_assessment_name = \ + load_layer(pairwise_clipped_property_assessment_layer, + 'Pairwise Clipped Property Assessment Layer') +print(f'{pairwise_clipped_property_assessment_name} ' + f'data count: {pairwise_clipped_property_assessment.featureCount()}') # ----- # Delete path and layer fields (This is going to be added after testing the whole program). @@ -199,29 +290,41 @@ print(f'{pairwise_clipped_property_assessment_name} data count: {pairwise_clippe # In QGIS spatial join is named Join Attributes by Location # Spatial join Pairwise Clipped Property Assessment with Clipped NRCan -property_assessment_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/property_join_nrcan/property_join_nrcan.shp' +property_assessment_nrcan_layer = \ + 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/property_join_nrcan/property_join_nrcan.shp' -spatial_join_nrcan_params = {'INPUT': pairwise_clipped_property_assessment_layer, - 'PREDICATE': [0], - 'JOIN': clipped_nrcan_layer, - 'JOIN_FIELDS': [], - 'METHOD': 0, - 'DISCARD_NONMATCHING': False, - 'PREFIX': '', - 'OUTPUT': property_assessment_nrcan_layer} +spatial_join_nrcan_params = \ + {'INPUT': pairwise_clipped_property_assessment_layer, + 'PREDICATE': [0], + 'JOIN': clipped_nrcan_layer, + 'JOIN_FIELDS': [], + 'METHOD': 0, + 'DISCARD_NONMATCHING': False, + 'PREFIX': '', + 'OUTPUT': property_assessment_nrcan_layer} feedback = QgsProcessingFeedback() -processing.run('native:joinattributesbylocation', spatial_join_nrcan_params, feedback=feedback) +processing.run('native:joinattributesbylocation', + spatial_join_nrcan_params, feedback=feedback) -create_index_params = {'INPUT': property_assessment_nrcan_layer, 'OUTPUT': 'Output'} -processing.run("native:createspatialindex", create_index_params) +params_create_index_joined_nrcan = \ + {'INPUT': property_assessment_nrcan_layer, + 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", params_create_index_joined_nrcan) property_assessment_nrcan, property_assessment_nrcan_name = \ - load_layer(property_assessment_nrcan_layer, 'Property Assessment Layer Joined with NRCan') -print(f'{property_assessment_nrcan_name} data count: {property_assessment_nrcan.featureCount()}') + load_layer(property_assessment_nrcan_layer, + 'Property Assessment Layer Joined with NRCan') +print(f'{property_assessment_nrcan_name} ' + f'data count: {property_assessment_nrcan.featureCount()}') # Spatial join Pairwise Clipped (joined with NRCan) Property Assessment layer with Clipped GeoIndex layer -property_assessment_nrcan_geo_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/propertynrcan_join_geo/propertynrcan_join_geo.shp' +property_assessment_nrcan_geo_layer = \ + 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/propertynrcan_join_geo/propertynrcan_join_geo.shp' spatial_join_nrcan_params = {'INPUT': property_assessment_nrcan_layer, @@ -234,34 +337,47 @@ spatial_join_nrcan_params = {'INPUT': property_assessment_nrcan_layer, 'OUTPUT': property_assessment_nrcan_geo_layer} feedback = QgsProcessingFeedback() -processing.run('native:joinattributesbylocation', spatial_join_nrcan_params, feedback=feedback) +processing.run('native:joinattributesbylocation', + spatial_join_nrcan_params, feedback=feedback) -create_index_params = {'INPUT': property_assessment_nrcan_geo_layer, 'OUTPUT': 'Output'} +create_index_params = \ + {'INPUT': property_assessment_nrcan_geo_layer, + 'OUTPUT': 'Output'} processing.run("native:createspatialindex", create_index_params) property_assessment_nrcan_geo, property_assessment_nrcan_geo_name = \ - load_layer(property_assessment_nrcan_geo_layer, 'Property Assessment Layer Joined with NRCan') -print(f'{property_assessment_nrcan_geo_name} data count: {property_assessment_nrcan_geo.featureCount()}') + load_layer(property_assessment_nrcan_geo_layer, + 'Property Assessment Layer Joined with NRCan') +print(f'{property_assessment_nrcan_geo_name} ' + f'data count: {property_assessment_nrcan_geo.featureCount()}') # --- # There are four steps that will be added later after testing the program: -# - Aligning GeoIndex layer/features with Property Assessment (We should, firstly, make sure about its benefit) +# - Aligning GeoIndex layer/features with Property Assessment +# (We should, firstly, make sure about its benefit) # - Count overlapping features # - Summarize within # - Adding the summarize-within field with a spatial join # --- # In QGIS Delete Identical is named Delete Duplicates -property_nrcan_geo_deleted_duplicates_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/output_data/deleted_duplicates_property_and_all/delete_duplicates.shp' +property_nrcan_geo_deleted_duplicates_layer = \ + 'C:/Users/a_adli/PycharmProjects/' \ + 'hydroquebec_archetype_gispy/data/' \ + 'output_data/deleted_duplicates_property_and_all/delete_duplicates.shp' delete_duplicates_params = {'INPUT': property_assessment_nrcan_geo_layer, 'OUTPUT': property_nrcan_geo_deleted_duplicates_layer} processing.run("native:deleteduplicategeometries", delete_duplicates_params) -create_index_params = {'INPUT': property_nrcan_geo_deleted_duplicates_layer, 'OUTPUT': 'Output'} +create_index_params = {'INPUT': property_nrcan_geo_deleted_duplicates_layer, + 'OUTPUT': 'Output'} processing.run("native:createspatialindex", create_index_params) -property_nrcan_geo_deleted_duplicates, property_nrcan_geo_deleted_duplicates_name = \ - load_layer(property_nrcan_geo_deleted_duplicates_layer, 'Property Assessment Layer Joined with NRCan') -print(f'{property_nrcan_geo_deleted_duplicates_name} data count: {property_nrcan_geo_deleted_duplicates.featureCount()}') +property_nrcan_geo_deleted_duplicates, \ + property_nrcan_geo_deleted_duplicates_name = \ + load_layer(property_nrcan_geo_deleted_duplicates_layer, + 'Property Assessment Layer Joined with NRCan') +print(f'{property_nrcan_geo_deleted_duplicates_name} ' + f'data count: {property_nrcan_geo_deleted_duplicates.featureCount()}') qgs.exitQgis() \ No newline at end of file