Skip to content
Permalink
Browse files

Thin out unneeded function calls

  • Loading branch information
dericke authored and nyalldawson committed Feb 20, 2021
1 parent da5f9db commit dcde81fb1b5d158ca6d0b6339768d88d3968ca12
Showing with 348 additions and 324 deletions.
  1. +5 −4 python/plugins/processing/algs/gdal/AssignProjection.py
  2. +7 −6 python/plugins/processing/algs/gdal/ClipRasterByExtent.py
  3. +12 −11 python/plugins/processing/algs/gdal/ClipVectorByExtent.py
  4. +10 −9 python/plugins/processing/algs/gdal/ClipVectorByMask.py
  5. +35 −33 python/plugins/processing/algs/gdal/Dissolve.py
  6. +6 −6 python/plugins/processing/algs/gdal/ExecuteSql.py
  7. +4 −3 python/plugins/processing/algs/gdal/GdalAlgorithm.py
  8. +4 −3 python/plugins/processing/algs/gdal/GridDataMetrics.py
  9. +4 −3 python/plugins/processing/algs/gdal/GridInverseDistance.py
  10. +4 −3 python/plugins/processing/algs/gdal/GridInverseDistanceNearestNeighbor.py
  11. +4 −3 python/plugins/processing/algs/gdal/GridLinear.py
  12. +4 −3 python/plugins/processing/algs/gdal/GridNearestNeighbor.py
  13. +7 −7 python/plugins/processing/algs/gdal/OffsetCurve.py
  14. +12 −11 python/plugins/processing/algs/gdal/OneSideBuffer.py
  15. +7 −7 python/plugins/processing/algs/gdal/PointsAlongLines.py
  16. +5 −3 python/plugins/processing/algs/gdal/buildvrt.py
  17. +4 −4 python/plugins/processing/algs/gdal/contour.py
  18. +4 −3 python/plugins/processing/algs/gdal/fillnodata.py
  19. +37 −36 python/plugins/processing/algs/gdal/gdal2tiles.py
  20. +4 −4 python/plugins/processing/algs/gdal/gdal2xyz.py
  21. +1 −3 python/plugins/processing/algs/gdal/gdaladdo.py
  22. +4 −3 python/plugins/processing/algs/gdal/gdaltindex.py
  23. +10 −10 python/plugins/processing/algs/gdal/nearblack.py
  24. +9 −9 python/plugins/processing/algs/gdal/pansharp.py
  25. +6 −5 python/plugins/processing/algs/gdal/proximity.py
  26. +4 −3 python/plugins/processing/algs/gdal/rasterize.py
  27. +16 −13 python/plugins/processing/algs/gdal/rasterize_over.py
  28. +15 −12 python/plugins/processing/algs/gdal/rasterize_over_fixed_value.py
  29. +4 −4 python/plugins/processing/algs/gdal/rearrange_bands.py
  30. +25 −23 python/plugins/processing/algs/gdal/retile.py
  31. +6 −6 python/plugins/processing/algs/gdal/rgb2pct.py
  32. +4 −3 python/plugins/processing/algs/gdal/sieve.py
  33. +17 −16 python/plugins/processing/algs/gdal/viewshed.py
  34. +10 −11 python/plugins/processing/algs/grass7/Grass7Utils.py
  35. +2 −4 python/plugins/processing/algs/qgis/Delaunay.py
  36. +1 −4 python/plugins/processing/algs/qgis/FieldPyculator.py
  37. +6 −6 python/plugins/processing/algs/qgis/MeanAndStdDevPlot.py
  38. +1 −1 python/plugins/processing/algs/qgis/RandomPointsAlongLines.py
  39. +1 −1 python/plugins/processing/algs/qgis/RandomPointsLayer.py
  40. +1 −1 python/plugins/processing/algs/qgis/RandomPointsPolygons.py
  41. +5 −5 python/plugins/processing/algs/qgis/RasterLayerHistogram.py
  42. +10 −6 python/plugins/processing/algs/qgis/RectanglesOvalsDiamondsVariable.py
  43. +6 −8 python/plugins/processing/algs/qgis/Relief.py
  44. +1 −1 python/plugins/processing/algs/qgis/SelectByAttribute.py
  45. +3 −3 python/plugins/processing/algs/qgis/UniqueValues.py
  46. +1 −1 python/plugins/processing/algs/qgis/VoronoiPolygons.py
@@ -82,11 +82,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

crs = self.parameterAsCrs(parameters, self.CRS, context)

arguments = []
arguments.append('-a_srs')
arguments.append(GdalUtils.gdal_crs_string(crs))
arguments = [
'-a_srs',
GdalUtils.gdal_crs_string(crs),

arguments.append(fileName)
fileName
]

if isWindows():
commands = ["python3", "-m", self.commandName()]
@@ -132,12 +132,13 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
out = self.parameterAsOutputLayer(parameters, self.OUTPUT, context)
self.setOutputValue(self.OUTPUT, out)

