def processAlgorithm(self, parameters, context, feedback): """ Here is where the processing itself takes place. """ layerHandler = LayerHandler() inputLyr = self.parameterAsVectorLayer( parameters, self.INPUT, context ) onlySelected = self.parameterAsBool( parameters, self.SELECTED, context ) attributeBlackList = self.parameterAsFields( parameters, self.ATTRIBUTE_BLACK_LIST, context ) ignoreVirtual = self.parameterAsBool( parameters, self.IGNORE_VIRTUAL_FIELDS, context ) ignorePK = self.parameterAsBool( parameters, self.IGNORE_PK_FIELDS, context ) layerHandler.mergeLinesOnLayer( inputLyr, feedback=feedback, onlySelected=onlySelected, ignoreVirtualFields=ignoreVirtual, attributeBlackList=attributeBlackList, excludePrimaryKeys=ignorePK ) return {self.OUTPUT: inputLyr}
def processAlgorithm(self, parameters, context, feedback): """ Here is where the processing itself takes place. """ layerHandler = LayerHandler() algRunner = AlgRunner() layerHandler = LayerHandler() inputLyr = self.parameterAsVectorLayer( parameters, self.INPUT, context ) onlySelected = self.parameterAsBool( parameters, self.SELECTED, context ) tol = self.parameterAsDouble( parameters, self.TOLERANCE, context ) attributeBlackList = self.parameterAsFields( parameters, self.ATTRIBUTE_BLACK_LIST, context ) ignoreVirtual = self.parameterAsBool( parameters, self.IGNORE_VIRTUAL_FIELDS, context ) ignorePK = self.parameterAsBool( parameters, self.IGNORE_PK_FIELDS, context ) layerHandler.mergeLinesOnLayer( inputLyr, feedback=feedback, onlySelected=onlySelected, ignoreVirtualFields=ignoreVirtual, attributeBlackList=attributeBlackList, excludePrimaryKeys=ignorePK ) #aux layer multiStepFeedback = QgsProcessingMultiStepFeedback(8, feedback) multiStepFeedback.setCurrentStep(0) if onlySelected: multiStepFeedback.pushInfo(self.tr('Building auxiliar layer...')) coverage = layerHandler.createAndPopulateUnifiedVectorLayer( [inputLyr], geomType=QgsWkbTypes.MultiPolygon, onlySelected=onlySelected, feedback=multiStepFeedback ) else: coverage = inputLyr #dangles multiStepFeedback.setCurrentStep(1) multiStepFeedback.pushInfo(self.tr('Identifying dangles on {layer}...').format(layer=coverage.name())) dangleLyr = algRunner.runIdentifyDangles( inputLayer=coverage, searchRadius=tol, context=context, feedback=multiStepFeedback, onlySelected=False ) #filter dangles multiStepFeedback.setCurrentStep(2) layerHandler.filterDangles( dangleLyr, tol, feedback=multiStepFeedback ) #snap layer to dangles multiStepFeedback.setCurrentStep(3) multiStepFeedback.pushInfo(self.tr('Snapping layer {layer} to dangles...').format(layer=coverage.name())) algRunner.runSnapLayerOnLayer( coverage, dangleLyr, tol, context, feedback=multiStepFeedback, onlySelected=False, #this is done due to the aux layer usage behavior=0 ) #inner layer snap multiStepFeedback.setCurrentStep(4) multiStepFeedback.pushInfo(self.tr('Snapping layer {layer} with {layer}...').format(layer=coverage.name())) algRunner.runSnapLayerOnLayer( coverage, coverage, tol, context, feedback=multiStepFeedback, onlySelected=False, #this is done due to the aux layer usage behavior=0 ) #clean to break lines multiStepFeedback.setCurrentStep(5) multiStepFeedback.pushInfo(self.tr('Running clean on {layer}...').format(layer=coverage.name())) multiStepFeedback.pushInfo(self.tr('Running clean on unified layer...')) cleanedCoverage, error = algRunner.runClean( coverage, [ algRunner.RMSA, algRunner.Break, algRunner.RmDupl, algRunner.RmDangle ], context, returnError=True, snap=snap, minArea=minArea, feedback=multiStepFeedback ) #remove duplicated features multiStepFeedback.setCurrentStep(6) multiStepFeedback.pushInfo(self.tr('Removing duplicated features from {layer}...').format(layer=coverage.name())) algRunner.runRemoveDuplicatedFeatures( inputLyr=cleanedCoverage, context=context, onlySelected=False, attributeBlackList=attributeBlackList, excludePrimaryKeys=excludePrimaryKeys, ignorePK=ignorePK, ignoreVirtual=ignoreVirtual ) #merging lines with same attributes multiStepFeedback.setCurrentStep(6) multiStepFeedback.pushInfo(self.tr('Merging lines from {layer} with same attribute set...').format(layer=coverage.name())) multiStepFeedback.setCurrentStep(7) multiStepFeedback.pushInfo(self.tr('Updating original layers...')) layerHandler.updateOriginalLayersFromUnifiedLayer( [inputLyr], coverage, feedback=multiStepFeedback, onlySelected=onlySelected ) return {self.INPUTLAYERS : inputLyrList}