Skip to content
Permalink
Browse files

Remove broken algorithms and clean code

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Dec 30, 2017
1 parent 486bcd6 commit 5a3a0dab95782c13bb9d0576aca92bbd30fc9ed3
Showing with 110 additions and 383 deletions.
  1. +53 −8 python/plugins/processing/algs/grass7/Grass7Algorithm.py
  2. +0 −13 python/plugins/processing/algs/grass7/description/i.rectify.txt
  3. +0 −15 python/plugins/processing/algs/grass7/description/v.lrs.create.txt
  4. +0 −7 python/plugins/processing/algs/grass7/description/v.lrs.segment.txt
  5. +0 −8 python/plugins/processing/algs/grass7/description/v.lrs.where.txt
  6. +0 −3 python/plugins/processing/algs/grass7/description/v.net.alloc.txt
  7. +0 −3 python/plugins/processing/algs/grass7/description/v.net.iso.txt
  8. +0 −3 python/plugins/processing/algs/grass7/description/v.net.path.txt
  9. +0 −3 python/plugins/processing/algs/grass7/description/v.net.salesman.txt
  10. +0 −9 python/plugins/processing/algs/grass7/description/v.net.turntable.txt
  11. +1 −3 python/plugins/processing/algs/grass7/description/v.net.txt
  12. +3 −4 python/plugins/processing/algs/grass7/ext/i.py
  13. +1 −1 python/plugins/processing/algs/grass7/ext/i_cca.py
  14. +2 −2 python/plugins/processing/algs/grass7/ext/i_cluster.py
  15. +2 −2 python/plugins/processing/algs/grass7/ext/i_evapo_mh.py
  16. +2 −2 python/plugins/processing/algs/grass7/ext/i_gensig.py
  17. +2 −2 python/plugins/processing/algs/grass7/ext/i_gensigset.py
  18. +1 −2 python/plugins/processing/algs/grass7/ext/i_maxlik.py
  19. +0 −1 python/plugins/processing/algs/grass7/ext/i_oif.py
  20. +1 −2 python/plugins/processing/algs/grass7/ext/i_pansharpen.py
  21. +0 −87 python/plugins/processing/algs/grass7/ext/i_rectify.py
  22. +1 −2 python/plugins/processing/algs/grass7/ext/i_smap.py
  23. +1 −1 python/plugins/processing/algs/grass7/ext/r_blend_combine.py
  24. +4 −4 python/plugins/processing/algs/grass7/ext/r_blend_rgb.py
  25. +2 −1 python/plugins/processing/algs/grass7/ext/r_category.py
  26. +5 −5 python/plugins/processing/algs/grass7/ext/r_colors.py
  27. +1 −0 python/plugins/processing/algs/grass7/ext/r_colors_stddev.py
  28. +2 −2 python/plugins/processing/algs/grass7/ext/r_drain.py
  29. +2 −0 python/plugins/processing/algs/grass7/ext/r_horizon.py
  30. +1 −0 python/plugins/processing/algs/grass7/ext/r_li.py
  31. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_dominance.py
  32. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_dominance_ascii.py
  33. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_edgedensity_ascii.py
  34. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_mps.py
  35. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_padsd.py
  36. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_pielou.py
  37. +0 −1 python/plugins/processing/algs/grass7/ext/r_li_renyi_ascii.py
  38. +3 −2 python/plugins/processing/algs/grass7/ext/r_mapcalc.py
  39. +1 −0 python/plugins/processing/algs/grass7/ext/r_mask_vect.py
  40. +1 −1 python/plugins/processing/algs/grass7/ext/r_reclass.py
  41. +2 −2 python/plugins/processing/algs/grass7/ext/r_series_interp.py
  42. +1 −0 python/plugins/processing/algs/grass7/ext/r_shade.py
  43. +1 −0 python/plugins/processing/algs/grass7/ext/r_statistics.py
  44. +0 −1 python/plugins/processing/algs/grass7/ext/r_stats_quantile_rast.py
  45. +1 −0 python/plugins/processing/algs/grass7/ext/v_distance.py
  46. +3 −3 python/plugins/processing/algs/grass7/ext/v_edit.py
  47. +0 −44 python/plugins/processing/algs/grass7/ext/v_lrs_create.py
  48. +0 −72 python/plugins/processing/algs/grass7/ext/v_lrs_segment.py
  49. +0 −51 python/plugins/processing/algs/grass7/ext/v_lrs_where.py
  50. +3 −2 python/plugins/processing/algs/grass7/ext/v_net.py
  51. +1 −0 python/plugins/processing/algs/grass7/ext/v_net_allpairs.py
  52. +1 −1 python/plugins/processing/algs/grass7/ext/v_net_components.py
  53. +2 −0 python/plugins/processing/algs/grass7/ext/v_net_distance.py
  54. +1 −0 python/plugins/processing/algs/grass7/ext/v_net_salesman.py
  55. +2 −2 python/plugins/processing/algs/grass7/ext/v_rectify.py