arguments = []
arguments.append('-projwin')
arguments.append(str(bbox.xMinimum()))
arguments.append(str(bbox.yMaximum()))
arguments.append(str(bbox.xMaximum()))
arguments.append(str(bbox.yMinimum()))
arguments = [
'-projwin',
str(bbox.xMinimum()),
str(bbox.yMaximum()),
str(bbox.xMaximum()),
str(bbox.yMinimum()),
]

crs = inLayer.crs()
if override_crs and crs.isValid():
@@ -86,17 +86,18 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

arguments = []
arguments.append('-spat')
arguments.append(str(extent.xMinimum()))
arguments.append(str(extent.yMaximum()))
arguments.append(str(extent.xMaximum()))
arguments.append(str(extent.yMinimum()))
arguments.append('-clipsrc spat_extent')

arguments.append(output)
arguments.append(ogrLayer)
arguments.append(layerName)
arguments = [
'-spat',
str(extent.xMinimum()),
str(extent.yMaximum()),
str(extent.xMaximum()),
str(extent.yMinimum()),
'-clipsrc spat_extent',

output,
ogrLayer,
layerName
]

if options:
arguments.append(options)
@@ -84,15 +84,16 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

arguments = []
arguments.append('-clipsrc')
arguments.append(maskLayer)
arguments.append('-clipsrclayer')
arguments.append(maskLayerName)

arguments.append(output)
arguments.append(inLayer)
arguments.append(inLayerName)
arguments = [
'-clipsrc',
maskLayer,
'-clipsrclayer',
maskLayerName,

output,
inLayer,
inLayerName,
]

if options:
arguments.append(options)
@@ -59,32 +59,33 @@ def initAlgorithm(self, config=None):
self.addParameter(QgsProcessingParameterString(self.GEOMETRY,
self.tr('Geometry column name'),
defaultValue='geometry'))
params = []
params.append(QgsProcessingParameterBoolean(self.EXPLODE_COLLECTIONS,
self.tr('Produce one feature for each geometry in any kind of geometry collection in the source file'),
defaultValue=False))
params.append(QgsProcessingParameterBoolean(self.KEEP_ATTRIBUTES,
self.tr('Keep input attributes'),
defaultValue=False))
params.append(QgsProcessingParameterBoolean(self.COUNT_FEATURES,
self.tr('Count dissolved features'),
defaultValue=False))
params.append(QgsProcessingParameterBoolean(self.COMPUTE_AREA,
self.tr('Compute area and perimeter of dissolved features'),
defaultValue=False))
params.append(QgsProcessingParameterBoolean(self.COMPUTE_STATISTICS,
self.tr('Compute min/max/sum/mean for attribute'),
defaultValue=False))
params.append(QgsProcessingParameterField(self.STATISTICS_ATTRIBUTE,
self.tr('Numeric attribute to calculate statistics on'),
None,
self.INPUT,
QgsProcessingParameterField.Numeric,
optional=True))
params.append(QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
optional=True))
params = [
QgsProcessingParameterBoolean(self.EXPLODE_COLLECTIONS,
self.tr('Produce one feature for each geometry in any kind of geometry collection in the source file'),
defaultValue=False,),
QgsProcessingParameterBoolean(self.KEEP_ATTRIBUTES,
self.tr('Keep input attributes'),
defaultValue=False),
QgsProcessingParameterBoolean(self.COUNT_FEATURES,
self.tr('Count dissolved features'),
defaultValue=False),
QgsProcessingParameterBoolean(self.COMPUTE_AREA,
self.tr('Compute area and perimeter of dissolved features'),
defaultValue=False),
QgsProcessingParameterBoolean(self.COMPUTE_STATISTICS,
self.tr('Compute min/max/sum/mean for attribute'),
defaultValue=False),
QgsProcessingParameterField(self.STATISTICS_ATTRIBUTE,
self.tr('Numeric attribute to calculate statistics on'),
None,
self.INPUT,
QgsProcessingParameterField.Numeric,
optional=True),
QgsProcessingParameterString(self.OPTIONS,
self.tr('Additional creation options'),
defaultValue='',
optional=True)
]
for param in params:
param.setFlags(param.flags() | QgsProcessingParameterDefinition.FlagAdvanced)
self.addParameter(param)
@@ -135,13 +136,14 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-nlt PROMOTE_TO_MULTI')
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')
arguments = [
output,
ogrLayer,
'-nlt PROMOTE_TO_MULTI',
'-dialect',
'sqlite',
'-sql',
]

tokens = []
if self.parameterAsBoolean(parameters, self.COUNT_FEATURES, context):
@@ -95,12 +95,12 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
raise QgsProcessingException(
self.tr('Empty SQL. Please enter valid SQL expression and try again.'))

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-sql')
arguments.append(sql)

arguments = [
output,
ogrLayer,
'-sql',
sql
]
dialect = self.dialects[self.parameterAsEnum(parameters, self.DIALECT, context)][1]
if dialect:
arguments.append('-dialect')
@@ -145,9 +145,10 @@ def processAlgorithm(self, parameters, context, feedback):
return results

