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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/hillshade.py
Expand Up @@ -120,7 +120,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 = ['hillshade']
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
arguments.append(inLayer.source())
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/merge.py
Expand Up @@ -101,7 +101,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'merge.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
layers = self.parameterAsLayerList(parameters, self.INPUT, context)
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/nearblack.py
Expand Up @@ -89,7 +89,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', 'nearblack.png'))

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

arguments = []
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ogr2ogr.py
Expand Up @@ -71,7 +71,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)
options = self.parameterAsString(parameters, self.OPTIONS, context)
outFile = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
Expand Down
12 changes: 3 additions & 9 deletions python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py
Expand Up @@ -60,7 +60,6 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm):

def __init__(self):
GdalAlgorithm.__init__(self)
self.processing = False

def dbConnectionNames(self):
settings = QgsSettings()
Expand Down Expand Up @@ -120,15 +119,10 @@ def displayName(self):
def group(self):
return self.tr('Vector miscellaneous')

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

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
connection = self.DB_CONNECTIONS[self.getParameterValue(self.DATABASE)]
uri = uri_from_name(connection)
if self.processing:
if executing:
# to get credentials input when needed
uri = GeoDB(uri=uri).uri

Expand Down Expand Up @@ -162,7 +156,7 @@ def getConsoleCommands(self, parameters, context, feedback):
arguments.append('-f')
arguments.append('PostgreSQL')
arguments.append('PG:"')
for token in uri.connectionInfo(self.processing).split(' '):
for token in uri.connectionInfo(executing).split(' '):
arguments.append(token)
arguments.append('active_schema={}'.format(schema or 'public'))
arguments.append('"')
Expand Down
Expand Up @@ -172,7 +172,7 @@ def processAlgorithm(self, parameters, context, feedback):
GdalAlgorithm.processAlgorithm(parameters, None, self)
self.processing = False

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
connection = self.getParameterValue(self.DATABASE)
uri = uri_from_name(connection)
if self.processing:
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/ogrinfo.py
Expand Up @@ -68,7 +68,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):
arguments = ['ogrinfo']
arguments.append('-al')

Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/gdal/pct2rgb.py
Expand Up @@ -74,7 +74,7 @@ def group(self):
def icon(self):
return QIcon(os.path.join(pluginPath, 'images', 'gdaltools', '8-to-24-bits.png'))

def getConsoleCommands(self, parameters, context, feedback):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
inLayer = self.parameterAsRasterLayer(parameters, self.INPUT, context)
arguments.append(inLayer.source())
Expand Down

0 comments on commit 96c7e6e

Please sign in to comment.