@@ -415,7 +415,7 @@ def processInputs(self, parameters, context):
continue
elif isinstance(parameters[paramName], str) and len(parameters[paramName]) == 0:
continue

# Raster inputs needs to be imported into temp GRASS DB
if isinstance(param, QgsProcessingParameterRasterLayer):
if paramName not in self.exportedLayers:
@@ -424,11 +424,13 @@ def processInputs(self, parameters, context):
# Vector inputs needs to be imported into temp GRASS DB
elif isinstance(param, QgsProcessingParameterVectorLayer):
if paramName not in self.exportedLayers:
self.loadVectorLayerFromParameter(
paramName, parameters, context)
# TODO: find the best replacement for ParameterTable
#if isinstance(param, ParameterTable):
# pass
# Attribute tables are also vector inputs
if QgsProcessing.TypeFile in param.dataTypes():
self.loadAttributeTableFromParameter(
paramName, parameters, context)
else:
self.loadVectorLayerFromParameter(
paramName, parameters, context)
# For multiple inputs, process each layer
elif isinstance(param, QgsProcessingParameterMultipleLayers):
layers = self.parameterAsLayerList(parameters, paramName, context)
@@ -667,7 +669,7 @@ def loadRasterLayer(self, name, layer, external=True, band=1, destName=None):
'band={} '.format(band) if band else '',
destName)
self.commands.append(command)

