Fix the paths based on input output data folders
This commit is contained in:
parent
8d523bfc11
commit
c86f4dc966
@ -24,8 +24,8 @@ qgs.initQgis()
|
||||
# Add native algorithms provider
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
|
||||
# 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'
|
||||
# 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')
|
||||
|
||||
print(f'Loading {nrcan_name}')
|
||||
@ -33,7 +33,7 @@ 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/data/tests/python_fixed_05/py_fixes_05.shp'
|
||||
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}
|
||||
processing.run('native:fixgeometries', params_fixing_nrcan)
|
||||
|
||||
@ -42,8 +42,8 @@ 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/montreal_boundary|layername=Montreal_boundary'
|
||||
clipped_nrcan_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/clipped_nrcan_1/clipped_nrcan_1.shp'
|
||||
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'
|
||||
|
||||
params_clipping_nrcan = {'INPUT': fixed_nrcan_0, 'OVERLAY': clipping_montreal_boundary_layer, 'FILTER_EXPRESSION': '', 'FILTER_EXTENT': None, 'OUTPUT': clipped_nrcan_layer}
|
||||
processing.run("native:clip", params_clipping_nrcan)
|
||||
@ -57,18 +57,18 @@ print(f'{clipped_nrcan_name} data count: {clipped_nrcan.featureCount()}')
|
||||
# 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, 'OUTPUT': 'Output'}
|
||||
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/Geoindex_81670/mamh_usage_predo_2022_s_poly.shp'
|
||||
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()}')
|
||||
|
||||
# Fixing the GeoIndex layer geometries
|
||||
print(f'Fixing {geoindex_name} geometries')
|
||||
fixed_geoindex = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/fixed_geoindex_9/fix_geo_9.shp'
|
||||
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)
|
||||
|
||||
@ -77,66 +77,30 @@ print(f'{fixed_geoindex_name} 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/tests/clipped_geo_3/clipped_geo_3.shp'
|
||||
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_nrcan_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, 'OUTPUT': 'Output'}
|
||||
params_create_index_geoindex = {'INPUT': clipped_geoindex_layer, 'OUTPUT': 'Output'}
|
||||
processing.run("native:createspatialindex", params_create_index_geoindex)
|
||||
print(f'Creating spatial index for {clipped_geoindex_name} is completed.')
|
||||
|
||||
# Reading the Property Assessment (uniteevaluationfonciere) dataset
|
||||
property_assessment_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/uniteevaluationfonciere/uniteevaluationfonciere.shp'
|
||||
property_assessment_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/input_data/uniteevaluationfonciere/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()}')
|
||||
|
||||
# Creating spatial index fo the GeoIndex layer
|
||||
# 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.')
|
||||
|
||||
intersection_nrcan_property_layer = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/intersection_nrcan_property/intersection_nrcan_property.shp'
|
||||
|
||||
# A. Intersection by inputting NRCan and assigning property assessment as the overlay
|
||||
# (Three steps replace the pairwise clip where input is the property assessment and the overlay is the clipped nrcan)
|
||||
# We call these three steps A, B and C respectively
|
||||
params_intersection_nrcan_property_assessment = \
|
||||
{'INPUT': clipped_nrcan,
|
||||
'INPUT_FIELDS': [], 'OVERLAY_FIELDS': [], 'OVERLAY_FIELDS_PREFIX': '',
|
||||
'OUTPUT': intersection_nrcan_property_layer, 'GRID_SIZE': None}
|
||||
processing.run("native:intersection", params)
|
||||
|
||||
intersection_nrcan_property_read, intersection_nrcan_property_layer_name = load_layer(property_assessment_layer, 'Property Assesment')
|
||||
print(f'{intersection_nrcan_property_layer_name} data count: {intersection_nrcan_property_read.featureCount()}')
|
||||
|
||||
# Creating spatial index fo the result of the previous intersection
|
||||
params_create_index_intersection_nrcan = {'INPUT': intersection_nrcan_property_layer, 'OUTPUT': 'Output'}
|
||||
processing.run("native:createspatialindex", params_create_index_intersection_nrcan)
|
||||
print(f'Creating spatial index for {intersection_nrcan_property_layer_name} is completed.')
|
||||
|
||||
# B. Spatial Join (in QGIS: join attributes by location), with the NRCan as input
|
||||
# and the result of previous intersection as overlay
|
||||
output_layer_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/join_nrcan_intersected_nrcan/py_joined_12.shp'
|
||||
|
||||
params_spatial_join_nrcan_intersection = \
|
||||
{'INPUT': clipped_nrcan,
|
||||
'PREDICATE': [0],
|
||||
'JOIN': intersection_nrcan_property_layer,
|
||||
'JOIN_FIELDS': [],
|
||||
'METHOD': 0,
|
||||
'DISCARD_NONMATCHING': False,
|
||||
'PREFIX': '',
|
||||
'OUTPUT': output_layer_path}
|
||||
|
||||
feedback_spatial_join_nrcan_intersection = QgsProcessingFeedback()
|
||||
processing.run('native:joinattributesbylocation', params,
|
||||
feedback=feedback_spatial_join_nrcan_intersection)
|
||||
|
||||
|
||||
qgs.exitQgis()
|
Loading…
Reference in New Issue
Block a user