Skip to content
Permalink
Browse files

Push parameters into processAlgorithm and related functions

  • Loading branch information
nyalldawson committed Jun 5, 2017
1 parent f1c53c3 commit 4cb7d18b1ca1ecbe144571bf2c80dabb5941fbf2
Showing 314 changed files with 489 additions and 412 deletions.
@@ -80,8 +80,9 @@ def displayName(self):
def group(self):
return self.tr('Algorithms for vector layers')

def processAlgorithm(self, context, feedback):
def processAlgorithm(self, parameters, context, feedback):
"""Here is where the processing itself takes place.
:param parameters:
:param context:
"""

@@ -66,7 +66,7 @@ def icon(self):
def group(self):
return self.tr('Raster projections')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
fileName = self.getParameterValue(self.INPUT)
crs = self.getParameterValue(self.CRS)
output = self.getOutputValue(self.OUTPUT) # NOQA
@@ -83,7 +83,7 @@ def icon(self):
def group(self):
return self.tr('Raster extraction')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
out = self.getOutputValue(self.OUTPUT)
noData = self.getParameterValue(self.NO_DATA)
opts = self.getParameterValue(self.OPTIONS)
@@ -102,7 +102,7 @@ def icon(self):
def group(self):
return self.tr('Raster extraction')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
out = self.getOutputValue(self.OUTPUT)
mask = self.getParameterValue(self.MASK)
context = dataobjects.createContext()
@@ -70,7 +70,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['color-relief']
arguments.append(str(self.getParameterValue(self.INPUT)))
arguments.append(str(self.getParameterValue(self.COLOR_TABLE)))
@@ -58,8 +58,11 @@ def svgIconPath(self):
def createCustomParametersWidget(self, parent):
return GdalAlgorithmDialog(self)

def processAlgorithm(self, context, feedback):
commands = self.getConsoleCommands()
def getConsoleCommands(self, parameters):
return None