def commandName(self):
parameters = {}
for param in self.parameterDefinitions():
parameters[param.name()] = "1"
parameters = {
param.name(): "1"
for param in self.parameterDefinitions()
}
context = QgsProcessingContext()
feedback = QgsProcessingFeedback()
name = self.getConsoleCommands(parameters, context, feedback, executing=False)[0]
@@ -160,9 +160,10 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

arguments = ['-l']
arguments.append(layerName)

arguments = [
'-l',
layerName
]
fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
if fieldName:
arguments.append('-zfield')
@@ -166,9 +166,10 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

arguments = ['-l']
arguments.append(layerName)

arguments = [
'-l',
layerName
]
fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
if fieldName:
arguments.append('-zfield')
@@ -153,9 +153,10 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

arguments = ['-l']
arguments.append(layerName)

arguments = [
'-l',
layerName
]
fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
if fieldName:
arguments.append('-zfield')
@@ -129,9 +129,10 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

arguments = ['-l']
arguments.append(layerName)

arguments = [
'-l',
layerName
]
fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
if fieldName:
arguments.append('-zfield')
@@ -141,9 +141,10 @@ def commandName(self):
def getConsoleCommands(self, parameters, context, feedback, executing=True):
ogrLayer, layerName = self.getOgrCompatibleSource(self.INPUT, parameters, context, feedback, executing)

arguments = ['-l']
arguments.append(layerName)

arguments = [
'-l',
layerName
]
fieldName = self.parameterAsString(parameters, self.Z_FIELD, context)
if fieldName:
arguments.append('-zfield')
@@ -107,13 +107,13 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

arguments = [
output,
ogrLayer,
'-dialect',
'sqlite',
'-sql'
]
sql = 'SELECT ST_OffsetCurve({}, {}) AS {}{} FROM "{}"'.format(geometry, distance, geometry, other_fields, layerName)
arguments.append(sql)

@@ -125,23 +125,24 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):

output, outputFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

other_fields = []
for f in fields:
if f.name() == geometry:
continue
other_fields.append('"{}"'.format(f.name()))
other_fields = [
'"{}"'.format(f.name())
for f in fields
if f.name() != geometry
]

if other_fields:
other_fields = ',*'
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')
arguments = [
output,
ogrLayer,
'-dialect',
'sqlite',
'-sql'
]

if dissolve or fieldName:
sql = 'SELECT ST_Union(ST_SingleSidedBuffer({}, {}, {})) AS {}{} FROM "{}"'.format(geometry, distance, side, geometry, other_fields, layerName)
@@ -111,13 +111,13 @@ def getConsoleCommands(self, parameters, context, feedback, executing=True):
else:
other_fields = ''

arguments = []
arguments.append(output)
arguments.append(ogrLayer)
arguments.append('-dialect')
arguments.append('sqlite')
arguments.append('-sql')

arguments = [
output,
ogrLayer,
'-dialect',
'sqlite',
'-sql'
]
sql = 'SELECT ST_Line_Interpolate_Point({}, {}) AS {}{} FROM "{}"'.format(geometry, distance, geometry, other_fields, layerName)
arguments.append(sql)

@@ -176,9 +176,11 @@ def commandName(self):
return "gdalbuildvrt"

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-resolution')
arguments.append(self.RESOLUTION_OPTIONS[self.parameterAsEnum(parameters, self.RESOLUTION, context)][1])
arguments = [
'-resolution',
self.RESOLUTION_OPTIONS[self.parameterAsEnum(parameters, self.RESOLUTION, context)][1]
]

if self.parameterAsBoolean(parameters, buildvrt.SEPARATE, context):
arguments.append('-separate')
if self.parameterAsBoolean(parameters, buildvrt.PROJ_DIFFERENCE, context):
@@ -154,10 +154,10 @@ def _buildArgsList(self, parameters, context, feedback, executing):
self.setOutputValue(self.OUTPUT, outFile)
output, outFormat = GdalUtils.ogrConnectionStringAndFormat(outFile, context)

arguments = []
arguments.append('-b')
arguments.append(str(self.parameterAsInt(parameters, self.BAND, context)))

arguments = [
'-b',
str(self.parameterAsInt(parameters, self.BAND, context))
]
if fieldName:
arguments.append('-a')
arguments.append(fieldName)
@@ -115,9 +115,10 @@ def flags(self):
return super().flags() | QgsProcessingAlgorithm.FlagDisplayNameIsLiteral

def getConsoleCommands(self, parameters, context, feedback, executing=True):
arguments = []
arguments.append('-md')
arguments.append(str(self.parameterAsInt(parameters, self.DISTANCE, context)))
arguments = [
'-md',
str(self.parameterAsInt(parameters, self.DISTANCE, context)),
]

nIterations = self.parameterAsInt(parameters, self.ITERATIONS, context)
if nIterations:

0 comments on commit dcde81f

Please sign in to comment.