def exportRasterLayerFromParameter(self, name, parameters, context, colorTable=True):
"""
Creates a dedicated command to export a raster from
@@ -772,7 +774,7 @@ def loadVectorLayer(self, name, layer, external=False):
Grass7Utils.GRASS_USE_VEXTERNAL)
self.inputLayers.append(layer)
self.setSessionProjectionFromLayer(layer)
destFilename = 'a' + os.path.basename(getTempFilename())
destFilename = 'vector_{}'.format(os.path.basename(getTempFilename()))
self.exportedLayers[name] = destFilename
command = '{0}{1}{2} input="{3}" output="{4}" --overwrite -o'.format(
'v.external' if external else 'v.in.ogr',
@@ -826,6 +828,49 @@ def exportVectorLayer(self, grassName, fileName, dataType='auto', layer=None, no
)
)

def loadAttributeTableFromParameter(self, name, parameters, context):
"""
Creates a dedicated command to load an attribute table
into the temporary GRASS DB.
:param name: name of the parameter
:param parameters: Parameters of the algorithm.
:param context: Processing context
"""
table = self.parameterAsVectorLayer(parameters, name, context)
self.loadAttributeTable(name, table)

def loadAttributeTable(self, name, layer, destName=None):
"""
Creates a dedicated command to load an attribute table
into the temporary GRASS DB.
:param name: name of the input parameter.
:param layer: a layer object to import from.
:param destName: force the name for the table into GRASS DB.
"""
self.inputLayers.append(layer)
if not destName:
destName = 'table_{}'.format(os.path.basename(getTempFilename()))
self.exportedLayers[name] = destName
command = 'db.in.ogr --overwrite input="{0}" output="{1}"'.format(
os.path.normpath(layer.source()), destName)
self.commands.append(command)

def exportAttributeTable(self, grassName, fileName, outFormat='CSV', layer=1):
"""
Creates a dedicated command to export an attribute
table from the temporary GRASS DB into a file via ogr.
:param grassName: name of the parameter.
:param fileName: file path of raster layer.
:param outFormat: file format for export.
:param layer: In GRASS a vector can have multiple layers.
"""
for cmd in [self.commands, self.outputCommands]:
cmd.append(
'db.out.ogr input="{0}" output="{1}" layer={2} format={3} --overwrite'.format(
grassName, fileName, layer, outFormat
)
)

def setSessionProjectionFromProject(self):
"""
Set the projection from the project.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -3,14 +3,11 @@ Allocates subnets for nearest centers (direction from center)
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t option)|0|None|True
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable (with -t option)|0|None|True
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
*QgsProcessingParameterString|center_cats|Category values|1-100000|False|False
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|False
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
*QgsProcessingParameterBoolean|-t|Use turntable|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
QgsProcessingParameterVectorDestination|output|Network Alloction
@@ -3,15 +3,12 @@ Splits network by cost isolines.
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t option)|0|None|True
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable (with -t option)|0|None|True
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|False
*QgsProcessingParameterString|center_cats|Category values|1-100000|False|False
QgsProcessingParameterString|costs|Costs for isolines|1000,2000,3000|False|False
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
*QgsProcessingParameterBoolean|-t|Use turntable|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
QgsProcessingParameterVectorDestination|output|Network_Iso
@@ -3,16 +3,13 @@ Finds shortest path on vector network
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t option)|0|None|True
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable (with -t option)|0|None|True
QgsProcessingParameterFile|file|Name of file containing start and end points|False|txt|None|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|False
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
*QgsProcessingParameterNumber|dmax|Maximum distance to the network|QgsProcessingParameterNumber.Double|1000.0|True|0.0|None
*QgsProcessingParameterBoolean|-t|Use turntable|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
*QgsProcessingParameterBoolean|-s|Write output as original input segments, not each path as one line|False|True
QgsProcessingParameterVectorDestination|output|Network_Path
@@ -3,14 +3,11 @@ Creates a cycle connecting given nodes (Traveling salesman problem)
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t option)|0|None|True
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable (with -t option)|0|None|True
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
*QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|False
*QgsProcessingParameterString|center_cats|Category values|1-100000|False|False
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (number)|None|input|0|False|True
*QgsProcessingParameterBoolean|-t|Use turntable|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
QgsProcessingParameterVectorDestination|output|Network_Salesman
QgsProcessingParameterFileDestination|sequence|Output file holding node sequence|Html files (*.html)|report.html|True

This file was deleted.

@@ -3,10 +3,8 @@ Performs network maintenance
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|True
QgsProcessingParameterVectorLayer|points|Input vector point layer (nodes)|0|None|True
QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable|0|None|True
QgsProcessingParameterVectorLayer|turn_cat_layer|Layer with unique categories used in turntable|0|None|True
QgsProcessingParameterFile|file|Name of input arcs file|False|txt|None|True
QgsProcessingParameterEnum|operation|Operation to be performed|nodes;connect;arcs;turntable|False|0|False
QgsProcessingParameterEnum|operation|Operation to be performed|nodes;connect;arcs|False|0|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
QgsProcessingParameterEnum|arc_type|Arc type|line;boundary|True|0,1|True
*QgsProcessingParameterBoolean|-s|Snap points to network|False
@@ -51,14 +51,14 @@ def orderedInput(alg, parameters, context, src, tgt, numSeq=None):
# Handle specific range
if numSeq is None:
numSeq = list(range(1, len(rasters) + 1))

for idx, raster in enumerate(rasters):
rasterName = '{}{}'.format(rootFilename, numSeq[idx])
alg.loadRasterLayer(rasterName, raster, False, None, rasterName)