def processAlgorithm(self, parameters, context, feedback):
commands = self.getConsoleCommands(parameters)
layers = QgsProcessingUtils.compatibleVectorLayers(QgsProject.instance())
supported = QgsVectorFileWriter.supportedFormatExtensions()
for i, c in enumerate(commands):
@@ -96,7 +99,7 @@ def commandName(self):
output.setValue("dummy")
for param in self.parameters:
param.setValue("1")
name = self.getConsoleCommands()[0]
name = self.getConsoleCommands(parameters)[0]
if name.endswith(".py"):
name = name[:-3]
return name
@@ -111,7 +111,7 @@ def parametersHaveChanged(self):
for output in self.alg.destinationParameterDefinitions():
if parameters[output.name()] is None:
parameters[output.name()] = self.tr("[temporary file]")
commands = self.alg.getConsoleCommands()
commands = self.alg.getConsoleCommands(parameters)
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
self.text.setPlainText(" ".join(commands))
except AlgorithmDialogBase.InvalidParameterValue as e:
@@ -90,7 +90,7 @@ def icon(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -97,7 +97,7 @@ def icon(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -100,7 +100,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -88,7 +88,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['-l']
arguments.append(
os.path.basename(os.path.splitext(
@@ -74,7 +74,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['aspect']
arguments.append(str(self.getParameterValue(self.INPUT)))
output = str(self.getOutputValue(self.OUTPUT))
@@ -75,7 +75,7 @@ def icon(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = []
arguments.append('-resolution')
arguments.append(self.RESOLUTION_OPTIONS[self.getParameterValue(self.RESOLUTION)])
@@ -79,7 +79,7 @@ def icon(self):
def group(self):
return self.tr('Raster extraction')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
output = self.getOutputValue(self.OUTPUT_VECTOR)
interval = str(self.getParameterValue(self.INTERVAL))
fieldName = str(self.getParameterValue(self.FIELD_NAME))
@@ -62,10 +62,10 @@ def icon(self):
def group(self):
return self.tr('Raster projections')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
return ["extractprojection"]

def processAlgorithm(self, context, feedback):
def processAlgorithm(self, parameters, context, feedback):
rasterPath = self.getParameterValue(self.INPUT)
createPrj = self.getParameterValue(self.PRJ_FILE)

@@ -78,7 +78,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
output = self.getOutputValue(self.OUTPUT)

arguments = []
@@ -126,7 +126,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):

arguments = []

@@ -61,7 +61,7 @@ def displayName(self):
def group(self):
return self.tr('Raster conversion')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = []
arguments.append('-band')
arguments.append(str(self.getParameterValue(self.BAND)))
@@ -89,7 +89,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inFile = self.getParameterValue(self.INPUT)
clearOverviews = self.getParameterValue(self.CLEAN)
ovrFormat = self.getParameterValue(self.FORMAT)
@@ -106,7 +106,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
out = self.getOutputValue(self.OUTPUT)
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
@@ -71,7 +71,7 @@ def icon(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
fieldName = str(self.getParameterValue(self.FIELD_NAME))

arguments = []
@@ -83,7 +83,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ['hillshade']
arguments.append(str(self.getParameterValue(self.INPUT)))
arguments.append(str(self.getOutputValue(self.OUTPUT)))
@@ -69,7 +69,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = []
if self.getParameterValue(information.NOGCP):
arguments.append('-nogcp')
@@ -78,8 +78,8 @@ def getConsoleCommands(self):
arguments.append(self.getParameterValue(information.INPUT))
return ['gdalinfo', GdalUtils.escapeAndJoin(arguments)]

def processAlgorithm(self, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
output = self.getOutputValue(information.OUTPUT)
with open(output, 'w') as f:
f.write('<pre>')
@@ -87,7 +87,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = []
arguments.append('-ot')
arguments.append(self.TYPE[self.getParameterValue(self.RTYPE)])
@@ -70,7 +70,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = []
arguments.append('-o')
output = str(self.getOutputValue(self.OUTPUT))
@@ -72,7 +72,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
geometry = self.getParameterValue(self.GEOMETRY)
distance = self.getParameterValue(self.RADIUS)
@@ -120,7 +120,7 @@ def displayName(self):
def group(self):
return self.tr('Vector conversion')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]

@@ -83,7 +83,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
geometry = self.getParameterValue(self.GEOMETRY)
distance = self.getParameterValue(self.DISTANCE)
@@ -65,7 +65,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
clipLayer = self.getParameterValue(self.CLIP_LAYER)
@@ -65,7 +65,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
clipExtent = self.getParameterValue(self.CLIP_EXTENT)
@@ -89,7 +89,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
geometry = self.getParameterValue(self.GEOMETRY)
field = self.getParameterValue(self.FIELD)
@@ -71,7 +71,7 @@ def displayName(self):
def group(self):
return self.tr('Vector geoprocessing')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
layername = "'" + ogrLayerName(inLayer) + "'"
@@ -126,12 +126,12 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

def processAlgorithm(self, context, feedback):
def processAlgorithm(self, parameters, context, feedback):
self.processing = True
GdalAlgorithm.processAlgorithm(self, context, feedback)
GdalAlgorithm.processAlgorithm(parameters, self, context)
self.processing = False

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
connection = self.DB_CONNECTIONS[self.getParameterValue(self.DATABASE)]
uri = uri_from_name(connection)
if self.processing:
@@ -162,7 +162,7 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

def getConnectionString(self):
def getConnectionString(self, parameters):
host = self.getParameterValue(self.HOST)
port = self.getParameterValue(self.PORT)
user = self.getParameterValue(self.USER)
@@ -184,7 +184,7 @@ def getConnectionString(self):
arguments.append('user=' + user)
return GdalUtils.escapeAndJoin(arguments)

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
inLayer = self.getParameterValue(self.INPUT_LAYER)
ogrLayer = ogrConnectionString(inLayer)[1:-1]
shapeEncoding = self.getParameterValue(self.SHAPE_ENCODING)
@@ -229,7 +229,7 @@ def getConsoleCommands(self):
arguments.append('-f')
arguments.append('PostgreSQL')
arguments.append('PG:"')
arguments.append(self.getConnectionString())
arguments.append(self.getConnectionString(parameters))
arguments.append('"')
arguments.append(dimstring)
arguments.append(ogrLayer)
@@ -178,12 +178,12 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

def processAlgorithm(self, context, feedback):
def processAlgorithm(self, parameters, context, feedback):
self.processing = True
GdalAlgorithm.processAlgorithm(None, self)
GdalAlgorithm.processAlgorithm(parameters, None, self)
self.processing = False

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
connection = self.getParameterValue(self.DATABASE)
uri = uri_from_name(connection)
if self.processing:
@@ -61,7 +61,7 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

def getConsoleCommands(self):
def getConsoleCommands(self, parameters):
arguments = ["ogrinfo"]
arguments.append('-al')
if self.getParameterValue(self.SUMMARY_ONLY):
@@ -71,8 +71,8 @@ def getConsoleCommands(self):
arguments.append(conn)
return arguments

def processAlgorithm(self, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(), feedback)
def processAlgorithm(self, parameters, context, feedback):
GdalUtils.runGdal(self.getConsoleCommands(parameters), feedback)
output = self.getOutputValue(self.OUTPUT)
with open(output, 'w') as f:
f.write('<pre>')

0 comments on commit 4cb7d18

Please sign in to comment.
You can’t perform that action at this time.