Skip to content

Commit

Permalink
[processing][gdal] Cleanup some code, add method to customise
Browse files Browse the repository at this point in the history
generated command based on whether the algorithm is actually
executing or just being displayed in the UI as a command
  • Loading branch information
nyalldawson committed Dec 8, 2017
1 parent 7584bf1 commit 96c7e6e
Show file tree
Hide file tree
Showing 53 changed files with 56 additions and 62 deletions.
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/AssignProjection.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def icon(self):
def group(self):
return self.tr('Raster projections')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fileName = inLayer.source()

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/Buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ClipRasterByExtent.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def icon(self):
def commandName(self):
return "gdal_translate"

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
bbox = self.parameterAsExtent(parameters, self.EXTENT, context, inLayer.crs())
nodata = self.parameterAsDouble(parameters, self.NODATA, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ClipRasterByMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def icon(self):
def group(self):
return self.tr('Raster extraction')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)

maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ClipVectorByExtent.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
source = self.parameterAsSource(parameters, self.INPUT, context)
extent = self.parameterAsExtent(parameters, self.EXTENT, context, source.sourceCrs())
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ClipVectorByMask.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer, inLayerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
maskLayer, maskLayerName = self.getOgrCompatibleSource(self.MASK, parameters, context, feedback)
options = self.parameterAsString(parameters, self.OPTIONS, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ColorRelief.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['color-relief']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
arguments.append(inLayer.source())
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/Dissolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ExecuteSql.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
sql = self.parameterAsString(parameters, self.SQL, context)
options = self.parameterAsString(parameters, self.OPTIONS, context)
Expand Down
4 changes: 2 additions & 2 deletions python/plugins/processing/algs/gdal/GdalAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def createInstance(self, config={}):
def createCustomParametersWidget(self, parent):
return GdalAlgorithmDialog(self)

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
return None

def getOgrCompatibleSource(self, parameter_name, parameters, context, feedback):
Expand Down Expand Up @@ -94,7 +94,7 @@ def setOutputValue(self, name, value):
self.output_values[name] = value

def processAlgorithm(self, parameters, context, feedback):
commands = self.getConsoleCommands(parameters, context, feedback)
commands = self.getConsoleCommands(parameters, context, feedback, executing=True)
GdalUtils.runGdal(commands, feedback)

# auto generate outputs
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def parametersHaveChanged(self):
self.text.setPlainText('')
return

commands = self.alg.getConsoleCommands(parameters, context, feedback)
commands = self.alg.getConsoleCommands(parameters, context, feedback, executing=False)
commands = [c for c in commands if c not in ['cmd.exe', '/C ']]
self.text.setPlainText(" ".join(commands))
except AlgorithmDialogBase.InvalidParameterValue as e:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GridAverage.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GridDataMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def icon(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GridInverseDistance.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GridLinear.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/GridNearestNeighbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'grid.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)

arguments = ['-l']
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/OffsetCurve.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/OgrToPostGis.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def getConnectionString(self, parameters, context):
arguments.append('user=' + user)
return GdalUtils.escapeAndJoin(arguments)

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsSource(parameters, self.INPUT, context)
ogrLayer, layername = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
shapeEncoding = self.parameterAsString(parameters, self.SHAPE_ENCODING, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/OneSideBuffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
geometry = self.parameterAsString(parameters, self.GEOMETRY, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/PointsAlongLines.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def group(self):
def commandName(self):
return 'ogr2ogr'

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
fields = self.parameterAsSource(parameters, self.INPUT, context).fields()
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback)
distance = self.parameterAsDouble(parameters, self.DISTANCE, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/aspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = ['aspect']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
arguments.append(inLayer.source())
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/buildvrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def icon(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-resolution')
arguments.append(self.RESOLUTION_OPTIONS[self.parameterAsEnum(parameters, self.RESOLUTION, context)])
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def icon(self):
def group(self):
return self.tr('Raster extraction')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fieldName = self.parameterAsString(parameters, self.FIELD_NAME, context)
nodata = self.parameterAsDouble(parameters, self.NODATA, context)
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/extractprojection.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def icon(self):
def group(self):
return self.tr('Raster projections')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
return ["extractprojection"]

def processAlgorithm(self, parameters, context, feedback):
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/fillnodata.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def displayName(self):
def group(self):
return self.tr('Raster analysis')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-md')
arguments.append(str(self.parameterAsInt(parameters, self.DISTANCE, context)))
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []

arguments.append('-p')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdal2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def displayName(self):
def group(self):
return self.tr('Raster conversion')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments = []
arguments.append('-band')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdaladdo.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-overview.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
fileName = inLayer.source()

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdalcalc.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def displayName(self):
def group(self):
return self.tr('Raster miscellaneous')

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.getOutputValue(self.OUTPUT)
extra = self.getParameterValue(self.EXTRA)
if extra is not None:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdalinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'raster-info.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
if self.parameterAsBool(parameters, self.MIN_MAX, context):
arguments.append('-mm')
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/gdaltindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'tiles.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
input_layers = self.parameterAsLayerList(parameters, self.LAYERS, context)
crs_field = self.parameterAsString(parameters, self.CRS_FIELD_NAME, context)
crs_format = self.parameterAsEnum(parameters, self.CRS_FORMAT, context)
Expand Down