Skip to content

Commit

Permalink
Port rgb2pct to new API
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 30, 2017
1 parent d0fea64 commit a29e378
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions python/plugins/processing/algs/gdal/GdalAlgorithmProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@
from .buildvrt import buildvrt
from .ColorRelief import ColorRelief
from .information import information
from .rgb2pct import rgb2pct
from .tri import tri
from .warp import warp
from .nearblack import nearblack
# from .rgb2pct import rgb2pct

# from .translate import translate
# from .pct2rgb import pct2rgb
# from .merge import merge
Expand Down Expand Up @@ -146,10 +147,11 @@ def loadAlgorithms(self):
ColorRelief(),
information(),
nearblack(),
rgb2pct(),
tri(),
warp(),
# translate(),
# rgb2pct(),
#
# pct2rgb(),
# merge(),
# polygonize(),
Expand Down
22 changes: 11 additions & 11 deletions python/plugins/processing/algs/gdal/rgb2pct.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

from qgis.PyQt.QtGui import QIcon

from qgis.core import (QgsProcessingParameterRasterLayer,
QgsProcessingParameterNumber,
QgsProcessingParameterRasterDestination)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.parameters import ParameterRaster
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

Expand All @@ -57,11 +57,11 @@ def __init__(self):
super().__init__()

def initAlgorithm(self, config=None):
self.addParameter(ParameterRaster(rgb2pct.INPUT,
self.tr('Input layer'), False))
self.addParameter(ParameterNumber(rgb2pct.NCOLORS,
self.tr('Number of colors'), 1, None, 2))
self.addOutput(OutputRaster(rgb2pct.OUTPUT, self.tr('RGB to PCT')))
self.addParameter(QgsProcessingParameterRasterLayer(rgb2pct.INPUT,
self.tr('Input layer'), optional=False))
self.addParameter(QgsProcessingParameterNumber(rgb2pct.NCOLORS,
self.tr('Number of colors'), minValue=1, defaultValue=2))
self.addParameter(QgsProcessingParameterRasterDestination(self.OUTPUT, self.tr('RGB to PCT')))

def name(self):
return 'rgbtopct'
Expand All @@ -72,11 +72,11 @@ def displayName(self):
def getConsoleCommands(self, parameters, context, feedback):
arguments = []
arguments.append('-n')
arguments.append(str(self.getParameterValue(rgb2pct.NCOLORS)))
arguments.append(str(self.parameterAsInt(parameters, rgb2pct.NCOLORS, context)))
arguments.append('-of')
out = self.getOutputValue(rgb2pct.OUTPUT)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
arguments.append(GdalUtils.getFormatShortNameFromFilename(out))
arguments.append(self.getParameterValue(rgb2pct.INPUT))
arguments.append(self.parameterAsRasterLayer(parameters, self.INPUT, context).source())
arguments.append(out)

if isWindows():
Expand Down

0 comments on commit a29e378

Please sign in to comment.