Pawel Netzel - software
Repositories
Help
Report an Issue
plTools
Code
Commits
Branches
Tags
Search
Tree:
4406deb
Branches
Tags
master
plTools
plTools_plugin
algo_plclump4p.py
Initial commit
netzel
commited
4406deb
at 2024-02-21 23:00:39
algo_plclump4p.py
Blame
History
Raw
# -*- coding: utf-8 -*- """ /*************************************************************************** plTools A QGIS plugin The plugin adds a set of algorithms from plTools Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/ ------------------- begin : 2024-01-10 copyright : (C) 2024 by Pawel Netzel email : pawel@netzel.pl ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ """ __author__ = 'Pawel Netzel' __date__ = '2024-01-10' __copyright__ = '(C) 2024 by Pawel Netzel' # This will get replaced with a git SHA1 when you do a git archive __revision__ = '$Format:%H$' from qgis.PyQt.QtCore import QCoreApplication from qgis.core import (QgsProcessing, QgsProcessingAlgorithm, QgsProcessingException, QgsProcessingParameterNumber, QgsProcessingParameterBoolean, QgsProcessingParameterRasterDestination, QgsProcessingParameterRasterLayer) from .algo_base import plToolsBaseAlgorithm class clump4p_Algorithm(plToolsBaseAlgorithm): COMMAND = 'plclump4p' OUTPUT = 'OUTPUT' INPUT = 'INPUT' QUEEN = 'QUEEN' THREADS = 'THREADS' TEMP = 'TEMP' def initAlgorithm(self, config): super().initAlgorithm(config) self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT,self.tr('Input raster layer'))) if self.isLinux: self.addParameter(QgsProcessingParameterBoolean(self.QUEEN,self.tr('Eight directional merging'),defaultValue=False)) self.addParameter(QgsProcessingParameterBoolean(self.TEMP,self.tr('Current directory will be used for temporary files'),defaultValue=False)) self.addParameter(QgsProcessingParameterNumber(self.THREADS,self.tr('Number of threads'),defaultValue=1,optional=True)) self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT,self.tr('Clumped layer'))) def processAlgorithm(self, parameters, context, feedback): arguments = [self.COMMAND] inp = self.parameterAsRasterLayer(parameters, self.INPUT, context) if inp: arguments.append('-i') arguments.append(inp.source()) queen = self.parameterAsBoolean(parameters, self.QUEEN, context) if queen: arguments.append('-8') if self.isLinux: temp = self.parameterAsBoolean(parameters, self.TEMP, context) if temp: arguments.append('-l') else: arguments.append('-l') thr = self.parameterAsInt(parameters, self.THREADS, context) if thr: arguments.append('-t') arguments.append(str(thr)) output = self.parameterAsOutputLayer(parameters,self.OUTPUT,context) arguments.append('-o') arguments.append(output) self.runplTools(arguments, feedback) return {self.OUTPUT: output} def name(self): return 'Clumping categorical raster' def groupId(self): return '' def createInstance(self): return clump4p_Algorithm() def shortHelpString(self): return ''' plClump4p applies a divide-and-conquer technique and parallel processing to a standard two-scan algorithm of labelled connected components. Initially, the solution was a variant of a standard CCL algorithm implemented as r.clump in GRASS GIS, which was available as r.clump3p. The algorithm was described in the <a href="https://doi.org/10.1016/j.cageo.2013.05.014">paper</a>. plClump4p is a new, standalone, improved algorithm implementation from r.clump3p based on GDAL and OpenMP libraries. '''