Skip to content
Permalink
Browse files

[processing][gdal] Cleanup some code, add method to customise

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 96c7e6e0a6e0aa46bf60fcac1c733901ec1b1770
Showing with 56 additions and 62 deletions.
  1. +1 −1 python/plugins/processing/algs/gdal/AssignProjection.py
  2. +1 −1 python/plugins/processing/algs/gdal/Buffer.py
  3. +1 −1 python/plugins/processing/algs/gdal/ClipRasterByExtent.py
  4. +1 −1 python/plugins/processing/algs/gdal/ClipRasterByMask.py
  5. +1 −1 python/plugins/processing/algs/gdal/ClipVectorByExtent.py
  6. +1 −1 python/plugins/processing/algs/gdal/ClipVectorByMask.py
  7. +1 −1 python/plugins/processing/algs/gdal/ColorRelief.py
  8. +1 −1 python/plugins/processing/algs/gdal/Dissolve.py
  9. +1 −1 python/plugins/processing/algs/gdal/ExecuteSql.py
  10. +2 −2 python/plugins/processing/algs/gdal/GdalAlgorithm.py
  11. +1 −1 python/plugins/processing/algs/gdal/GdalAlgorithmDialog.py
  12. +1 −1 python/plugins/processing/algs/gdal/GridAverage.py
  13. +1 −1 python/plugins/processing/algs/gdal/GridDataMetrics.py
  14. +1 −1 python/plugins/processing/algs/gdal/GridInverseDistance.py
  15. +1 −1 python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py
  16. +1 −1 python/plugins/processing/algs/gdal/GridLinear.py
  17. +1 −1 python/plugins/processing/algs/gdal/GridNearestNeighbor.py
  18. +1 −1 python/plugins/processing/algs/gdal/OffsetCurve.py
  19. +1 −1 python/plugins/processing/algs/gdal/OgrToPostGis.py
  20. +1 −1 python/plugins/processing/algs/gdal/OneSideBuffer.py
  21. +1 −1 python/plugins/processing/algs/gdal/PointsAlongLines.py
  22. +1 −1 python/plugins/processing/algs/gdal/aspect.py
  23. +1 −1 python/plugins/processing/algs/gdal/buildvrt.py
  24. +1 −1 python/plugins/processing/algs/gdal/contour.py
  25. +1 −1 python/plugins/processing/algs/gdal/extractprojection.py
  26. +1 −1 python/plugins/processing/algs/gdal/fillnodata.py
  27. +1 −1 python/plugins/processing/algs/gdal/gdal2tiles.py
  28. +1 −1 python/plugins/processing/algs/gdal/gdal2xyz.py
  29. +1 −1 python/plugins/processing/algs/gdal/gdaladdo.py
  30. +1 −1 python/plugins/processing/algs/gdal/gdalcalc.py
  31. +1 −1 python/plugins/processing/algs/gdal/gdalinfo.py
  32. +1 −1 python/plugins/processing/algs/gdal/gdaltindex.py
  33. +1 −1 python/plugins/processing/algs/gdal/hillshade.py
  34. +1 −1 python/plugins/processing/algs/gdal/merge.py
  35. +1 −1 python/plugins/processing/algs/gdal/nearblack.py
  36. +1 −1 python/plugins/processing/algs/gdal/ogr2ogr.py
  37. +3 −9 python/plugins/processing/algs/gdal/ogr2ogrtabletopostgislist.py
  38. +1 −1 python/plugins/processing/algs/gdal/ogr2ogrtopostgislist.py
  39. +1 −1 python/plugins/processing/algs/gdal/ogrinfo.py
  40. +1 −1 python/plugins/processing/algs/gdal/pct2rgb.py
  41. +1 −1 python/plugins/processing/algs/gdal/polygonize.py
  42. +1 −1 python/plugins/processing/algs/gdal/proximity.py
  43. +1 −1 python/plugins/processing/algs/gdal/rasterize.py
  44. +1 −1 python/plugins/processing/algs/gdal/rasterize_over.py
  45. +1 −1 python/plugins/processing/algs/gdal/retile.py
  46. +1 −1 python/plugins/processing/algs/gdal/rgb2pct.py
  47. +1 −1 python/plugins/processing/algs/gdal/roughness.py
  48. +1 −1 python/plugins/processing/algs/gdal/sieve.py
  49. +1 −1 python/plugins/processing/algs/gdal/slope.py
  50. +1 −1 python/plugins/processing/algs/gdal/tpi.py
  51. +1 −1 python/plugins/processing/algs/gdal/translate.py
  52. +1 −1 python/plugins/processing/algs/gdal/tri.py
  53. +1 −1 python/plugins/processing/algs/gdal/warp.py
@@ -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()

@@ -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)
@@ -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)
@@ -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)
@@ -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())
@@ -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)
@@ -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())
@@ -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)
@@ -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)
@@ -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):
@@ -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
@@ -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:
@@ -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']
@@ -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']
@@ -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']
@@ -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']
@@ -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']
@@ -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']
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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())
@@ -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)])
@@ -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)
@@ -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):
@@ -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)))
@@ -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')
@@ -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')
@@ -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()

@@ -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:
@@ -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')
@@ -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)
@@ -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())
@@ -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)

@@ -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 = []
@@ -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)
@@ -60,7 +60,6 @@ class Ogr2OgrTableToPostGisList(GdalAlgorithm):

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

def dbConnectionNames(self):
settings = QgsSettings()
@@ -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

@@ -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('"')
@@ -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:
@@ -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')

@@ -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())

0 comments on commit 96c7e6e

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