Edit the workflow(mtl_buildings_workflow) & Add intersection and spatial join (joinAttributesByLocation)
This commit is contained in:
parent
3333b54182
commit
cca682871c
@ -88,13 +88,17 @@ 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.')
|
||||
|
||||
# Reading the Property Assessment (uniteevaluationfonciere) dataset
|
||||
uniteevaluationfonciere_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/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()}')
|
||||
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
|
||||
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.')
|
||||
|
||||
qgs.exitQgis()
|
@ -0,0 +1,31 @@
|
||||
# Join attributes by location in QGIS is the same as Spatial Join in ArcGIS
|
||||
|
||||
from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, QgsProcessingFeedback
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
import processing
|
||||
|
||||
# Set the path to QGIS installation
|
||||
QgsApplication.setPrefixPath('C:/Program Files/QGIS 3.34.1/apps/qgis', True)
|
||||
|
||||
# Initialize QGIS application
|
||||
qgs = QgsApplication([], False)
|
||||
qgs.initQgis()
|
||||
|
||||
|
||||
# Add native algorithms provider
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
|
||||
layer_1_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/new_tests/python_fixed_05/py_fixes_05.shp'
|
||||
layer_2_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/property_assessment/uniteevaluationfonciere.shp'
|
||||
output_layer_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/intersection_nrcan_property/intersection_nrcan_property.shp'
|
||||
|
||||
|
||||
params = {'INPUT': layer_1_path,
|
||||
'OVERLAY': layer_2_path,
|
||||
'INPUT_FIELDS': [], 'OVERLAY_FIELDS': [], 'OVERLAY_FIELDS_PREFIX': '',
|
||||
'OUTPUT': output_layer_path, 'GRID_SIZE': None}
|
||||
|
||||
processing.run("native:intersection", params)
|
||||
|
||||
# Exit QGIS application
|
||||
qgs.exitQgis()
|
@ -0,0 +1,36 @@
|
||||
# Join attributes by location in QGIS is the same as Spatial Join in ArcGIS
|
||||
|
||||
from qgis.core import QgsApplication, QgsVectorLayer, QgsProject, QgsProcessingFeedback
|
||||
from qgis.analysis import QgsNativeAlgorithms
|
||||
import processing
|
||||
|
||||
# Set the path to QGIS installation
|
||||
QgsApplication.setPrefixPath('C:/Program Files/QGIS 3.34.1/apps/qgis', True)
|
||||
|
||||
# Initialize QGIS application
|
||||
qgs = QgsApplication([], False)
|
||||
qgs.initQgis()
|
||||
|
||||
|
||||
# Add native algorithms provider
|
||||
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
||||
|
||||
layer_1_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_fixed_05/py_fixes_05.shp'
|
||||
layer_2_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/property_assessment/uniteevaluationfonciere.shp'
|
||||
output_layer_path = 'C:/Users/a_adli/PycharmProjects/hydroquebec_archetype_gispy/data/tests/python_joined_12/py_joined_12.shp'
|
||||
|
||||
|
||||
params = {'INPUT': layer_1_path,
|
||||
'PREDICATE': [0],
|
||||
'JOIN': layer_2_path,
|
||||
'JOIN_FIELDS': [],
|
||||
'METHOD': 0,
|
||||
'DISCARD_NONMATCHING': False,
|
||||
'PREFIX': '',
|
||||
'OUTPUT': output_layer_path}
|
||||
|
||||
feedback = QgsProcessingFeedback()
|
||||
processing.run('native:joinattributesbylocation', params, feedback=feedback)
|
||||
|
||||
# Exit QGIS application
|
||||
qgs.exitQgis()
|
Loading…
Reference in New Issue
Block a user