mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-15 00:04:00 -04:00
[processing] restore sieve algorithm
This commit is contained in:
parent
90308f33c0
commit
babc35d169
@ -45,6 +45,7 @@ from .pct2rgb import pct2rgb
|
||||
from .polygonize import polygonize
|
||||
from .rgb2pct import rgb2pct
|
||||
from .roughness import roughness
|
||||
from .sieve import sieve
|
||||
from .slope import slope
|
||||
from .translate import translate
|
||||
from .tpi import tpi
|
||||
@ -57,7 +58,6 @@ from .warp import warp
|
||||
# from .ClipByMask import ClipByMask
|
||||
# from .rasterize import rasterize
|
||||
# from .proximity import proximity
|
||||
# from .sieve import sieve
|
||||
# from .fillnodata import fillnodata
|
||||
# from .extractprojection import ExtractProjection
|
||||
# from .gdal2xyz import gdal2xyz
|
||||
@ -146,6 +146,7 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
polygonize(),
|
||||
rgb2pct(),
|
||||
roughness(),
|
||||
sieve(),
|
||||
slope(),
|
||||
translate(),
|
||||
tpi(),
|
||||
@ -157,7 +158,6 @@ class GdalAlgorithmProvider(QgsProcessingProvider):
|
||||
# ClipByMask(),
|
||||
# rasterize(),
|
||||
# proximity(),
|
||||
# sieve(),
|
||||
# fillnodata(),
|
||||
# ExtractProjection(),
|
||||
# gdal2xyz(),
|
||||
|
@ -16,8 +16,6 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from builtins import str
|
||||
from builtins import range
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
|
@ -16,7 +16,6 @@
|
||||
* *
|
||||
***************************************************************************
|
||||
"""
|
||||
from builtins import str
|
||||
|
||||
__author__ = 'Victor Olaya'
|
||||
__date__ = 'August 2012'
|
||||
@ -30,15 +29,13 @@ import os
|
||||
|
||||
from qgis.PyQt.QtGui import QIcon
|
||||
|
||||
from qgis.core import (QgsRasterFileWriter,
|
||||
QgsProcessingParameterRasterLayer,
|
||||
QgsProcessingParameterNumber,
|
||||
QgsProcessingParameterBoolean,
|
||||
QgsProcessingParameterRasterDestination)
|
||||
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
|
||||
|
||||
from processing.core.parameters import ParameterRaster
|
||||
from processing.core.parameters import ParameterSelection
|
||||
from processing.core.parameters import ParameterNumber
|
||||
from processing.core.outputs import OutputRaster
|
||||
|
||||
from processing.tools.system import isWindows
|
||||
|
||||
from processing.algs.gdal.GdalUtils import GdalUtils
|
||||
|
||||
pluginPath = os.path.split(os.path.split(os.path.dirname(__file__))[0])[0]
|
||||
@ -48,25 +45,29 @@ class sieve(GdalAlgorithm):
|
||||
|
||||
INPUT = 'INPUT'
|
||||
THRESHOLD = 'THRESHOLD'
|
||||
CONNECTIONS = 'CONNECTIONS'
|
||||
EIGHT_CONNECTEDNESS = 'EIGHT_CONNECTEDNESS'
|
||||
NO_MASK = 'NO_MASK'
|
||||
MASK_LAYER = 'MASK_LAYER'
|
||||
OUTPUT = 'OUTPUT'
|
||||
|
||||
PIXEL_CONNECTIONS = ['4', '8']
|
||||
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'sieve.png'))
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def initAlgorithm(self, config=None):
|
||||
self.addParameter(ParameterRaster(self.INPUT, self.tr('Input layer'), False))
|
||||
self.addParameter(ParameterNumber(self.THRESHOLD,
|
||||
self.tr('Threshold'), 0, 9999, 2))
|
||||
self.addParameter(ParameterSelection(self.CONNECTIONS,
|
||||
self.tr('Pixel connection'), self.PIXEL_CONNECTIONS, 0))
|
||||
self.addParameter(QgsProcessingParameterRasterLayer(self.INPUT, self.tr('Input layer')))
|
||||
self.addParameter(QgsProcessingParameterNumber(
|
||||
self.THRESHOLD, self.tr('Threshold'),
|
||||
type=QgsProcessingParameterNumber.Integer,
|
||||
minValue=0, maxValue=999999, defaultValue=10))
|
||||
self.addParameter(QgsProcessingParameterBoolean(
|
||||
self.EIGHT_CONNECTEDNESS, self.tr('Use 8-connectedness'),
|
||||
defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterBoolean(
|
||||
self.NO_MASK, self.tr('Do not use the default validity mask for the input band'),
|
||||
defaultValue=False))
|
||||
self.addParameter(QgsProcessingParameterRasterLayer(self.MASK_LAYER, self.tr('Validity mask'), optional=True))
|
||||
|
||||
self.addOutput(OutputRaster(self.OUTPUT, self.tr('Sieved')))
|
||||
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('Sieved')))
|
||||
|
||||
def name(self):
|
||||
return 'sieve'
|
||||
@ -77,22 +78,32 @@ class sieve(GdalAlgorithm):
|
||||
def group(self):
|
||||
return self.tr('Raster analysis')
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback):
|
||||
output = self.getOutputValue(self.OUTPUT)
|
||||
def icon(self):
|
||||
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'sieve.png'))
|
||||
|
||||
def getConsoleCommands(self, parameters, context, feedback):
|
||||
arguments = []
|
||||
arguments.append('-st')
|
||||
arguments.append(str(self.getParameterValue(self.THRESHOLD)))
|
||||
arguments.append(str(self.parameterAsInt(self.THRESHOLD)))
|
||||
|
||||
arguments.append('-' +
|
||||
self.PIXEL_CONNECTIONS[self.getParameterValue(
|
||||
self.CONNECTIONS)])
|
||||
if self.parameterAsBool(parameters, self.EIGHT_CONNECTEDNESS, context):
|
||||
arguments.append('-8')
|
||||
else:
|
||||
arguments.append('-4')
|
||||
|
||||
if self.parameterAsBool(parameters, self.NO_MASK, context):
|
||||
arguments.append('-nomask')
|
||||
|
||||
mask = self.parameterAsRasterLayer(parameters, self.INPUT, context)
|
||||
if mask:
|
||||
arguments.append('-mask {}'.format(mask.source()))
|
||||
|
||||
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
|
||||
arguments.append('-of')
|
||||
arguments.append(GdalUtils.getFormatShortNameFromFilename(output))
|
||||
arguments.append(QgsRasterFileWriter.driverForExtension(os.path.splitext(out)[1]))
|
||||
|
||||
arguments.append(self.getParameterValue(self.INPUT))
|
||||
arguments.append(output)
|
||||
arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
|
||||
arguments.append(out)
|
||||
|
||||
commands = []
|
||||
if isWindows():
|
||||
|
Loading…
x
Reference in New Issue
Block a user