# Don't forget to remove the old input parameter
alg.removeParameter(src)


def regroupRasters(alg, parameters, context, src, group, subgroup=None, extFile=None):
"""
@@ -114,10 +114,9 @@ def regroupRasters(alg, parameters, context, src, group, subgroup=None, extFile=
# 'subgroup', new_parameters[subgroup.name()],
# extFile[ext], shortFileName)
# copyFile(alg, extFileName, destPath)


alg.removeParameter(src)

return groupName, subgroupName


@@ -40,6 +40,6 @@ def processCommand(alg, parameters, context):
signatureFile = alg.parameterAsString(parameters, 'signature', context)
shortSigFile = importSigFile(alg, group, subgroup, signatureFile)
parameters['signature'] = shortSigFile

# Handle other parameters
alg.processCommand(parameters, context)
@@ -28,6 +28,7 @@
import os
from .i import regroupRasters, verifyRasterNum, exportSigFile


def checkParameterValuesBeforeExecuting(alg, parameters, context):
return verifyRasterNum(alg, parameters, context, 'input', 2)

@@ -41,10 +42,9 @@ def processCommand(alg, parameters, context):
# Regroup rasters
group, subgroup = regroupRasters(alg, parameters, context, 'input', 'group', 'subgroup')
alg.processCommand(parameters, context)

# Re-add signature files
parameters['signaturefile'] = signatureFile

# Export signature file
exportSigFile(alg, group, subgroup, signatureFile)

@@ -28,9 +28,9 @@

def checkParameterValuesBeforeExecuting(alg, parameters, context):
if (alg.parameterAsBool(parameters, '-h', context)
and alg.parameterAsLayer(parameters, 'precipitation', context)):
and alg.parameterAsLayer(parameters, 'precipitation', context)):
return alg.tr('You can\'t use original Hargreaves flag and precipitation parameter together!')
if (not alg.parameterAsBool(parameters, '-h', context)
and not alg.parameterAsLayer(parameters, 'precipitation', context)):
and not alg.parameterAsLayer(parameters, 'precipitation', context)):
return alg.tr('If you don\'t use original Hargreaves flag, you must set the precipitation raster parameter!')
return None
@@ -28,6 +28,7 @@
import os
from .i import regroupRasters, exportSigFile


def processCommand(alg, parameters, context):
# We need to extract the basename of the signature file
signatureFile = alg.parameterAsString(parameters, 'signaturefile', context)
@@ -37,10 +38,9 @@ def processCommand(alg, parameters, context):
# Regroup rasters
group, subgroup = regroupRasters(alg, parameters, context, 'input', 'group', 'subgroup')
alg.processCommand(parameters, context)

# Re-add signature files
parameters['signaturefile'] = signatureFile

# Export signature file
exportSigFile(alg, group, subgroup, signatureFile)

@@ -28,6 +28,7 @@
import os
from .i import regroupRasters, exportSigFile


def processCommand(alg, parameters, context):
# We need to extract the basename of the signature file
signatureFile = alg.parameterAsString(parameters, 'signaturefile', context)
@@ -37,10 +38,9 @@ def processCommand(alg, parameters, context):
# Regroup rasters
group, subgroup = regroupRasters(alg, parameters, context, 'input', 'group', 'subgroup')
alg.processCommand(parameters, context)

# Re-add signature files
parameters['signaturefile'] = signatureFile

# Export signature file
exportSigFile(alg, group, subgroup, signatureFile, 'sigset')

@@ -36,7 +36,6 @@ def processCommand(alg, parameters, context):
signatureFile = alg.parameterAsString(parameters, 'signaturefile', context)
shortSigFile = importSigFile(alg, group, subgroup, signatureFile)
parameters['signaturefile'] = shortSigFile

# Handle other parameters
alg.processCommand(parameters, context)

@@ -30,4 +30,3 @@

def checkParameterValuesBeforeExecuting(alg, parameters, context):
return verifyRasterNum(alg, parameters, context, 'input', 4)

0 comments on commit 5a3a0da

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