Skip to content

Commit

Permalink
Fix nearly all v. ext scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Médéric RIBREUX committed Dec 28, 2017
1 parent 90bf630 commit 14709f5
Show file tree
Hide file tree
Showing 35 changed files with 282 additions and 358 deletions.
21 changes: 16 additions & 5 deletions python/plugins/processing/algs/grass7/Grass7Algorithm.py
Expand Up @@ -523,14 +523,19 @@ def processCommand(self, parameters, context, delOutputs=False):
elif isinstance(param, QgsProcessingParameterBoolean):
if self.parameterAsBool(parameters, paramName, context):
command += ' {}'.format(paramName)
# For Extents, remove if the value is null
elif isinstance(param, QgsProcessingParameterExtent):
if self.parameterAsExtent(parameters, paramName, context):
value = self.parameterAsString(parameters, paramName, context)
# For enumeration, we need to grab the string value
elif isinstance(param, QgsProcessingParameterEnum):
# Handle multiple values
if param.allowMultiple():
indexes = self.parameterAsEnums(parameters, paramName, context)
else:
indexes = [self.parameterAsEnum(parameters, paramName, context)]
value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
if indexes:
value = '"{}"'.format(','.join([param.options()[i] for i in indexes]))
# For strings, we just translate as string
elif isinstance(param, QgsProcessingParameterString):
data = self.parameterAsString(parameters, paramName, context)
Expand All @@ -545,7 +550,10 @@ def processCommand(self, parameters, context, delOutputs=False):
self.parameterAsFields(parameters, paramName, context)
)
elif isinstance(param, QgsProcessingParameterFile):
value = self.parameterAsString(parameters, paramName, context)
if self.parameterAsString(parameters, paramName, context):
value = '"{}"'.format(
self.parameterAsString(parameters, paramName, context)
)
# For numbers and points, we translate as a string
elif isinstance(param, (QgsProcessingParameterNumber,
QgsProcessingParameterPoint)):
Expand Down Expand Up @@ -795,13 +803,16 @@ def exportVectorLayer(self, grassName, fileName, dataType='auto', layer=None, no
"""
Creates a dedicated command to export a vector from
temporary GRASS DB into a file via ogr.
:param grassName: name of the parameter
:param fileName: file path of raster layer
:param grassName: name of the parameter.
:param fileName: file path of raster layer.
:param dataType: GRASS data type for exporting data.
:param layer: In GRASS a vector can have multiple layers.
:param nocats: Also export features without category if True.
"""
for cmd in [self.commands, self.outputCommands]:
cmd.append(
'v.out.ogr{0} type={1} {2} input="{3}" output="{4}" {5}'.format(
'' if nocats else ' -c',
' -c' if nocats else '',
dataType,
'layer={}'.format(layer) if layer else '',
grassName,
Expand Down
6 changes: 3 additions & 3 deletions python/plugins/processing/algs/grass7/description/v.edit.txt
Expand Up @@ -2,18 +2,18 @@ v.edit
Edits a vector map, allows adding, deleting and modifying selected vector features.
Vector (v.*)
QgsProcessingParameterVectorLayer|map|Name of vector layer|-1|None|False
QgsProcessingParameterEnum|type|Input feature type|point;line;boundary;centroid|True|0,1,3,4|True
QgsProcessingParameterEnum|type|Input feature type|point;line;boundary;centroid|True|0,1,2,3|True
QgsProcessingParameterEnum|tool|Tool|create;add;delete;copy;move;flip;catadd;catdel;merge;break;snap;connect;chtype;vertexadd;vertexdel;vertexmove;areadel;zbulk;select|False|0|False
QgsProcessingParameterFile|input|ASCII file for add tool|False|txt|None|True
QgsProcessingParameterString|move|Difference in x,y,z direction for moving feature or vertex|None|False|True
QgsProcessingParameterString|threshold|Threshold distance (coords,snap,query)|None|False|True
QgsProcessingParameterString|ids|Feature ids|None|False|True
QgsProcessingParameterString|cats|Category values|None|False|True
QgsProcessingParameterString|coords|List of point coordinates|None|False|True
QgsProcessingParameterString|bbox|Bounding box for selecting features|None|False|True
QgsProcessingParameterExtent|bbox|Bounding box for selecting features|None|True
QgsProcessingParameterString|polygon|Polygon for selecting features|None|False|True
QgsProcessingParameterString|where|WHERE conditions of SQL statement without 'where' keyword|None|True|True
QgsProcessingParameterEnum|query|Query tool|length;dangle|False|0|True
QgsProcessingParameterEnum|query|Query tool|length;dangle|False|None|True
QgsProcessingParameterVectorLayer|bgmap|Name of background vector map|-1|None|True
QgsProcessingParameterEnum|snap|Snap added or modified features in the given threshold to the nearest existing feature|no;node;vertex|False|0|True
QgsProcessingParameterString|zbulk|Starting value and step for z bulk-labeling. Pair: value,step (e.g. 1100,10)|None|False|True
Expand Down
Expand Up @@ -4,8 +4,8 @@ Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
*QgsProcessingParameterString|cats|Category values|1-10000|False|False
*QgsProcessingParameterString|where|WHERE condition of SQL statement without 'where' keyword'|None|True|False
*QgsProcessingParameterString|cats|Category values|1-10000|False|True
*QgsProcessingParameterString|where|WHERE condition of SQL statement without 'where' keyword'|None|True|True
*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
Expand Down

This file was deleted.

Expand Up @@ -4,6 +4,7 @@ Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
QgsProcessingParameterEnum|method|Feature type|bridge;articulation|False|0|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (name)|None|input|0|False|True
*QgsProcessingParameterField|arc_backward_column|Arc backward direction cost column (name)|None|input|0|False|True
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
Expand Down
Expand Up @@ -3,6 +3,7 @@ Computes degree, centrality, betweeness, closeness and eigenvector centrality me
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
QgsProcessingParameterString|degree|Name of output degree centrality column|degree|False|True
QgsProcessingParameterString|closeness|Name of output closeness centrality column|closeness|False|True
QgsProcessingParameterString|betweenness|Name of output betweenness centrality column|None|False|True
Expand Down
Expand Up @@ -3,6 +3,7 @@ Computes strongly and weakly connected components in the network.
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
QgsProcessingParameterEnum|method|Type of components|weak;strong|False|0|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
Expand Down

This file was deleted.

Expand Up @@ -2,9 +2,8 @@ v.net.distance
Computes shortest distance via the network between the given sets of features.
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (network)|1|None|False
QgsProcessingParameterVectorLayer|points|Centers point layer (nodes)|0|None|True
QgsProcessingParameterVectorLayer|from_layer|Input vector from points layer (from)|0|None|True
QgsProcessingParameterVectorLayer|to_layer|Input vector to points layer (to)|0|None|True
QgsProcessingParameterVectorLayer|flayer|Input vector from points layer (from)|0|None|False
QgsProcessingParameterVectorLayer|tlayer|Input vector to layer (to)|-1|None|False
QgsProcessingParameterNumber|threshold|Threshold for connecting nodes 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
*QgsProcessingParameterString|from_cats|From Category values|None|False|True
Expand All @@ -14,7 +13,7 @@ QgsProcessingParameterNumber|threshold|Threshold for connecting nodes to the net
*QgsProcessingParameterString|to_where|To WHERE conditions of SQL statement without 'where' keyword|None|True|True
*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
*QgsProcessingParameterField|node_column|Node cost column (number)|None|from_layer|0|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
*QgsProcessingParameterBoolean|-l|Write each output path as one line, not as original input segments|False|True
QgsProcessingParameterVectorDestination|output|Network_Distance

This file was deleted.

Expand Up @@ -7,7 +7,7 @@ QgsProcessingParameterVectorLayer|turn_layer|Layer with turntable (with -t optio
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|type|Arc type|line;boundary|True|0,1|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
Expand Down
Expand Up @@ -2,8 +2,8 @@ v.net.spanningtree
Computes minimum spanning tree for the network.
Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|1|None|False
QgsProcessingParameterVectorLayer|points|Input point layer (nodes)|0|None|False
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|False|0.0|None
QgsProcessingParameterVectorLayer|points|Input point layer (nodes)|0|None|True
QgsProcessingParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|QgsProcessingParameterNumber.Double|50.0|True|0.0|None
*QgsProcessingParameterField|arc_column|Arc forward/both direction(s) cost column (number)|None|input|0|False|True
*QgsProcessingParameterField|node_column|Node cost column (number)|None|points|0|False|True
*QgsProcessingParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True
Expand Down
14 changes: 14 additions & 0 deletions python/plugins/processing/algs/grass7/description/v.net.txt
@@ -0,0 +1,14 @@
v.net
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
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
*QgsProcessingParameterBoolean|-c|Assign unique categories to new points|False
QgsProcessingParameterVectorDestination|output|Network|QgsProcessing.TypeVectorAnyGeometry|None|False
Expand Up @@ -4,5 +4,5 @@ Vector (v.*)
QgsProcessingParameterVectorLayer|input|Input vector line layer (arcs)|-1|None|False
QgsProcessingParameterPoint|coordinates|Coordinates|None|True
QgsProcessingParameterString|coordinates|Coordinates|None|False|True
QgsProcessingParameterVectorLayer|visibility|Input vector line layer containing visible points|1|None|True
QgsProcessingParameterVectorLayer|visibility|Input vector line layer containing visible points|0|None|True
QgsProcessingParameterVectorDestination|output|Network Visibility
52 changes: 20 additions & 32 deletions python/plugins/processing/algs/grass7/ext/v_edit.py
Expand Up @@ -29,46 +29,34 @@
import os


def checkParameterValuesBeforeExecuting(alg):
def checkParameterValuesBeforeExecuting(alg, parameters, context):
""" Verify if we have the right parameters """
if alg.getParameterValue('input_txt') and alg.getParameterValue(u'input'):
if (alg.parameterAsString(parameters, 'input_txt', context)
and alg.parameterAsString(parameters, 'input', context)):
return alg.tr("You need to set either an input ASCII file or inline data!")

return None


def processCommand(alg, parameters):
# handle inline add data
input_txt = alg.getParameterFromName('input_txt')
inputParameter = alg.getParameterFromName('input')
if input_txt.value:
def processCommand(alg, parameters, context):
# Handle inline rules
txtRules = alg.parameterAsString(parameters, 'input_txt', context)
if txtRules:
# Creates a temporary txt file
ruleFile = alg.getTempFilename()

tempRulesName = getTempFilename()
# Inject rules into temporary txt file
with open(ruleFile, "w") as tempRules:
tempRules.write(input_txt.value)
inputParameter.value = ruleFile
alg.parameters.remove(input_txt)

# exclude output for from_output
output = alg.getOutputFromName('output')
alg.removeOutputFromName('output')

alg.processCommand()
alg.addOutput(output)
if input_txt.value:
inputParameter.value = None
alg.addParameter(input_txt)
with open(tempRulesName, "w") as tempRules:
tempRules.write(txtRules)
alg.removeParameter('input_txt')
parameters['input'] = tempRulesName

alg.processCommand(parameters, context, True)


def processOutputs(alg):
def processOutputs(alg, parameters, context):
# We need to add the from layer to outputs:
out = alg.exportedLayers[alg.getParameterValue('map')]
from_out = alg.getOutputValue('output')
command = u"v.out.ogr -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format(
out, os.path.dirname(from_out),
os.path.splitext(os.path.basename(from_out))[0]
)
alg.commands.append(command)
alg.outputCommands.append(command)
fileName = alg.parameterAsOutputLayer(parameters, 'output', context)
grassName = alg.exportedLayers['map']
dataType = 'auto'
alg.exportVectorLayer(grassName, fileName, dataType)
39 changes: 0 additions & 39 deletions python/plugins/processing/algs/grass7/ext/v_in_lidar.py

This file was deleted.

22 changes: 11 additions & 11 deletions python/plugins/processing/algs/grass7/ext/v_lrs_create.py
Expand Up @@ -26,19 +26,19 @@
__revision__ = '$Format:%H$'


def processOutputs(alg):
def processOutputs(alg, parameters, context):
# add some export commands
command = 'v.build.all'
alg.commands.append(command)

# export the SQLite table to CSV
rstable = alg.getOutputValue('rstable')
# I don't use db.out.ogr because it doesn't work
command = 'db.select table={} separator=comma output=\"{}\" --overwrite'.format(
alg.exportedLayers[rstable],
rstable
)
alg.commands.append(command)
command = 'echo \"Integer\",\"Integer\",\"Integer\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\" > \"{}t\"'.format(rstable)
alg.commands.append(command)
alg.processOutputs()
# rstable = alg.getOutputValue('rstable')
# # I don't use db.out.ogr because it doesn't work
# command = 'db.select table={} separator=comma output=\"{}\" --overwrite'.format(
# alg.exportedLayers[rstable],
# rstable
# )
# alg.commands.append(command)
# command = 'echo \"Integer\",\"Integer\",\"Integer\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\",\"Real\" > \"{}t\"'.format(rstable)
# alg.commands.append(command)
alg.processOutputs(parameters, context)

0 comments on commit 14709f5

Please sign in to comment.