125 lines
5.2 KiB
Python
125 lines
5.2 KiB
Python
from scrub_layer_class import *
|
|
from basic_functions import *
|
|
|
|
|
|
class ScrubMTL:
|
|
def __init__(self, qgis_path, nrcan, geo_index, property_assessment,
|
|
montreal_boundary, output_paths_dir):
|
|
self.qgis_path = qgis_path
|
|
self.nrcan = self.initialize_layer(nrcan, 'NRCan')
|
|
self.geo_index = self.initialize_layer(geo_index, 'GeoIndex')
|
|
self.property_assessment = \
|
|
self.initialize_layer(property_assessment, 'Property Assessment')
|
|
self.montreal_boundary = montreal_boundary
|
|
self.output_paths_dir = output_paths_dir
|
|
self.output_paths = {
|
|
'Fixed NRCan': '',
|
|
'Fixed GeoIndex': '',
|
|
'Clipped Fixed GeoIndex': '',
|
|
'Splitted NRCan': '',
|
|
'Pairwise Clipped Property Assessment Partitions': '',
|
|
'Pairwise Clipped Merged Property Assessment': '',
|
|
'Property Assessment and NRCan': '',
|
|
'Property Assessment and NRCan and GeoIndex': '',
|
|
'Deleted Duplicates Layer': '',
|
|
'Singled Parts Layer': ''
|
|
}
|
|
|
|
@staticmethod
|
|
def merge_layers(layers_path, mered_layer_path):
|
|
merging_layers = find_shp_files(layers_path)
|
|
QgsApplication.processingRegistry().addProvider(QgsNativeAlgorithms())
|
|
|
|
params = {'LAYERS': merging_layers,
|
|
'CRS': None,
|
|
'OUTPUT': mered_layer_path}
|
|
|
|
processing.run("native:mergevectorlayers", params)
|
|
|
|
def generate_output_paths(self):
|
|
for path in self.output_paths.keys():
|
|
new_folder = path.lower().replace(' ', '_')
|
|
output_path = self.output_paths_dir + '/' + new_folder
|
|
os.mkdir(output_path)
|
|
self.output_paths[path] = output_path + f'/{new_folder}.shp'
|
|
|
|
def initialize_layer(self, layer_path, layer_name):
|
|
return ScrubLayer(self.qgis_path, layer_path, layer_name)
|
|
|
|
def process_nrcan(self):
|
|
print(f'Data Count of the NRCan layer: {self.nrcan.data_count}')
|
|
self.nrcan.create_spatial_index()
|
|
self.nrcan.fix_geometries(self.output_paths['Fixed NRCan'])
|
|
nrcan_fixed = \
|
|
self.initialize_layer(self.output_paths['Fixed NRCan'],
|
|
'Fixed NRCan')
|
|
nrcan_fixed.create_spatial_index()
|
|
print(f'Data Count of the NRCan layer ({nrcan_fixed.layer_name})'
|
|
f'after fixing geometries: {nrcan_fixed.layer.featureCount()}')
|
|
|
|
def process_geo_index(self):
|
|
print(f'Data Count of the GeoIndex layer: {self.geo_index.data_count}')
|
|
self.geo_index.create_spatial_index()
|
|
self.geo_index.fix_geometries(self.output_paths['Fixed GeoIndex'])
|
|
geo_index_fixed = \
|
|
self.initialize_layer(self.output_paths['Fixed GeoIndex'],
|
|
'Fixed GeoIndex')
|
|
geo_index_fixed.create_spatial_index()
|
|
print(f'Data Count of the GeoIndex layer ({geo_index_fixed.layer_name})'
|
|
f'after fixing geometries: {geo_index_fixed.layer.featureCount()}')
|
|
geo_index_fixed.clip_layer(self.montreal_boundary,
|
|
self.output_paths['Clipped Fixed GeoIndex'])
|
|
geo_index_clipped = \
|
|
self.initialize_layer(self.output_paths['Clipped Fixed GeoIndex'],
|
|
'Clipped Fixed GeoIndex')
|
|
geo_index_clipped.create_spatial_index()
|
|
print(f'Data Count of the {geo_index_fixed.layer_name} '
|
|
f'({geo_index_clipped.layer_name}) after clipping it '
|
|
f'based on the Montreal Boundary layer: '
|
|
f'{geo_index_clipped.layer.featureCount()}')
|
|
|
|
def process_property_assesment(self):
|
|
print(f'Data Count of the GeoIndex layer: '
|
|
f'{self.property_assessment.data_count}')
|
|
self.property_assessment.create_spatial_index()
|
|
|
|
def clip_with_several_overlays(self, input_layer_path, input_layer_name,
|
|
overlaying_layer_path, overlaying_layer_name,
|
|
number_of_overlays, splitted_layers_dir,
|
|
clipped_layers_dir):
|
|
"""This method clips using desired number of overlay layers
|
|
by splitting a big overlaying layer. It uses the ScrubLayer class
|
|
clip_layer method."""
|
|
overlaying_layer = \
|
|
self.initialize_layer(overlaying_layer_path, overlaying_layer_name)
|
|
input_layer = \
|
|
self.initialize_layer(input_layer_path, input_layer_name)
|
|
overlaying_layer.\
|
|
split_layer(number_of_overlays, splitted_layers_dir, self.qgis_path)
|
|
create_folders(clipped_layers_dir, number_of_overlays)
|
|
for overlay_layer_num in range(number_of_overlays):
|
|
splitted_overlay_layer_path = \
|
|
splitted_layers_dir + \
|
|
f'/layer_{overlay_layer_num}/layer_{overlay_layer_num}.shp'
|
|
clipped_layer_partition_path = \
|
|
clipped_layers_dir + \
|
|
f'/layer_{overlay_layer_num}/layer_{overlay_layer_num}.shp'
|
|
input_layer.clip_layer(splitted_overlay_layer_path,
|
|
clipped_layer_partition_path)
|
|
clipped_layer = \
|
|
self.initialize_layer(clipped_layer_partition_path,
|
|
f'clipped_layer_{overlay_layer_num}')
|
|
clipped_layer.create_spatial_index()
|
|
|
|
print('Pairwise Clipping is completed.')
|
|
|
|
def refine_heights(self):
|
|
pass
|
|
|
|
def remove_redundant_fields(self):
|
|
pass
|
|
|
|
def remove_records_by_area(self, area_limitation):
|
|
"""Area limitation can be assigned in the constructor"""
|
|
pass
|