diff --git a/mtl_buildings_workflow.py b/mtl_buildings_workflow.py index d8ff9cf..b3abe56 100644 --- a/mtl_buildings_workflow.py +++ b/mtl_buildings_workflow.py @@ -117,11 +117,11 @@ 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' - params = {'INPUT': clipped_nrcan_layer, - 'EXPRESSION': f'$id >= {each * splitting_intervals} AND $id < {(each + 1) * splitting_intervals}\r\n', - 'OUTPUT': output_layer_path} + splitting_params = {'INPUT': clipped_nrcan_layer, + 'EXPRESSION': f'$id >= {each * splitting_intervals} AND $id < {(each + 1) * splitting_intervals}\r\n', + 'OUTPUT': output_layer_path} - processing.run("native:extractbyexpression", params) + processing.run("native:extractbyexpression", splitting_params) # Creating spatian index for each new layer create_spatial_indext_params = {'INPUT': output_layer_path, 'OUTPUT': 'Output'} @@ -129,12 +129,42 @@ for each in range(num_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/aEndeavor/divided_all/layer_{remaining_features}') -output_layer_path = f'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/aEndeavor/divided_all/layer_{remaining_features}/layer_{remaining_features}.shp' -params = {'INPUT': clipped_nrcan_layer, - 'EXPRESSION': f'$id >= {num_layers * splitting_intervals}\r\n', - 'OUTPUT': output_layer_path} +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' +last_splitting_params = {'INPUT': clipped_nrcan_layer, + 'EXPRESSION': f'$id >= {num_layers * splitting_intervals}\r\n', + 'OUTPUT': output_layer_path} -processing.run("native:extractbyexpression", params) +processing.run("native:extractbyexpression", last_splitting_params) + +# Create spatial index for the last partition (layer) +create_spatial_indext_params = {'INPUT': output_layer_path, 'OUTPUT': 'Output'} +processing.run("native:createspatialindex", create_spatial_indext_params) + +# 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 + +# 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 +create_folders(clipped_layers_folder, num_clipped_layers) + +# 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' + + 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 spatian index for each new layer + create_spatial_indext_params = {'INPUT': clipped_layer, 'OUTPUT': 'Output'} + processing.run("native:createspatialindex", create_spatial_indext_params) + +print("Pairwise Clipping is completed.") + +# Finally, we merge all the clipped layers to make the +# pairwise clipped Property Assessment layer qgs.exitQgis() \ No newline at end of file