From af0165265014e165aa12bcd3817fec0c7ae2bdf1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20Ribreux?= Date: Wed, 16 Dec 2015 17:39:16 +0100 Subject: [PATCH 1/5] [Feature][Processing] GRASS v.net modules --- .../processing/algs/grass7/CMakeLists.txt | 2 + .../processing/algs/grass7/Grass7Algorithm.py | 199 ++++++++++-------- .../algs/grass7/description/v.net.alloc.txt | 13 ++ .../grass7/description/v.net.allpairs.txt | 13 ++ .../algs/grass7/description/v.net.bridge.txt | 8 + .../grass7/description/v.net.centrality.txt | 17 ++ .../grass7/description/v.net.components.txt | 10 + .../grass7/description/v.net.connectivity.txt | 14 ++ .../grass7/description/v.net.distance.txt | 18 ++ .../algs/grass7/description/v.net.flow.txt | 15 ++ .../algs/grass7/description/v.net.iso.txt | 14 ++ .../algs/grass7/description/v.net.path.txt | 16 ++ .../grass7/description/v.net.salesman.txt | 13 ++ .../grass7/description/v.net.spanningtree.txt | 7 + .../algs/grass7/description/v.net.steiner.txt | 12 ++ .../algs/grass7/description/v.net.txt | 11 + .../grass7/description/v.net.visibility.txt | 7 + .../processing/algs/grass7/ext/CMakeLists.txt | 3 + .../processing/algs/grass7/ext/__init__.py | 0 .../processing/algs/grass7/ext/v_net.py | 188 +++++++++++++++++ .../processing/algs/grass7/ext/v_net_alloc.py | 31 +++ .../algs/grass7/ext/v_net_allpairs.py | 31 +++ .../algs/grass7/ext/v_net_bridge.py | 33 +++ .../algs/grass7/ext/v_net_components.py | 46 ++++ .../algs/grass7/ext/v_net_connectivity.py | 49 +++++ .../algs/grass7/ext/v_net_distance.py | 91 ++++++++ .../processing/algs/grass7/ext/v_net_flow.py | 50 +++++ .../processing/algs/grass7/ext/v_net_iso.py | 31 +++ .../processing/algs/grass7/ext/v_net_path.py | 31 +++ .../algs/grass7/ext/v_net_salesman.py | 49 +++++ .../algs/grass7/ext/v_net_steiner.py | 31 +++ .../algs/grass7/ext/v_net_visibility.py | 32 +++ 32 files changed, 1000 insertions(+), 85 deletions(-) create mode 100644 python/plugins/processing/algs/grass7/description/v.net.alloc.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.allpairs.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.bridge.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.centrality.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.components.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.connectivity.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.distance.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.flow.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.iso.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.path.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.salesman.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.spanningtree.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.steiner.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.visibility.txt create mode 100644 python/plugins/processing/algs/grass7/ext/CMakeLists.txt rename TODO => python/plugins/processing/algs/grass7/ext/__init__.py (100%) create mode 100644 python/plugins/processing/algs/grass7/ext/v_net.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_alloc.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_allpairs.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_bridge.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_components.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_connectivity.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_distance.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_flow.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_iso.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_path.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_salesman.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_steiner.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_visibility.py diff --git a/python/plugins/processing/algs/grass7/CMakeLists.txt b/python/plugins/processing/algs/grass7/CMakeLists.txt index 2bc6bf3de50..c35ca5cae67 100644 --- a/python/plugins/processing/algs/grass7/CMakeLists.txt +++ b/python/plugins/processing/algs/grass7/CMakeLists.txt @@ -2,5 +2,7 @@ FILE(GLOB PY_FILES *.py) FILE(GLOB OTHER_FILES grass7.txt) FILE(GLOB DESCR_FILES description/*.txt) +ADD_SUBDIRECTORY(ext) + PLUGIN_INSTALL(processing algs/grass7 ${PY_FILES} ${OTHER_FILES}) PLUGIN_INSTALL(processing algs/grass7/description ${DESCR_FILES}) diff --git a/python/plugins/processing/algs/grass7/Grass7Algorithm.py b/python/plugins/processing/algs/grass7/Grass7Algorithm.py index b2bf3fb062e..68d1c9016ac 100644 --- a/python/plugins/processing/algs/grass7/Grass7Algorithm.py +++ b/python/plugins/processing/algs/grass7/Grass7Algorithm.py @@ -69,6 +69,14 @@ class Grass7Algorithm(GeoAlgorithm): self.descriptionFile = descriptionfile self.defineCharacteristicsFromFile() self.numExportedLayers = 0 + self.uniqueSufix = unicode(uuid.uuid4()).replace('-', '') + + # Use the ext mechanism + name = self.commandLineName().replace('.', '_')[len('grass7:'):] + try: + self.module = importlib.import_module('processing.algs.grass7.ext.' + name) + except ImportError: + self.module = None def getCopy(self): newone = Grass7Algorithm(self.descriptionFile) @@ -214,10 +222,11 @@ class Grass7Algorithm(GeoAlgorithm): raise GeoAlgorithmExecutionException( self.tr('GRASS GIS 7 folder is not configured. Please ' 'configure it before running GRASS GIS 7 algorithms.')) - - commands = [] + + # Create brand new commands lists + self.commands = [] + self.outputCommands = [] self.exportedLayers = {} - outputCommands = [] # If GRASS session has been created outside of this algorithm then # get the list of layers loaded in GRASS otherwise start a new @@ -228,8 +237,57 @@ class Grass7Algorithm(GeoAlgorithm): else: Grass7Utils.startGrass7Session() - # 1: Export layer to grass mapset + # Handle ext functions for inputs/command/outputs + if self.module: + if hasattr(self.module, 'processInputs'): + func = getattr(self.module, 'processInputs') + func(self) + else: + self.processInputs() + + if hasattr(self.module, 'processCommand'): + func = getattr(self.module, 'processCommand') + func(self) + else: + self.processCommand() + + if hasattr(self.module, 'processOutputs'): + func = getattr(self.module, 'processOutputs') + func(self) + else: + self.processOutputs() + else: + self.processInputs() + self.processCommand() + self.processOutputs() + # Run GRASS + loglines = [] + loglines.append(self.tr('GRASS GIS 7 execution self.commands')) + for line in self.commands: + progress.setCommand(line) + loglines.append(line) + if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS): + ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) + + Grass7Utils.executeGrass7(self.commands, progress, self.outputCommands) + + for out in self.outputs: + if isinstance(out, OutputHTML): + with open(self.getOutputFromName("rawoutput").value) as f: + rawOutput = "".join(f.readlines()) + with open(out.value, "w") as f: + f.write("
%s
" % rawOutput) + + # If the session has been created outside of this algorithm, add + # the new GRASS GIS 7 layers to it otherwise finish the session + if existingSession: + Grass7Utils.addSessionLayers(self.exportedLayers) + else: + Grass7Utils.endGrass7Session() + + def processInputs(self): + """Prepare the GRASS import commands""" for param in self.parameters: if isinstance(param, ParameterRaster): if param.value is None: @@ -241,8 +299,8 @@ class Grass7Algorithm(GeoAlgorithm): if value in self.exportedLayers.keys(): continue else: - self.setSessionProjectionFromLayer(value, commands) - commands.append(self.exportRasterLayer(value)) + self.setSessionProjectionFromLayer(value, self.commands) + self.commands.append(self.exportRasterLayer(value)) if isinstance(param, ParameterVector): if param.value is None: continue @@ -250,8 +308,8 @@ class Grass7Algorithm(GeoAlgorithm): if value in self.exportedLayers.keys(): continue else: - self.setSessionProjectionFromLayer(value, commands) - commands.append(self.exportVectorLayer(value)) + self.setSessionProjectionFromLayer(value, self.commands) + self.commands.append(self.exportVectorLayer(value)) if isinstance(param, ParameterTable): pass if isinstance(param, ParameterMultipleInput): @@ -265,17 +323,17 @@ class Grass7Algorithm(GeoAlgorithm): if layer in self.exportedLayers.keys(): continue else: - self.setSessionProjectionFromLayer(layer, commands) - commands.append(self.exportRasterLayer(layer)) + self.setSessionProjectionFromLayer(layer, self.commands) + self.commands.append(self.exportRasterLayer(layer)) elif param.datatype == ParameterMultipleInput.TYPE_VECTOR_ANY: for layer in layers: if layer in self.exportedLayers.keys(): continue else: - self.setSessionProjectionFromLayer(layer, commands) - commands.append(self.exportVectorLayer(layer)) + self.setSessionProjectionFromLayer(layer, self.commands) + self.commands.append(self.exportVectorLayer(layer)) - self.setSessionProjectionFromProject(commands) + self.setSessionProjectionFromProject(self.commands) region = \ unicode(self.getParameterValue(self.GRASS_REGION_EXTENT_PARAMETER)) @@ -295,13 +353,14 @@ class Grass7Algorithm(GeoAlgorithm): self.getParameterValue(self.GRASS_REGION_ALIGN_TO_RESOLUTION) if alignToResolution: command += ' -a' - commands.append(command) - - # 2: Set parameters and outputs + self.commands.append(command) + def processCommand(self): + """Prepare the GRASS algorithm command""" command = self.grass7Name command += ' ' + ' '.join(self.hardcodedStrings) + # Add algorithm command for param in self.parameters: if param.value is None or param.value == '': continue @@ -330,15 +389,14 @@ class Grass7Algorithm(GeoAlgorithm): command += ' ' + param.name + '="' + unicode(param.value) + '"' else: command += ' ' + param.name + '="' + unicode(param.value) + '"' - - uniqueSufix = unicode(uuid.uuid4()).replace('-', '') + for out in self.outputs: if isinstance(out, OutputFile): command += ' > ' + out.value elif not isinstance(out, OutputHTML): # We add an output name to make sure it is unique if the session # uses this algorithm several times. - uniqueOutputName = out.name + uniqueSufix + uniqueOutputName = out.name + self.uniqueSufix command += ' ' + out.name + '=' + uniqueOutputName # Add output file to exported layers, to indicate that @@ -346,55 +404,55 @@ class Grass7Algorithm(GeoAlgorithm): self.exportedLayers[out.value] = uniqueOutputName command += ' --overwrite' - commands.append(command) - - # 3: Export resulting layers to a format that qgis can read - + self.commands.append(command) + + def processOutputs(self): + """Prepare the GRASS v.out.ogr commands""" for out in self.outputs: if isinstance(out, OutputRaster): filename = out.value # Raster layer output: adjust region to layer before # exporting - commands.append('g.region raster=' + out.name + uniqueSufix) - outputCommands.append('g.region raster=' + out.name - + uniqueSufix) + self.commands.append('g.region raster=' + out.name + self.uniqueSufix) + self.outputCommands.append('g.region raster=' + out.name + + self.uniqueSufix) if self.grass7Name == 'r.statistics': # r.statistics saves its results in a non-qgis compatible # way. Post-process them with r.mapcalc. - calcExpression = 'correctedoutput' + uniqueSufix - calcExpression += '=@' + out.name + uniqueSufix + calcExpression = 'correctedoutput' + self.uniqueSufix + calcExpression += '=@' + out.name + self.uniqueSufix command = 'r.mapcalc expression="' + calcExpression + '"' - commands.append(command) - outputCommands.append(command) + self.commands.append(command) + self.outputCommands.append(command) command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"' command += ' input=' - command += 'correctedoutput' + uniqueSufix + command += 'correctedoutput' + self.uniqueSufix command += ' output="' + filename + '"' elif self.grass7Name == 'r.composite': command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"' command += ' input=' - command += 'correctedoutput' + uniqueSufix + command += 'correctedoutput' + self.uniqueSufix command += ' output="' + filename + '"' else: command = 'r.out.gdal -c createopt="TFW=YES,COMPRESS=LZW"' command += ' input=' if self.grass7Name == 'r.horizon': - command += out.name + uniqueSufix + '_0' + command += out.name + self.uniqueSufix + '_0' elif self.grass7Name == 'r.composite': - commands.append(command) - outputCommands.append(command) + self.commands.append(command) + self.outputCommands.append(command) elif self.grass7Name == 'r.statistics': - commands.append(command) - outputCommands.append(command) + self.commands.append(command) + self.outputCommands.append(command) else: - command += out.name + uniqueSufix + command += out.name + self.uniqueSufix command += ' output="' + filename + '"' - commands.append(command) - outputCommands.append(command) + self.commands.append(command) + self.outputCommands.append(command) if isinstance(out, OutputVector): filename = out.value @@ -402,50 +460,24 @@ class Grass7Algorithm(GeoAlgorithm): outtype = ('auto' if typeidx is None else self.OUTPUT_TYPES[typeidx]) if self.grass7Name == 'r.flow': - command = 'v.out.ogr type=line layer=0 -s -e input=' + out.name + uniqueSufix + command = 'v.out.ogr type=line layer=0 -s -e input=' + out.name + self.uniqueSufix elif self.grass7Name == 'v.voronoi': - if '-l' in command: - command = 'v.out.ogr type=line layer=0 -s -e input=' + out.name + uniqueSufix + if '-l' in self.commands[-1]: + command = 'v.out.ogr type=line layer=0 -s -e input=' + out.name + self.uniqueSufix else: - command = 'v.out.ogr -s -e input=' + out.name + uniqueSufix + command = 'v.out.ogr -s -e input=' + out.name + self.uniqueSufix command += ' type=' + outtype elif self.grass7Name == 'v.sample': - command = 'v.out.ogr type=point -s -e input=' + out.name + uniqueSufix + command = 'v.out.ogr type=point -s -e input=' + out.name + self.uniqueSufix else: - command = 'v.out.ogr -s -e input=' + out.name + uniqueSufix + command = 'v.out.ogr -s -e input=' + out.name + self.uniqueSufix command += ' type=' + outtype command += ' output="' + os.path.dirname(out.value) + '"' command += ' format=ESRI_Shapefile' command += ' output_layer=' + os.path.basename(out.value)[:-4] - commands.append(command) - outputCommands.append(command) - - # 4: Run GRASS - - loglines = [] - loglines.append(self.tr('GRASS GIS 7 execution commands')) - for line in commands: - progress.setCommand(line) - loglines.append(line) - if ProcessingConfig.getSetting(Grass7Utils.GRASS_LOG_COMMANDS): - ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines) - - Grass7Utils.executeGrass7(commands, progress, outputCommands) - - for out in self.outputs: - if isinstance(out, OutputHTML): - with open(self.getOutputFromName("rawoutput").value) as f: - rawOutput = "".join(f.readlines()) - with open(out.value, "w") as f: - f.write("
%s
" % rawOutput) - - # If the session has been created outside of this algorithm, add - # the new GRASS GIS 7 layers to it otherwise finish the session - if existingSession: - Grass7Utils.addSessionLayers(self.exportedLayers) - else: - Grass7Utils.endGrass7Session() - + self.commands.append(command) + self.outputCommands.append(command) + def exportVectorLayer(self, orgFilename): # TODO: improve this. We are now exporting if it is not a shapefile, @@ -485,7 +517,7 @@ class Grass7Algorithm(GeoAlgorithm): command = 'g.proj' command += ' -c' command += ' proj4="' + proj4 + '"' - commands.append(command) + self.commands.append(command) Grass7Utils.projectionSet = True def setSessionProjectionFromLayer(self, layer, commands): @@ -496,7 +528,7 @@ class Grass7Algorithm(GeoAlgorithm): command = 'g.proj' command += ' -c' command += ' proj4="' + proj4 + '"' - commands.append(command) + self.commands.append(command) Grass7Utils.projectionSet = True def exportRasterLayer(self, layer): @@ -523,11 +555,8 @@ class Grass7Algorithm(GeoAlgorithm): return msg def checkParameterValuesBeforeExecuting(self): - name = self.commandLineName().replace('.', '_')[len('grass7:'):] - try: - module = importlib.import_module('processing.algs.grass7.ext.' + name) - except ImportError: - return - if hasattr(module, 'checkParameterValuesBeforeExecuting'): - func = getattr(module, 'checkParameterValuesBeforeExecuting') - return func(self) + if self.module: + if hasattr(self.module, 'checkParameterValuesBeforeExecuting'): + func = getattr(self.module, 'checkParameterValuesBeforeExecuting') + return func(self) + return diff --git a/python/plugins/processing/algs/grass7/description/v.net.alloc.txt b/python/plugins/processing/algs/grass7/description/v.net.alloc.txt new file mode 100644 index 00000000000..08f74bdd0b6 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.alloc.txt @@ -0,0 +1,13 @@ +v.net.alloc +Allocates subnets for nearest centers (direction from center) +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterString|center_cats|Category values|1-100000|False|False +*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2 +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Alloc diff --git a/python/plugins/processing/algs/grass7/description/v.net.allpairs.txt b/python/plugins/processing/algs/grass7/description/v.net.allpairs.txt new file mode 100644 index 00000000000..3b0a99fb84a --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.allpairs.txt @@ -0,0 +1,13 @@ +v.net.allpairs +Computes the shortest path between all pairs of nodes in the network +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterString|cats|Category values|1-10000|False|False +*ParameterString|where|WHERE condition of SQL statement without 'where' keyword'||True|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Allpairs diff --git a/python/plugins/processing/algs/grass7/description/v.net.bridge.txt b/python/plugins/processing/algs/grass7/description/v.net.bridge.txt new file mode 100644 index 00000000000..b2a2b8f5756 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.bridge.txt @@ -0,0 +1,8 @@ +v.net.bridge +Computes bridges and articulation points in the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterSelection|method|Operation to be performed|bridge;articulation|0|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True +OutputVector|output|Bridge_Or_Articulation diff --git a/python/plugins/processing/algs/grass7/description/v.net.centrality.txt b/python/plugins/processing/algs/grass7/description/v.net.centrality.txt new file mode 100644 index 00000000000..1313c8d4b7c --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.centrality.txt @@ -0,0 +1,17 @@ +v.net.centrality +Computes degree, centrality, betweeness, closeness and eigenvector centrality measures in the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterString|degree|Name of degree centrality column|degree|False|True +ParameterString|closeness|Name of closeness centrality column|closeness|False|True +ParameterString|betweenness|Name of betweenness centrality column||False|True +ParameterString|eigenvector|Name of eigenvector centrality column||False|True +*ParameterNumber|iterations|Maximum number of iterations to compute eigenvector centrality|1|None|1000|True +*ParameterNumber|error|Cumulative error tolerance for eigenvector centrality|0.001|None|0.1|True +*ParameterString|cats|Category values||False|True +*ParameterString|where|WHERE conditions of SQL statement without 'where' keyword||True|True +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterBoolean|-a|Add points on nodes|True|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Centrality diff --git a/python/plugins/processing/algs/grass7/description/v.net.components.txt b/python/plugins/processing/algs/grass7/description/v.net.components.txt new file mode 100644 index 00000000000..e7b306ca03a --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.components.txt @@ -0,0 +1,10 @@ +v.net.components +Computes strongly and weakly connected components in the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterSelection|method|Type of components|weak;strong|0|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterBoolean|-a|Add points on nodes|True|True +OutputVector|output|Network_Components_Line +OutputVector|output_point|Network_Components_Point diff --git a/python/plugins/processing/algs/grass7/description/v.net.connectivity.txt b/python/plugins/processing/algs/grass7/description/v.net.connectivity.txt new file mode 100644 index 00000000000..7632da3dbfd --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.connectivity.txt @@ -0,0 +1,14 @@ +v.net.connectivity +Computes vertex connectivity between two sets of nodes in the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterVector|points|Input vector point layer (first set of nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +ParameterString|set1_cats|Set1 Category values||False|True +ParameterString|set1_where|Set1 WHERE conditions of SQL statement without 'where' keyword||True|True +ParameterString|set2_cats|Set2 Category values||False|True +ParameterString|set2_where|Set2 WHERE conditions of SQL statement without 'where' keyword||True|True +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +OutputVector|output|Network_Connectivity diff --git a/python/plugins/processing/algs/grass7/description/v.net.distance.txt b/python/plugins/processing/algs/grass7/description/v.net.distance.txt new file mode 100644 index 00000000000..442d75981e9 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.distance.txt @@ -0,0 +1,18 @@ +v.net.distance +Computes shortest distance via the network between the given sets of features. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterVector|from_points|Input vector point layer (from)|0|False +ParameterVector|to_points|Input vector point layer (to)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2 +*ParameterString|from_cats|From Category values||False|True +*ParameterString|from_where|From WHERE conditions of SQL statement without 'where' keyword||True|True +*ParameterSelection|to_type|To feature type|point;line;boundary|0 +*ParameterString|to_cats|To Category values||False|True +*ParameterString|to_where|To WHERE conditions of SQL statement without 'where' keyword||True|True +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|from_points|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Distance diff --git a/python/plugins/processing/algs/grass7/description/v.net.flow.txt b/python/plugins/processing/algs/grass7/description/v.net.flow.txt new file mode 100644 index 00000000000..ea0348d6eff --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.flow.txt @@ -0,0 +1,15 @@ +v.net.flow +Computes the maximum flow between two sets of nodes in the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +ParameterVector|points|Input vector point layer (flow nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +ParameterString|source_cats|Source Category values||False|True +ParameterString|source_where|Source WHERE conditions of SQL statement without 'where' keyword||True|True +ParameterString|sink_cats|Sink Category values||False|True +ParameterString|sink_where|Sink WHERE conditions of SQL statement without 'where' keyword||True|True +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +OutputVector|output|Network_Flow +OutputVector|cut|Network_Cut diff --git a/python/plugins/processing/algs/grass7/description/v.net.iso.txt b/python/plugins/processing/algs/grass7/description/v.net.iso.txt new file mode 100644 index 00000000000..cb411977efe --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.iso.txt @@ -0,0 +1,14 @@ +v.net.iso +Splits network by cost isolines. +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2 +*ParameterString|center_cats|Category values|1-100000|False|False +ParameterString|costs|Costs for isolines|1000,2000,3000|False|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Iso diff --git a/python/plugins/processing/algs/grass7/description/v.net.path.txt b/python/plugins/processing/algs/grass7/description/v.net.path.txt new file mode 100644 index 00000000000..4431c787384 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.path.txt @@ -0,0 +1,16 @@ +v.net.path +Finds shortest path on vector network +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterFile|file|Name of file containing start and end points|False|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterSelection|type|Arc type|line;boundary;line,boundary|2 +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterTableField|node_column|Node cost column (number)|points|0|True +*ParameterNumber|dmax|Maximum distance to the network|None|None|1000.0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +*ParameterBoolean|-s|Write output as original input segments, not each path as one line|False|True +OutputVector|output|Network_Path + diff --git a/python/plugins/processing/algs/grass7/description/v.net.salesman.txt b/python/plugins/processing/algs/grass7/description/v.net.salesman.txt new file mode 100644 index 00000000000..de585033722 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.salesman.txt @@ -0,0 +1,13 @@ +v.net.salesman +Creates a cycle connecting given nodes (Traveling salesman problem) +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2 +*ParameterString|center_cats|Category values|1-100000|False|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (number)|input|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Salesman +OutputTable|sequence|Salesman_Nodes_Sequence diff --git a/python/plugins/processing/algs/grass7/description/v.net.spanningtree.txt b/python/plugins/processing/algs/grass7/description/v.net.spanningtree.txt new file mode 100644 index 00000000000..c4437b340a5 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.spanningtree.txt @@ -0,0 +1,7 @@ +v.net.spanningtree +Computes minimum spanning tree for the network. +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|SpanningTree diff --git a/python/plugins/processing/algs/grass7/description/v.net.steiner.txt b/python/plugins/processing/algs/grass7/description/v.net.steiner.txt new file mode 100644 index 00000000000..54ddd9f3922 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.steiner.txt @@ -0,0 +1,12 @@ +v.net.steiner +Creates Steiner tree for the network and given terminals +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Centers point layer (nodes)|0|False +ParameterNumber|threshold|Threshold for connecting centers to the network (in map unit)|0.0|None|50.0|False +*ParameterSelection|arc_type|Arc type|line;boundary;line,boundary|2 +*ParameterString|terminal_cats|Category values|1-100000|False|False +*ParameterTableField|acolumn|Arc forward/both direction(s) cost column (number)|input|0|True +*ParameterNumber|npoints|Maximum distance to the network|None|None|-1|True +*ParameterBoolean|-g|Use geodesic calculation for longitude-latitude locations|False|True +OutputVector|output|Network_Steiner diff --git a/python/plugins/processing/algs/grass7/description/v.net.txt b/python/plugins/processing/algs/grass7/description/v.net.txt new file mode 100644 index 00000000000..8802312052f --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.txt @@ -0,0 +1,11 @@ +v.net +Performs network maintenance +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Input vector point layer (nodes)|0|True +ParameterFile|file|Name of input file (required for operation 'arcs')|False|True +ParameterSelection|operation|Operation to be performed|nodes;connect;arcs;report;nreport|1 +ParameterNumber|threshold|Threshold (for operation 'connect')|None|None|50.0 +*ParameterBoolean|-c|Assign unique categories to new points (for operation 'nodes')|False|True +*ParameterBoolean|-s|Snap points to network (for operation 'connect')|False|True +OutputVector|output|Network diff --git a/python/plugins/processing/algs/grass7/description/v.net.visibility.txt b/python/plugins/processing/algs/grass7/description/v.net.visibility.txt new file mode 100644 index 00000000000..46a5f69fe2c --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.visibility.txt @@ -0,0 +1,7 @@ +v.net.visibility +Performs visibility graph construction. +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|-1|False +*ParameterString|coordinates|Coordinates||False|True +*ParameterVector|visibility|Input vector line layer containing visable points|1|True +OutputVector|output|Network_Visibility diff --git a/python/plugins/processing/algs/grass7/ext/CMakeLists.txt b/python/plugins/processing/algs/grass7/ext/CMakeLists.txt new file mode 100644 index 00000000000..5834ce9c254 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/CMakeLists.txt @@ -0,0 +1,3 @@ +FILE(GLOB PY_FILES *.py) + +PLUGIN_INSTALL(processing algs/grass7/ext ${PY_FILES}) diff --git a/TODO b/python/plugins/processing/algs/grass7/ext/__init__.py similarity index 100% rename from TODO rename to python/plugins/processing/algs/grass7/ext/__init__.py diff --git a/python/plugins/processing/algs/grass7/ext/v_net.py b/python/plugins/processing/algs/grass7/ext/v_net.py new file mode 100644 index 00000000000..5e7e004d198 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net.py @@ -0,0 +1,188 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net.py + -------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** + +This Python module handles pre-treatment operations for v.net.* GRASS7 modules. +Before using v.net you often have to incorporate a points layer into the network + vector map. + +You also have different output depending on some parameters. + +This file also contains dedicated ext functions for v.net module... +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +import os +from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString + +def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'): + """ + incorporate points with lines to form a GRASS network + """ + paramsToDelete = [] + + # Create an intermediate GRASS layer which is the combination of network + centers + intLayer = alg.getTempFilename() + + # Grab the point layer and delete this parameter (not used by v.net.alloc) + pointLayer = alg.getParameterValue(pointLayerName) + if pointLayer: + pointLayer = alg.exportedLayers[pointLayer] + paramsToDelete.append(alg.getParameterFromName(u'points')) + + # Grab the network layer and tell to v.net.alloc to use the temp layer instead + lineLayer = alg.getParameterValue(networkLayerName) + if lineLayer: + lineLayer = alg.exportedLayers[lineLayer] + alg.setParameterValue(networkLayerName, intLayer) + + threshold = alg.getParameterValue(u'threshold') + paramsToDelete.append(alg.getParameterFromName(u'threshold')) + + # Create the v.net connect command for point layer integration + command = u"v.net -s input={} points={} out={} op=connect threshold={}".format( + lineLayer, pointLayer, intLayer, threshold ) + alg.commands.append(command) + + # Connect the point layer database to the layer 2 of the network + command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer) + alg.commands.append(command) + + # Delete some unnecessary parameters + for param in paramsToDelete: + alg.parameters.remove(param) + + alg.processCommand() + + # Bring back the parameters: + for param in paramsToDelete: + alg.parameters.append(param) + +def variableOutput(alg, params, nocats=True): + """ Handle variable data output for v.net modules: + parameters: + { u"output": { u"param" : { 0: u"line", 1: u"point" } }, # parametized output + u"output3: u"line" # use this type for this output + } + """ + + # Build the v.out.ogr commands + for outName in params.keys(): + param = params[outName] + # There is a dict parameter: + if isinstance(param, dict): + paramName = param.keys()[0] + paramValue = alg.getParameterValue(paramName) + paramDict = param[paramName] + geomType = paramDict[paramValue] + elif isinstance(param, unicode): + geomType = param + else: + continue + + out = alg.getOutputValue(outName) + command = u"v.out.ogr {} type={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( + u"" if geomType == u"line" and nocats else u"-c", + geomType, + alg.exportedLayers[out], + os.path.dirname( out ), + os.path.basename( out)[:-4] + ) + alg.commands.append(command) + alg.outputCommands.append(command) + + +# v.net dedicated functions +def checkParameterValuesBeforeExecuting(alg): + """ Verify if we have the right parameters """ + operation = alg.getParameterValue(u'operation') + pointLayer = alg.getParameterValue(u'points') + threshold = alg.getParameterValue(u'threshold') + fileName = alg.getParameterValue(u'file') + if operation == 1: + if not (pointLayer and threshold): + return alg.tr("You need to set an input points layer and a threshold for operation 'connect' !") + elif operation == 2: + if not (fileName and pointLayer): + return alg.tr("You need to set an input points layer and a file for operation 'arcs' !") + + return None + +def processCommand(alg): + """ Handle data preparation for v.net: + * Integrate point layers into network vector map. + * Make v.net.distance use those layers. + * Delete the threshold parameter. + """ + paramsToDelete = [] + + # If we use the node operation, no need for threshold, + operation = alg.getParameterValue(u'operation') + if operation == 0: + paramsToDelete.append(alg.getParameterFromName(u'threshold')) + paramsToDelete.append(alg.getParameterFromName(u'file')) + elif operation == 2: + paramsToDelete.append(alg.getParameterFromName(u'threshold')) + elif operation in [3,4]: + paramsToDelete.append(alg.getParameterFromName(u'threshold')) + paramsToDelete.append(alg.getParameterFromName(u'points')) + paramsToDelete.append(alg.getParameterFromName(u'file')) + + # Grab the network layer and tell to v.net.alloc to use the temp layer instead + lineLayer = alg.getParameterValue(u'input') + if lineLayer: + lineLayer = alg.exportedLayers[lineLayer] + + # Delete some unnecessary parameters + for param in paramsToDelete: + alg.parameters.remove(param) + + alg.processCommand() + + # Bring back the parameters: + for param in paramsToDelete: + alg.parameters.append(param) + + +def processOutputs(alg): + """ Handle data output for v.net: + * use v.out.ogr with type=line on node operation. + * use v.out.ogr with type=point on articulation method. + """ + + # Find the method used + operation = alg.getParameterValue(u'operation') + + # Grab the name of the output + out = alg.getOutputValue(u'output') + + # Build the v.out.ogr command + command = u"v.out.ogr -c type={} layer={} -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( + u"point" if operation == 0 else "line", + u"2" if operation == 0 else u"1", + alg.exportedLayers[out], + os.path.dirname( out ), + os.path.basename( out )[:-4] + ) + alg.commands.append(command) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_alloc.py b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py new file mode 100644 index 00000000000..72ce43ee2a8 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_alloc.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints + +def processCommand(alg): + incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py new file mode 100644 index 00000000000..15119a3b05d --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_allpairs.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints + +def processCommand(alg): + incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_bridge.py b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py new file mode 100644 index 00000000000..5706d8f97a5 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_bridge.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + +def processOutputs(alg): + outputParameter = { u"output": { u"method" : { 0: u"line", 1: u"point" } } } + variableOutput(alg, outputParameter) + diff --git a/python/plugins/processing/algs/grass7/ext/v_net_components.py b/python/plugins/processing/algs/grass7/ext/v_net_components.py new file mode 100644 index 00000000000..103001a5d34 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_components.py @@ -0,0 +1,46 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_components.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + +def processCommand(alg): + # remove the output for point + outPoint = alg.getOutputFromName(u'output_point') + outLine = alg.getOutputFromName(u'output') + alg.exportedLayers[outPoint.value] = outLine.name + alg.uniqueSufix + alg.removeOutputFromName(u'output_point') + + alg.processCommand() + + # Re-add output for point + alg.addOutput(outPoint) + +def processOutputs(alg): + outputParameter = { u"output": u"line", + u"output_point": u"point" } + variableOutput(alg, outputParameter) + diff --git a/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py new file mode 100644 index 00000000000..98822a4c668 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_connectivity.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints, variableOutput + +def checkParameterValuesBeforeExecuting(alg): + """ Verify if we have the right parameters """ + params = [u'where', u'cats'] + values = [] + for param in params: + for i in range(1,3): + values.append(alg.getParameterValue(u'set{}_{}'.format(i,param))) + + if (values[0] or values[2]) and (values[1] or values[3]): + return None + + return alg.tr("You need to set at least setX_where or setX_cats parameters for each set !") + +def processCommand(alg): + incorporatePoints(alg) + +def processOutputs(alg): + outputParameter = { u"output": u"point" } + variableOutput(alg, outputParameter) + diff --git a/python/plugins/processing/algs/grass7/ext/v_net_distance.py b/python/plugins/processing/algs/grass7/ext/v_net_distance.py new file mode 100644 index 00000000000..cd530d31a65 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_distance.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_distance.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + + +from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString + +def processCommand(alg): + """ Handle data preparation for v.net.distance: + * Integrate point layers into network vector map. + * Make v.net.distance use those layers. + * Delete the threshold parameter. + * If where statement, connect to the db + """ + paramsToDelete = [] + + # Grab the threshold value for our v.net connect command + threshold = alg.getParameterValue(u'threshold') + if threshold: + paramsToDelete.append(alg.getParameterFromName(u'threshold')) + + # Grab the network layer and tell to v.net.alloc to use the temp layer instead + line_layer = alg.getParameterValue(u'input') + if line_layer: + line_layer = alg.exportedLayers[line_layer] + + # import the two point layers into the network + for i, layer in enumerate([u'from', u'to']): + # Get a temp layer name + intLayer = alg.getTempFilename() + + # Grab the from point layer and delete this parameter (not used by v.net.distance) + point_layer = alg.getParameterValue(layer + u'_points') + if point_layer: + point_layer = alg.exportedLayers[point_layer] + paramsToDelete.append(alg.getParameterFromName(layer + u'_points')) + + # Create the v.net connect command for point layer integration + command = u"v.net -s input={} points={} out={} op=connect threshold={} arc_layer=1 node_layer={}".format( line_layer, point_layer, intLayer, threshold, i+2 ) + alg.commands.append(command) + line_layer = intLayer + + # Add the parameter to the algorithm + parameter = alg.getParameterFromName(u'{}_layer'.format(layer)) + if not parameter: + parameter = getParameterFromString(u'ParameterNumber|{0}_layer|{0} layer number|1|3|2|False'.format(layer)) + alg.addParameter(parameter) + parameter.setValue(i+2) + + # Make the connection with attribute table + command = u"v.db.connect -o map={} table={} layer={}".format(line_layer, point_layer, i+2) + alg.commands.append(command) + + alg.setParameterValue(u'input', line_layer) + + # Delete some unnecessary parameters + for param in paramsToDelete: + alg.parameters.remove(param) + + alg.processCommand() + + # Bring back the parameters: + for param in paramsToDelete: + alg.parameters.append(param) + + # Delete from_layer and to_layer + for word in [u'from', u'to']: + alg.parameters.remove(alg.getParameterFromName(u'{}_layer'.format(word))) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_flow.py b/python/plugins/processing/algs/grass7/ext/v_net_flow.py new file mode 100644 index 00000000000..d6eedf26874 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_flow.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_flow.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + + +from v_net import incorporatePoints, processOutputs + +def checkParameterValuesBeforeExecuting(alg): + """ Verify if we have the right parameters """ + params = [u'where', u'cats'] + values = [] + for param in params: + for i in [u'source', u'sink']: + values.append(alg.getParameterValue(u'{}_{}'.format(i,param))) + + if (values[0] or values[2]) and (values[1] or values[3]): + return None + + return alg.tr("You need to set at least source/sink_where or source/sink_cats parameters for each set !") + +def processCommand(alg): + incorporatePoints(alg) + +def processOutputs(alg): + outputParameter = { u"output": u"line", + u"cut": u"line" } + variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_iso.py b/python/plugins/processing/algs/grass7/ext/v_net_iso.py new file mode 100644 index 00000000000..71c9bdec3a4 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_iso.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_iso.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints + +def processCommand(alg): + incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_path.py b/python/plugins/processing/algs/grass7/ext/v_net_path.py new file mode 100644 index 00000000000..448e87964f2 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_path.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_path.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints + +def processCommand(alg): + incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_salesman.py b/python/plugins/processing/algs/grass7/ext/v_net_salesman.py new file mode 100644 index 00000000000..bc822fbdd1d --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_salesman.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_salesman.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from processing.core.parameters import getParameterFromString +from v_net import incorporatePoints + +def processCommand(alg): + # We temporary remove the output 'sequence' + sequence = alg.getOutputFromName(u'sequence') + sequenceFile = alg.getOutputValue(u'sequence') + alg.exportedLayers[sequence.value] = sequence.name + alg.uniqueSufix + alg.removeOutputFromName(u'sequence') + + # We create a new parameter with the same name + param = getParameterFromString(u"ParameterString|sequence|sequence|None|False|False") + param.setValue(sequenceFile) + alg.addParameter(param) + + # Let's do the incorporation and command generation + incorporatePoints(alg) + + # then we delete the input parameter and add the old output + alg.parameters.remove(param) + alg.addOutput(sequence) + diff --git a/python/plugins/processing/algs/grass7/ext/v_net_steiner.py b/python/plugins/processing/algs/grass7/ext/v_net_steiner.py new file mode 100644 index 00000000000..012de49829b --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_steiner.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_steiner.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import incorporatePoints + +def processCommand(alg): + incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_visibility.py b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py new file mode 100644 index 00000000000..111e55e0164 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py @@ -0,0 +1,32 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_visibility.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + +def processOutputs(alg): + outputParameter = { u"output": u"line" } + variableOutput(alg, outputParameter, False) From d6fbe93f0a11b673dbb176a6e66b347cd05d6997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20RIBREUX?= Date: Sat, 2 Jan 2016 16:14:41 +0100 Subject: [PATCH 2/5] Fix indendation problems (as usual)... --- .../processing/algs/grass7/Grass7Algorithm.py | 14 +++++++------- .../processing/algs/grass7/ext/v_net_alloc.py | 1 + .../processing/algs/grass7/ext/v_net_allpairs.py | 1 + .../processing/algs/grass7/ext/v_net_bridge.py | 4 ++-- .../processing/algs/grass7/ext/v_net_components.py | 7 ++++--- .../algs/grass7/ext/v_net_connectivity.py | 14 ++++++++------ .../processing/algs/grass7/ext/v_net_distance.py | 13 +++++++------ .../processing/algs/grass7/ext/v_net_flow.py | 9 ++++++--- .../processing/algs/grass7/ext/v_net_iso.py | 1 + .../processing/algs/grass7/ext/v_net_path.py | 1 + .../processing/algs/grass7/ext/v_net_salesman.py | 2 +- .../processing/algs/grass7/ext/v_net_steiner.py | 1 + .../processing/algs/grass7/ext/v_net_visibility.py | 3 ++- 13 files changed, 42 insertions(+), 29 deletions(-) diff --git a/python/plugins/processing/algs/grass7/Grass7Algorithm.py b/python/plugins/processing/algs/grass7/Grass7Algorithm.py index 68d1c9016ac..11888581224 100644 --- a/python/plugins/processing/algs/grass7/Grass7Algorithm.py +++ b/python/plugins/processing/algs/grass7/Grass7Algorithm.py @@ -222,7 +222,7 @@ class Grass7Algorithm(GeoAlgorithm): raise GeoAlgorithmExecutionException( self.tr('GRASS GIS 7 folder is not configured. Please ' 'configure it before running GRASS GIS 7 algorithms.')) - + # Create brand new commands lists self.commands = [] self.outputCommands = [] @@ -244,13 +244,13 @@ class Grass7Algorithm(GeoAlgorithm): func(self) else: self.processInputs() - + if hasattr(self.module, 'processCommand'): func = getattr(self.module, 'processCommand') func(self) else: self.processCommand() - + if hasattr(self.module, 'processOutputs'): func = getattr(self.module, 'processOutputs') func(self) @@ -389,7 +389,7 @@ class Grass7Algorithm(GeoAlgorithm): command += ' ' + param.name + '="' + unicode(param.value) + '"' else: command += ' ' + param.name + '="' + unicode(param.value) + '"' - + for out in self.outputs: if isinstance(out, OutputFile): command += ' > ' + out.value @@ -405,7 +405,7 @@ class Grass7Algorithm(GeoAlgorithm): command += ' --overwrite' self.commands.append(command) - + def processOutputs(self): """Prepare the GRASS v.out.ogr commands""" for out in self.outputs: @@ -416,7 +416,7 @@ class Grass7Algorithm(GeoAlgorithm): # exporting self.commands.append('g.region raster=' + out.name + self.uniqueSufix) self.outputCommands.append('g.region raster=' + out.name - + self.uniqueSufix) + + self.uniqueSufix) if self.grass7Name == 'r.statistics': # r.statistics saves its results in a non-qgis compatible @@ -477,7 +477,7 @@ class Grass7Algorithm(GeoAlgorithm): command += ' output_layer=' + os.path.basename(out.value)[:-4] self.commands.append(command) self.outputCommands.append(command) - + def exportVectorLayer(self, orgFilename): # TODO: improve this. We are now exporting if it is not a shapefile, diff --git a/python/plugins/processing/algs/grass7/ext/v_net_alloc.py b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py index 72ce43ee2a8..3dd849497af 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_alloc.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py @@ -27,5 +27,6 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints + def processCommand(alg): incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py index 15119a3b05d..cb06cb4da88 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py @@ -27,5 +27,6 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints + def processCommand(alg): incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_bridge.py b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py index 5706d8f97a5..a13e3853eb4 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_bridge.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py @@ -27,7 +27,7 @@ __revision__ = '$Format:%H$' from v_net import variableOutput + def processOutputs(alg): - outputParameter = { u"output": { u"method" : { 0: u"line", 1: u"point" } } } + outputParameter = {u"output": {u"method": {0: u"line", 1: u"point"}}} variableOutput(alg, outputParameter) - diff --git a/python/plugins/processing/algs/grass7/ext/v_net_components.py b/python/plugins/processing/algs/grass7/ext/v_net_components.py index 103001a5d34..e188838ee2b 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_components.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_components.py @@ -27,6 +27,7 @@ __revision__ = '$Format:%H$' from v_net import variableOutput + def processCommand(alg): # remove the output for point outPoint = alg.getOutputFromName(u'output_point') @@ -39,8 +40,8 @@ def processCommand(alg): # Re-add output for point alg.addOutput(outPoint) + def processOutputs(alg): - outputParameter = { u"output": u"line", - u"output_point": u"point" } + outputParameter = {u"output": u"line", + u"output_point": u"point"} variableOutput(alg, outputParameter) - diff --git a/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py index 98822a4c668..5a784773004 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py @@ -27,23 +27,25 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints, variableOutput + def checkParameterValuesBeforeExecuting(alg): """ Verify if we have the right parameters """ params = [u'where', u'cats'] values = [] for param in params: - for i in range(1,3): - values.append(alg.getParameterValue(u'set{}_{}'.format(i,param))) + for i in range(1, 3): + values.append(alg.getParameterValue(u'set{}_{}'.format(i, param))) if (values[0] or values[2]) and (values[1] or values[3]): return None return alg.tr("You need to set at least setX_where or setX_cats parameters for each set !") + def processCommand(alg): incorporatePoints(alg) - -def processOutputs(alg): - outputParameter = { u"output": u"point" } - variableOutput(alg, outputParameter) + +def processOutputs(alg): + outputParameter = {u"output": u"point"} + variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_distance.py b/python/plugins/processing/algs/grass7/ext/v_net_distance.py index cd530d31a65..624f051f49a 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_distance.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_distance.py @@ -28,6 +28,7 @@ __revision__ = '$Format:%H$' from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString + def processCommand(alg): """ Handle data preparation for v.net.distance: * Integrate point layers into network vector map. @@ -51,7 +52,7 @@ def processCommand(alg): for i, layer in enumerate([u'from', u'to']): # Get a temp layer name intLayer = alg.getTempFilename() - + # Grab the from point layer and delete this parameter (not used by v.net.distance) point_layer = alg.getParameterValue(layer + u'_points') if point_layer: @@ -59,7 +60,7 @@ def processCommand(alg): paramsToDelete.append(alg.getParameterFromName(layer + u'_points')) # Create the v.net connect command for point layer integration - command = u"v.net -s input={} points={} out={} op=connect threshold={} arc_layer=1 node_layer={}".format( line_layer, point_layer, intLayer, threshold, i+2 ) + command = u"v.net -s input={} points={} out={} op=connect threshold={} arc_layer=1 node_layer={}".format(line_layer, point_layer, intLayer, threshold, i + 2) alg.commands.append(command) line_layer = intLayer @@ -68,12 +69,12 @@ def processCommand(alg): if not parameter: parameter = getParameterFromString(u'ParameterNumber|{0}_layer|{0} layer number|1|3|2|False'.format(layer)) alg.addParameter(parameter) - parameter.setValue(i+2) + parameter.setValue(i + 2) # Make the connection with attribute table - command = u"v.db.connect -o map={} table={} layer={}".format(line_layer, point_layer, i+2) + command = u"v.db.connect -o map={} table={} layer={}".format(line_layer, point_layer, i + 2) alg.commands.append(command) - + alg.setParameterValue(u'input', line_layer) # Delete some unnecessary parameters @@ -81,7 +82,7 @@ def processCommand(alg): alg.parameters.remove(param) alg.processCommand() - + # Bring back the parameters: for param in paramsToDelete: alg.parameters.append(param) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_flow.py b/python/plugins/processing/algs/grass7/ext/v_net_flow.py index d6eedf26874..97898c89105 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_flow.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_flow.py @@ -28,23 +28,26 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints, processOutputs + def checkParameterValuesBeforeExecuting(alg): """ Verify if we have the right parameters """ params = [u'where', u'cats'] values = [] for param in params: for i in [u'source', u'sink']: - values.append(alg.getParameterValue(u'{}_{}'.format(i,param))) + values.append(alg.getParameterValue(u'{}_{}'.format(i, param))) if (values[0] or values[2]) and (values[1] or values[3]): return None return alg.tr("You need to set at least source/sink_where or source/sink_cats parameters for each set !") + def processCommand(alg): incorporatePoints(alg) + def processOutputs(alg): - outputParameter = { u"output": u"line", - u"cut": u"line" } + outputParameter = {u"output": u"line", + u"cut": u"line"} variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_iso.py b/python/plugins/processing/algs/grass7/ext/v_net_iso.py index 71c9bdec3a4..50cf9db2902 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_iso.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_iso.py @@ -27,5 +27,6 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints + def processCommand(alg): incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_path.py b/python/plugins/processing/algs/grass7/ext/v_net_path.py index 448e87964f2..f313416bd21 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_path.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_path.py @@ -27,5 +27,6 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints + def processCommand(alg): incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_salesman.py b/python/plugins/processing/algs/grass7/ext/v_net_salesman.py index bc822fbdd1d..4f22a3722f1 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_salesman.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_salesman.py @@ -28,6 +28,7 @@ __revision__ = '$Format:%H$' from processing.core.parameters import getParameterFromString from v_net import incorporatePoints + def processCommand(alg): # We temporary remove the output 'sequence' sequence = alg.getOutputFromName(u'sequence') @@ -46,4 +47,3 @@ def processCommand(alg): # then we delete the input parameter and add the old output alg.parameters.remove(param) alg.addOutput(sequence) - diff --git a/python/plugins/processing/algs/grass7/ext/v_net_steiner.py b/python/plugins/processing/algs/grass7/ext/v_net_steiner.py index 012de49829b..936f7048476 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_steiner.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_steiner.py @@ -27,5 +27,6 @@ __revision__ = '$Format:%H$' from v_net import incorporatePoints + def processCommand(alg): incorporatePoints(alg) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_visibility.py b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py index 111e55e0164..690f4853796 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_visibility.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py @@ -27,6 +27,7 @@ __revision__ = '$Format:%H$' from v_net import variableOutput + def processOutputs(alg): - outputParameter = { u"output": u"line" } + outputParameter = {u"output": u"line"} variableOutput(alg, outputParameter, False) From 14a6115ee20cd7438e9840b358346e48845e9727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20RIBREUX?= Date: Sat, 2 Jan 2016 16:48:21 +0100 Subject: [PATCH 3/5] Fix indentation (one more time) --- .../processing/algs/grass7/Grass7Algorithm.py | 2 +- .../processing/algs/grass7/ext/v_net.py | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/python/plugins/processing/algs/grass7/Grass7Algorithm.py b/python/plugins/processing/algs/grass7/Grass7Algorithm.py index 11888581224..512120e8450 100644 --- a/python/plugins/processing/algs/grass7/Grass7Algorithm.py +++ b/python/plugins/processing/algs/grass7/Grass7Algorithm.py @@ -197,7 +197,7 @@ class Grass7Algorithm(GeoAlgorithm): else: layer = dataobjects.getObjectFromUri(param.value) cellsize = max(cellsize, (layer.extent().xMaximum() - - layer.extent().xMinimum()) + - layer.extent().xMinimum()) / layer.width()) elif isinstance(param, ParameterMultipleInput): diff --git a/python/plugins/processing/algs/grass7/ext/v_net.py b/python/plugins/processing/algs/grass7/ext/v_net.py index 5e7e004d198..2d666fcbfc8 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net.py +++ b/python/plugins/processing/algs/grass7/ext/v_net.py @@ -36,12 +36,13 @@ __revision__ = '$Format:%H$' import os from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString + def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'): """ incorporate points with lines to form a GRASS network """ paramsToDelete = [] - + # Create an intermediate GRASS layer which is the combination of network + centers intLayer = alg.getTempFilename() @@ -62,23 +63,24 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'): # Create the v.net connect command for point layer integration command = u"v.net -s input={} points={} out={} op=connect threshold={}".format( - lineLayer, pointLayer, intLayer, threshold ) + lineLayer, pointLayer, intLayer, threshold) alg.commands.append(command) # Connect the point layer database to the layer 2 of the network command = u"v.db.connect -o map={} table={} layer=2".format(intLayer, pointLayer) alg.commands.append(command) - + # Delete some unnecessary parameters for param in paramsToDelete: alg.parameters.remove(param) - + alg.processCommand() # Bring back the parameters: for param in paramsToDelete: alg.parameters.append(param) + def variableOutput(alg, params, nocats=True): """ Handle variable data output for v.net modules: parameters: @@ -106,9 +108,9 @@ def variableOutput(alg, params, nocats=True): u"" if geomType == u"line" and nocats else u"-c", geomType, alg.exportedLayers[out], - os.path.dirname( out ), - os.path.basename( out)[:-4] - ) + os.path.dirname(out), + os.path.basename(out)[:-4] + ) alg.commands.append(command) alg.outputCommands.append(command) @@ -129,6 +131,7 @@ def checkParameterValuesBeforeExecuting(alg): return None + def processCommand(alg): """ Handle data preparation for v.net: * Integrate point layers into network vector map. @@ -144,7 +147,7 @@ def processCommand(alg): paramsToDelete.append(alg.getParameterFromName(u'file')) elif operation == 2: paramsToDelete.append(alg.getParameterFromName(u'threshold')) - elif operation in [3,4]: + elif operation in [3, 4]: paramsToDelete.append(alg.getParameterFromName(u'threshold')) paramsToDelete.append(alg.getParameterFromName(u'points')) paramsToDelete.append(alg.getParameterFromName(u'file')) @@ -159,7 +162,7 @@ def processCommand(alg): alg.parameters.remove(param) alg.processCommand() - + # Bring back the parameters: for param in paramsToDelete: alg.parameters.append(param) @@ -170,7 +173,7 @@ def processOutputs(alg): * use v.out.ogr with type=line on node operation. * use v.out.ogr with type=point on articulation method. """ - + # Find the method used operation = alg.getParameterValue(u'operation') @@ -182,7 +185,7 @@ def processOutputs(alg): u"point" if operation == 0 else "line", u"2" if operation == 0 else u"1", alg.exportedLayers[out], - os.path.dirname( out ), - os.path.basename( out )[:-4] - ) + os.path.dirname(out), + os.path.basename(out)[:-4] + ) alg.commands.append(command) From 85b87d5d5c9bb944c4499bd26d009d89674062fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20RIBREUX?= Date: Sat, 9 Jan 2016 15:53:56 +0100 Subject: [PATCH 4/5] Non variable output version. Adds: * v.net.arcs for v.net 'arcs' operation. * v.net.articulation for v.net.brdige 'articulation' method. * v.net.connect for v.net 'connect' operation. * v.net.nodes for v.net 'nodes' operation. * v.net.nreport for v.net 'nreport' operation. * v.net.report for v.net 'report operation. * Some code simplification. --- .../algs/grass7/description/v.net.arcs.txt | 7 ++ .../grass7/description/v.net.articulation.txt | 8 ++ .../algs/grass7/description/v.net.bridge.txt | 6 +- .../algs/grass7/description/v.net.connect.txt | 9 ++ .../algs/grass7/description/v.net.nodes.txt | 7 ++ .../algs/grass7/description/v.net.nreport.txt | 7 ++ .../algs/grass7/description/v.net.report.txt | 7 ++ .../algs/grass7/description/v.net.txt | 11 -- .../processing/algs/grass7/ext/v_net.py | 114 +++--------------- .../processing/algs/grass7/ext/v_net_alloc.py | 8 +- .../algs/grass7/ext/v_net_allpairs.py | 1 + .../processing/algs/grass7/ext/v_net_arcs.py | 33 +++++ .../algs/grass7/ext/v_net_articulation.py | 33 +++++ .../algs/grass7/ext/v_net_bridge.py | 2 +- .../algs/grass7/ext/v_net_components.py | 6 +- .../algs/grass7/ext/v_net_connect.py | 39 ++++++ .../algs/grass7/ext/v_net_connectivity.py | 2 +- .../algs/grass7/ext/v_net_distance.py | 2 +- .../processing/algs/grass7/ext/v_net_flow.py | 6 +- .../processing/algs/grass7/ext/v_net_nodes.py | 33 +++++ .../algs/grass7/ext/v_net_visibility.py | 2 +- 21 files changed, 218 insertions(+), 125 deletions(-) create mode 100644 python/plugins/processing/algs/grass7/description/v.net.arcs.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.articulation.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.connect.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.nodes.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.nreport.txt create mode 100644 python/plugins/processing/algs/grass7/description/v.net.report.txt delete mode 100644 python/plugins/processing/algs/grass7/description/v.net.txt create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_arcs.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_articulation.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_connect.py create mode 100644 python/plugins/processing/algs/grass7/ext/v_net_nodes.py diff --git a/python/plugins/processing/algs/grass7/description/v.net.arcs.txt b/python/plugins/processing/algs/grass7/description/v.net.arcs.txt new file mode 100644 index 00000000000..3475a36d19e --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.arcs.txt @@ -0,0 +1,7 @@ +v.net +v.net.arcs - Creates arcs from a file of points +Vector (v.*) +ParameterVector|points|Input vector point layer (nodes)|0|False +ParameterFile|file|Name of input arcs file|False|False +Hardcoded|operation=arcs +OutputVector|output|Arcs diff --git a/python/plugins/processing/algs/grass7/description/v.net.articulation.txt b/python/plugins/processing/algs/grass7/description/v.net.articulation.txt new file mode 100644 index 00000000000..bf8c2734e7c --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.articulation.txt @@ -0,0 +1,8 @@ +v.net.bridge +v.net.articulation - Computes articulation points in the network +Vector (v.*) +ParameterVector|input|Input vector line layer (network)|1|False +Hardcoded|method=articulation +*ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True +*ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True +OutputVector|output|Articulation diff --git a/python/plugins/processing/algs/grass7/description/v.net.bridge.txt b/python/plugins/processing/algs/grass7/description/v.net.bridge.txt index b2a2b8f5756..921754bf935 100644 --- a/python/plugins/processing/algs/grass7/description/v.net.bridge.txt +++ b/python/plugins/processing/algs/grass7/description/v.net.bridge.txt @@ -1,8 +1,8 @@ v.net.bridge -Computes bridges and articulation points in the network. +Computes bridges in the network. Vector (v.*) ParameterVector|input|Input vector line layer (network)|1|False -ParameterSelection|method|Operation to be performed|bridge;articulation|0|False +Hardcoded|method=bridge *ParameterTableField|arc_column|Arc forward/both direction(s) cost column (name)|input|0|True *ParameterTableField|arc_backward_column|Arc backward direction cost column (name)|input|0|True -OutputVector|output|Bridge_Or_Articulation +OutputVector|output|Bridge diff --git a/python/plugins/processing/algs/grass7/description/v.net.connect.txt b/python/plugins/processing/algs/grass7/description/v.net.connect.txt new file mode 100644 index 00000000000..e31a77f04a9 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.connect.txt @@ -0,0 +1,9 @@ +v.net +v.net.connect - Connects points to nearest arcs in a network +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +ParameterVector|points|Input vector point layer (nodes)|0|False +Hardcoded|operation=connect +ParameterNumber|threshold|Threshold for connection distance|None|None|50.0 +*ParameterBoolean|-s|Snap points to network|False +OutputVector|output|Network diff --git a/python/plugins/processing/algs/grass7/description/v.net.nodes.txt b/python/plugins/processing/algs/grass7/description/v.net.nodes.txt new file mode 100644 index 00000000000..35f88c75830 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.nodes.txt @@ -0,0 +1,7 @@ +v.net +v.net.nodes - Creates points for each network arcs +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +Hardcoded|operation=nodes +*ParameterBoolean|-c|Assign unique categories to new points (for operation 'nodes')|False +OutputVector|output|Nodes diff --git a/python/plugins/processing/algs/grass7/description/v.net.nreport.txt b/python/plugins/processing/algs/grass7/description/v.net.nreport.txt new file mode 100644 index 00000000000..f0844e10ad1 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.nreport.txt @@ -0,0 +1,7 @@ +v.net +v.net.nreport - Reports nodes information of a network +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +Hardcoded|operation=nreport +OutputFile|output|NReport + diff --git a/python/plugins/processing/algs/grass7/description/v.net.report.txt b/python/plugins/processing/algs/grass7/description/v.net.report.txt new file mode 100644 index 00000000000..ae08fad63a4 --- /dev/null +++ b/python/plugins/processing/algs/grass7/description/v.net.report.txt @@ -0,0 +1,7 @@ +v.net +v.net.report - Reports lines information of a network +Vector (v.*) +ParameterVector|input|Input vector line layer (arcs)|1|False +Hardcoded|operation=report +OutputFile|output|Report + diff --git a/python/plugins/processing/algs/grass7/description/v.net.txt b/python/plugins/processing/algs/grass7/description/v.net.txt deleted file mode 100644 index 8802312052f..00000000000 --- a/python/plugins/processing/algs/grass7/description/v.net.txt +++ /dev/null @@ -1,11 +0,0 @@ -v.net -Performs network maintenance -Vector (v.*) -ParameterVector|input|Input vector line layer (arcs)|1|False -ParameterVector|points|Input vector point layer (nodes)|0|True -ParameterFile|file|Name of input file (required for operation 'arcs')|False|True -ParameterSelection|operation|Operation to be performed|nodes;connect;arcs;report;nreport|1 -ParameterNumber|threshold|Threshold (for operation 'connect')|None|None|50.0 -*ParameterBoolean|-c|Assign unique categories to new points (for operation 'nodes')|False|True -*ParameterBoolean|-s|Snap points to network (for operation 'connect')|False|True -OutputVector|output|Network diff --git a/python/plugins/processing/algs/grass7/ext/v_net.py b/python/plugins/processing/algs/grass7/ext/v_net.py index 2d666fcbfc8..05b2827a365 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net.py +++ b/python/plugins/processing/algs/grass7/ext/v_net.py @@ -17,12 +17,8 @@ *************************************************************************** This Python module handles pre-treatment operations for v.net.* GRASS7 modules. -Before using v.net you often have to incorporate a points layer into the network - vector map. - -You also have different output depending on some parameters. - -This file also contains dedicated ext functions for v.net module... +Before using a v.net module you often have to incorporate a points layer into +the network vector map. """ __author__ = 'Médéric Ribreux' @@ -83,109 +79,27 @@ def incorporatePoints(alg, pointLayerName=u'points', networkLayerName=u'input'): def variableOutput(alg, params, nocats=True): """ Handle variable data output for v.net modules: - parameters: - { u"output": { u"param" : { 0: u"line", 1: u"point" } }, # parametized output - u"output3: u"line" # use this type for this output + params is like: + { u"output": [u"point", 1], # One output of type point from layer 1 + u"output2": [u"line", 1], # One output of type line from layer 1 + u"output3: [u"point", 2] # one output of type point from layer 2 } + """ # Build the v.out.ogr commands - for outName in params.keys(): - param = params[outName] - # There is a dict parameter: - if isinstance(param, dict): - paramName = param.keys()[0] - paramValue = alg.getParameterValue(paramName) - paramDict = param[paramName] - geomType = paramDict[paramValue] - elif isinstance(param, unicode): - geomType = param - else: + for outputName, typeList in params.iteritems(): + if not isinstance(typeList, list): continue - out = alg.getOutputValue(outName) - command = u"v.out.ogr {} type={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( - u"" if geomType == u"line" and nocats else u"-c", - geomType, + out = alg.getOutputValue(outputName) + command = u"v.out.ogr {} type={} layer={} -s -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( + u"" if typeList[0] == u"line" and nocats else u"-c", + typeList[0], + typeList[1], alg.exportedLayers[out], os.path.dirname(out), os.path.basename(out)[:-4] ) alg.commands.append(command) alg.outputCommands.append(command) - - -# v.net dedicated functions -def checkParameterValuesBeforeExecuting(alg): - """ Verify if we have the right parameters """ - operation = alg.getParameterValue(u'operation') - pointLayer = alg.getParameterValue(u'points') - threshold = alg.getParameterValue(u'threshold') - fileName = alg.getParameterValue(u'file') - if operation == 1: - if not (pointLayer and threshold): - return alg.tr("You need to set an input points layer and a threshold for operation 'connect' !") - elif operation == 2: - if not (fileName and pointLayer): - return alg.tr("You need to set an input points layer and a file for operation 'arcs' !") - - return None - - -def processCommand(alg): - """ Handle data preparation for v.net: - * Integrate point layers into network vector map. - * Make v.net.distance use those layers. - * Delete the threshold parameter. - """ - paramsToDelete = [] - - # If we use the node operation, no need for threshold, - operation = alg.getParameterValue(u'operation') - if operation == 0: - paramsToDelete.append(alg.getParameterFromName(u'threshold')) - paramsToDelete.append(alg.getParameterFromName(u'file')) - elif operation == 2: - paramsToDelete.append(alg.getParameterFromName(u'threshold')) - elif operation in [3, 4]: - paramsToDelete.append(alg.getParameterFromName(u'threshold')) - paramsToDelete.append(alg.getParameterFromName(u'points')) - paramsToDelete.append(alg.getParameterFromName(u'file')) - - # Grab the network layer and tell to v.net.alloc to use the temp layer instead - lineLayer = alg.getParameterValue(u'input') - if lineLayer: - lineLayer = alg.exportedLayers[lineLayer] - - # Delete some unnecessary parameters - for param in paramsToDelete: - alg.parameters.remove(param) - - alg.processCommand() - - # Bring back the parameters: - for param in paramsToDelete: - alg.parameters.append(param) - - -def processOutputs(alg): - """ Handle data output for v.net: - * use v.out.ogr with type=line on node operation. - * use v.out.ogr with type=point on articulation method. - """ - - # Find the method used - operation = alg.getParameterValue(u'operation') - - # Grab the name of the output - out = alg.getOutputValue(u'output') - - # Build the v.out.ogr command - command = u"v.out.ogr -c type={} layer={} -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( - u"point" if operation == 0 else "line", - u"2" if operation == 0 else u"1", - alg.exportedLayers[out], - os.path.dirname(out), - os.path.basename(out)[:-4] - ) - alg.commands.append(command) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_alloc.py b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py index 3dd849497af..723f50365f0 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_alloc.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_alloc.py @@ -25,8 +25,14 @@ __copyright__ = '(C) 2015, Médéric Ribreux' __revision__ = '$Format:%H$' -from v_net import incorporatePoints + +from v_net import incorporatePoints, variableOutput def processCommand(alg): incorporatePoints(alg) + + +def processOutputs(alg): + outputParameter = {u"output": [u"line", 1]} + variableOutput(alg, outputParameter, False) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py index cb06cb4da88..575c47c7417 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_allpairs.py @@ -25,6 +25,7 @@ __copyright__ = '(C) 2015, Médéric Ribreux' __revision__ = '$Format:%H$' + from v_net import incorporatePoints diff --git a/python/plugins/processing/algs/grass7/ext/v_net_arcs.py b/python/plugins/processing/algs/grass7/ext/v_net_arcs.py new file mode 100644 index 00000000000..3d05c2fb291 --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_arcs.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_arcs.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + + +def processOutputs(alg): + outputParameter = {u"output": [u"line", 1]} + variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_articulation.py b/python/plugins/processing/algs/grass7/ext/v_net_articulation.py new file mode 100644 index 00000000000..69aa04dd43a --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_articulation.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_articulation.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + + +def processOutputs(alg): + outputParameter = {u"output": [u"point", 1]} + variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_bridge.py b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py index a13e3853eb4..c757d7665c5 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_bridge.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_bridge.py @@ -29,5 +29,5 @@ from v_net import variableOutput def processOutputs(alg): - outputParameter = {u"output": {u"method": {0: u"line", 1: u"point"}}} + outputParameter = {u"output": [u"line", 1]} variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_components.py b/python/plugins/processing/algs/grass7/ext/v_net_components.py index e188838ee2b..4e31081a24f 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_components.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_components.py @@ -30,8 +30,8 @@ from v_net import variableOutput def processCommand(alg): # remove the output for point - outPoint = alg.getOutputFromName(u'output_point') outLine = alg.getOutputFromName(u'output') + outPoint = alg.getOutputFromName(u'output_point') alg.exportedLayers[outPoint.value] = outLine.name + alg.uniqueSufix alg.removeOutputFromName(u'output_point') @@ -42,6 +42,6 @@ def processCommand(alg): def processOutputs(alg): - outputParameter = {u"output": u"line", - u"output_point": u"point"} + outputParameter = {u"output": [u"line", 1], + u"output_point": [u"point", 2]} variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_connect.py b/python/plugins/processing/algs/grass7/ext/v_net_connect.py new file mode 100644 index 00000000000..5cc75b849ae --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_connect.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_connect.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +import os + + +def processOutputs(alg): + out = alg.getOutputValue(u"output") + command = u"v.out.ogr -c type=line layer=1 -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( + alg.exportedLayers[out], + os.path.dirname(out), + os.path.basename(out)[:-4] + ) + alg.commands.append(command) + alg.outputCommands.append(command) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py index 5a784773004..fb7053c403b 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_connectivity.py @@ -47,5 +47,5 @@ def processCommand(alg): def processOutputs(alg): - outputParameter = {u"output": u"point"} + outputParameter = {u"output": [u"point", 2]} variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_distance.py b/python/plugins/processing/algs/grass7/ext/v_net_distance.py index 624f051f49a..02e77e44e49 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_distance.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_distance.py @@ -26,7 +26,7 @@ __copyright__ = '(C) 2015, Médéric Ribreux' __revision__ = '$Format:%H$' -from processing.core.parameters import getParameterFromString, ParameterVector, ParameterNumber, ParameterBoolean, ParameterString +from processing.core.parameters import getParameterFromString def processCommand(alg): diff --git a/python/plugins/processing/algs/grass7/ext/v_net_flow.py b/python/plugins/processing/algs/grass7/ext/v_net_flow.py index 97898c89105..fc9d3e617b2 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_flow.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_flow.py @@ -26,7 +26,7 @@ __copyright__ = '(C) 2015, Médéric Ribreux' __revision__ = '$Format:%H$' -from v_net import incorporatePoints, processOutputs +from v_net import incorporatePoints, variableOutput def checkParameterValuesBeforeExecuting(alg): @@ -48,6 +48,6 @@ def processCommand(alg): def processOutputs(alg): - outputParameter = {u"output": u"line", - u"cut": u"line"} + outputParameter = {u"output": [u"line", 1], + u"cut": [u"line", 1]} variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_nodes.py b/python/plugins/processing/algs/grass7/ext/v_net_nodes.py new file mode 100644 index 00000000000..c6c1ce0e8ee --- /dev/null +++ b/python/plugins/processing/algs/grass7/ext/v_net_nodes.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +""" +*************************************************************************** + v_net_nodes.py + --------------------- + Date : December 2015 + Copyright : (C) 2015 by Médéric Ribreux + Email : medspx at medspx dot fr +*************************************************************************** +* * +* This program is free software; you can redistribute it and/or modify * +* it under the terms of the GNU General Public License as published by * +* the Free Software Foundation; either version 2 of the License, or * +* (at your option) any later version. * +* * +*************************************************************************** +""" + +__author__ = 'Médéric Ribreux' +__date__ = 'December 2015' +__copyright__ = '(C) 2015, Médéric Ribreux' + +# This will get replaced with a git SHA1 when you do a git archive + +__revision__ = '$Format:%H$' + +from v_net import variableOutput + + +def processOutputs(alg): + outputParameter = {u"output": [u"point", 2]} + variableOutput(alg, outputParameter) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_visibility.py b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py index 690f4853796..403f4d371d2 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_visibility.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_visibility.py @@ -29,5 +29,5 @@ from v_net import variableOutput def processOutputs(alg): - outputParameter = {u"output": u"line"} + outputParameter = {u"output": [u"line", 1]} variableOutput(alg, outputParameter, False) From 89a1ad5ede5cec517f3ad72aa4bfaf9ebdf4f373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9d=C3=A9ric=20RIBREUX?= Date: Sat, 9 Jan 2016 18:01:27 +0100 Subject: [PATCH 5/5] Fix indentation problem (as usual) --- python/plugins/processing/algs/grass7/ext/v_net_connect.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/plugins/processing/algs/grass7/ext/v_net_connect.py b/python/plugins/processing/algs/grass7/ext/v_net_connect.py index 5cc75b849ae..b38e90900fd 100644 --- a/python/plugins/processing/algs/grass7/ext/v_net_connect.py +++ b/python/plugins/processing/algs/grass7/ext/v_net_connect.py @@ -32,8 +32,8 @@ def processOutputs(alg): out = alg.getOutputValue(u"output") command = u"v.out.ogr -c type=line layer=1 -e input={} output=\"{}\" format=ESRI_Shapefile output_layer={}".format( alg.exportedLayers[out], - os.path.dirname(out), - os.path.basename(out)[:-4] + os.path.dirname(out), + os.path.basename(out)[:-4] ) alg.commands.append(command) alg.outputCommands.append(command)