Skip to content
Permalink
Browse files

Fix r.li.* description files and ext scripts

  • Loading branch information
Médéric RIBREUX
Médéric RIBREUX committed Dec 27, 2017
1 parent 9b6f98a commit 1f8fbf313f9b50321ed138f8c56ea1daa1d98670
Showing with 242 additions and 410 deletions.
  1. +1 −0 python/plugins/processing/algs/grass7/description/r.blend.rgb.txt
  2. +1 −1 python/plugins/processing/algs/grass7/description/r.li.cwed.ascii.txt
  3. +1 −1 python/plugins/processing/algs/grass7/description/r.li.dominance.ascii.txt
  4. +1 −1 python/plugins/processing/algs/grass7/description/r.li.edgedensity.ascii.txt
  5. +1 −1 python/plugins/processing/algs/grass7/description/r.li.mpa.ascii.txt
  6. +1 −1 python/plugins/processing/algs/grass7/description/r.li.mps.ascii.txt
  7. +1 −1 python/plugins/processing/algs/grass7/description/r.li.padcv.ascii.txt
  8. +1 −1 python/plugins/processing/algs/grass7/description/r.li.padrange.ascii.txt
  9. +1 −1 python/plugins/processing/algs/grass7/description/r.li.padsd.ascii.txt
  10. +1 −1 python/plugins/processing/algs/grass7/description/r.li.patchdensity.ascii.txt
  11. +1 −1 python/plugins/processing/algs/grass7/description/r.li.patchnum.ascii.txt
  12. +1 −1 python/plugins/processing/algs/grass7/description/r.li.pielou.ascii.txt
  13. +1 −1 python/plugins/processing/algs/grass7/description/r.li.renyi.ascii.txt
  14. +1 −1 python/plugins/processing/algs/grass7/description/r.li.richness.ascii.txt
  15. +1 −1 python/plugins/processing/algs/grass7/description/r.li.shannon.ascii.txt
  16. +1 −1 python/plugins/processing/algs/grass7/description/r.li.shape.ascii.txt
  17. +1 −1 python/plugins/processing/algs/grass7/description/r.li.simpson.ascii.txt
  18. +4 −3 python/plugins/processing/algs/grass7/ext/r_blend_combine.py
  19. +22 −58 python/plugins/processing/algs/grass7/ext/r_blend_rgb.py
  20. +32 −40 python/plugins/processing/algs/grass7/ext/r_li.py
  21. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_cwed.py
  22. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_cwed_ascii.py
  23. +5 −4 python/plugins/processing/algs/grass7/ext/r_li_dominance.py
  24. +7 −6 python/plugins/processing/algs/grass7/ext/r_li_dominance_ascii.py
  25. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_edgedensity.py
  26. +7 −6 python/plugins/processing/algs/grass7/ext/r_li_edgedensity_ascii.py
  27. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_mpa.py
  28. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_mpa_ascii.py
  29. +5 −4 python/plugins/processing/algs/grass7/ext/r_li_mps.py
  30. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_mps_ascii.py
  31. +0 −133 python/plugins/processing/algs/grass7/ext/r_li_orig.py
  32. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_padcv.py
  33. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_padcv_ascii.py
  34. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_padrange.py
  35. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_padrange_ascii.py
  36. +5 −4 python/plugins/processing/algs/grass7/ext/r_li_padsd.py
  37. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_padsd_ascii.py
  38. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_patchdensity.py
  39. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_patchdensity_ascii.py
  40. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_patchnum.py
  41. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_patchnum_ascii.py
  42. +5 −4 python/plugins/processing/algs/grass7/ext/r_li_pielou.py
  43. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_pielou_ascii.py
  44. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_renyi.py
  45. +7 −6 python/plugins/processing/algs/grass7/ext/r_li_renyi_ascii.py
  46. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_richness.py
  47. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_richness_ascii.py
  48. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_shannon.py
  49. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_shannon_ascii.py
  50. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_shape.py
  51. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_shape_ascii.py
  52. +4 −4 python/plugins/processing/algs/grass7/ext/r_li_simpson.py
  53. +6 −6 python/plugins/processing/algs/grass7/ext/r_li_simpson_ascii.py
@@ -4,6 +4,7 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|first|Name of first raster map for blending|None|False
QgsProcessingParameterRasterLayer|second|Name of second raster map for blending|None|False
QgsProcessingParameterNumber|percent|Percentage weight of first map for color blending|QgsProcessingParameterNumber.Double|50.0|True|0.0|100.0
Hardcoded|output=blended
QgsProcessingParameterRasterDestination|output_red|Blended Red
QgsProcessingParameterRasterDestination|output_green|Blended Green
QgsProcessingParameterRasterDestination|output_blue|Blended Blue
@@ -5,4 +5,4 @@ QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFile|path|Name of file that contains the weight to calculate the index|False|txt|None|False
QgsProcessingParameterFileDestination|output|CWED|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|CWED|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Dominance|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Dominance|Txt files (*.txt)|None|False
@@ -6,4 +6,4 @@ QgsProcessingParameterString|config_txt|Landscape structure configuration|None|T
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterString|patch_type|The value of the patch type|None|False|True
QgsProcessingParameterBoolean|-b|Exclude border edges|False
QgsProcessingParameterFileDestination|output|Edge Density|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Edge Density|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Mean Pixel Attribute|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Mean Pixel Attribute|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None
QgsProcessingParameterFileDestination|output|Mean Patch Size|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Mean Patch Size|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|PADCV|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|PADCV|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Pad Range|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Pad Range|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Patch Area SD|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Patch Area SD|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Patch Density|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Patch Density|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Patch Number|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Patch Number|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Pielou|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Pielou|Txt files (*.txt)|None|False
@@ -5,4 +5,4 @@ QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterString|alpha|Alpha value is the order of the generalized entropy|None|False|False
QgsProcessingParameterFileDestination|output|Renyi|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Renyi|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Richness|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Richness|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Shannon|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Shannon|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Shape|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Shape|Txt files (*.txt)|None|False
@@ -4,4 +4,4 @@ Raster (r.*)
QgsProcessingParameterRasterLayer|input|Name of input raster map|None|False
QgsProcessingParameterString|config_txt|Landscape structure configuration|None|True|True
QgsProcessingParameterFile|config|Landscape structure configuration file|False|txt|None|True
QgsProcessingParameterFileDestination|output|Simpson|Txt files (*.txt)|None|False
QgsProcessingParameterFileDestination|output_txt|Simpson|Txt files (*.txt)|None|False
@@ -2,8 +2,8 @@

"""
***************************************************************************
r_blend.py
----------
r_blend_combine.py
------------------
Date : February 2016
Copyright : (C) 2016 by Médéric Ribreux
Email : medspx at medspx dot fr
@@ -29,7 +29,8 @@
def processInputs(alg, parameters, context):
if 'first' and 'second' in alg.exportedLayers:
return


# Use v.in.ogr
for name in ['first', 'second']:
alg.loadRasterLayerFromParameter(name, parameters, context, False, None)
alg.postInputs()
@@ -25,71 +25,35 @@

__revision__ = '$Format:%H$'

from processing.core.outputs import getOutputFromString

import os
from processing.algs.grass7.Grass7Utils import Grass7Utils

def processInputs(alg):
# If there is another raster to copy categories from
# we need to import it with r.in.gdal rather than r.external
first = alg.getParameterValue(u'first')
second = alg.getParameterValue(u'second')
if first in list(alg.exportedLayers.keys()) and second in list(alg.exportedLayers.keys()):
def processInputs(alg, parameters, context):
if 'first' and 'second' in alg.exportedLayers:
return

# Use v.in.ogr
for name in ['first', 'second']:
alg.loadRasterLayerFromParameter(name, parameters, context, False, None)
alg.postInputs()

for raster in [first, second]:
alg.setSessionProjectionFromLayer(raster, alg.commands)

destFilename = alg.getTempFilename()
alg.exportedLayers[raster] = destFilename
command = 'r.in.gdal input={} output={} --overwrite -o'.format(raster, destFilename)
alg.commands.append(command)

alg.setSessionProjectionFromProject(alg.commands)

region = str(alg.getParameterValue(alg.GRASS_REGION_EXTENT_PARAMETER))
regionCoords = region.split(',')
command = 'g.region'
command += ' -a'
command += ' n=' + str(regionCoords[3])
command += ' s=' + str(regionCoords[2])
command += ' e=' + str(regionCoords[1])
command += ' w=' + str(regionCoords[0])
cellsize = alg.getParameterValue(alg.GRASS_REGION_CELLSIZE_PARAMETER)
if cellsize:
command += ' res=' + str(cellsize)
else:
command += ' res=' + str(alg.getDefaultCellsize(parameters, context))
alignToResolution = alg.getParameterValue(alg.GRASS_REGION_ALIGN_TO_RESOLUTION)
if alignToResolution:
command += ' -a'
alg.commands.append(command)


def processCommand(alg, parameters):
def processCommand(alg, parameters, context):
# We need to remove all outputs
basename = getOutputFromString('OutputRaster|output|Output basename')
basename.value = 'output'
alg.addOutput(basename)
outputNames = ['output_{}'.format(f) for f in ['red', 'green', 'blue']]
outputs = [alg.getOutputFromName(f) for f in outputNames]
for output in outputNames:
alg.exportedLayers[alg.getOutputValue(output)] = 'output' + alg.uniqueSuffix
alg.removeOutputFromName(output)

alg.processCommand()

# And to re-add them
alg.removeOutputFromName('output')
for output in outputs:
alg.addOutput(output)
alg.processCommand(parameters, context, True)

def processOutputs(alg, parameters, context):
createOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_OPT, context)
metaOpt = alg.parameterAsString(parameters, alg.GRASS_RASTER_FORMAT_META, context)

def processOutputs(alg):
# Export each color raster
colors = ['red', 'green', 'blue']
for color in colors:
output = alg.getOutputValue('output_{}'.format(color))
command = "r.out.gdal input={} output=\"{}\" createopt=\"TFW=YES,COMPRESS=LZW\"".format(
alg.exportedLayers[output] + '.' + color[0], output)
alg.commands.append(command)
alg.outputCommands.append(command)
fileName = os.path.normpath(
alg.parameterAsOutputLayer(parameters, 'output_{}'.format(color), context))
outFormat = Grass7Utils.getRasterFormatFromFilename(fileName)
alg.exportRasterLayer('blended.{}'.format(color[0]),
fileName, True, outFormat, createOpt, metaOpt)



@@ -26,10 +26,10 @@
__revision__ = '$Format:%H$'

import shutil
from processing.tools.system import isWindows, mkdir
from processing.core.parameters import getParameterFromString
from qgis.core import QgsProcessingParameterString
from processing.tools.system import (isWindows, mkdir,
getTempFilename)
import os
from copy import deepcopy

# for MS-Windows users who have MBCS chars in their name:
if os.name == 'nt':
@@ -85,69 +85,61 @@ def checkMovingWindow(alg, parameters, context, outputTxt=False):


def configFile(alg, parameters, context, outputTxt=False):
""" Handle inline configuration
"""Handle inline configuration
:param parameters:
"""
# Where is the GRASS7 user directory ?

new_parameters = deepcopy(parameters)

userGrass7Path = rliPath()
if not os.path.isdir(userGrass7Path):
mkdir(userGrass7Path)
if not os.path.isdir(os.path.join(userGrass7Path, 'output')):
mkdir(os.path.join(userGrass7Path, 'output'))
origConfigFile = new_parameters['config']

# If we have a configuration file, we need to copy it into user dir
if parameters['config']:
fileName = alg.parameterAsString(parameters, 'config', context)
configFilePath = os.path.join(userGrass7Path, os.path.basename(fileName))
# Copy the file
shutil.copy(parameters['config'], configFilePath)
# Change the parameter value
parameters['config'] = os.path.basename(configFilePath)
# Handle inline configuration
if new_parameters['config_txt']:
elif parameters['config_txt']:
# Creates a temporary txt file in user r.li directory
tempConfig = alg.getTempFilename()
tempConfig = os.path.basename(getTempFilename())
configFilePath = os.path.join(userGrass7Path, tempConfig)
# Inject rules into temporary txt file
with open(configFilePath, "w") as f:
f.write(new_parameters['config_txt'])
f.write(alg.parameterAsString(parameters, 'config_txt', context))
f.write("\n")

# Use temporary file as rules file
new_parameters['config'] = os.path.basename(configFilePath)
del new_parameters['config_txt']

# If we have a configuration file, we need to copy it into user dir
if origConfigFile:
configFilePath = os.path.join(userGrass7Path, os.path.basename(origConfigFile))
# Copy the file
shutil.copy(origConfigFile, configFilePath)
parameters['config'] = os.path.basename(configFilePath)
alg.removeParameter('config_txt')

# Change the parameter value
new_parameters['config'] = os.path.basename(configFilePath)

origOutput = alg.getOutputFromName('output')
if new_parameters['output']:
param = getParameterFromString("ParameterString|output|txt output|None|False|True")
new_parameters[param.name()] = origOutput.value
alg.removeOutputFromName('output')
# For ascii output, we need a virtual output
if outputTxt:
param = QgsProcessingParameterString(
'output', 'virtual output',
'a' + os.path.basename(getTempFilename()),
False, False)
alg.addParameter(param)

alg.processCommand(new_parameters, context)
alg.processCommand(parameters, context, outputTxt)

# Remove Config file:
removeConfigFile(alg, new_parameters, context)

# re-add configTxt
if outputTxt:
alg.addOutput(origOutput)

removeConfigFile(alg, parameters, context)

def moveOutputTxtFile(alg, parameters, context):
# Find output file name:
origOutput = alg.getOutputValue('output')
txtPath = alg.parameterAsString(parameters, 'output_txt', context)
userGrass7Path = rliPath()

outputDir = os.path.join(userGrass7Path, 'output')
output = os.path.join(outputDir, os.path.basename(origOutput))

output = os.path.join(userGrass7Path, 'output',
alg.parameterAsString(parameters, 'output', context))
# move the file
if isWindows():
command = "MOVE /Y {} {}".format(output, origOutput)
command = "MOVE /Y {} {}".format(output, txtPath)
else:
command = "mv -f {} {}".format(output, origOutput)
command = "mv -f {} {}".format(output, txtPath)
alg.commands.append(command)
@@ -28,9 +28,9 @@
from .r_li import checkMovingWindow, configFile


def checkParameterValuesBeforeExecuting(alg):
return checkMovingWindow(alg)
def checkParameterValuesBeforeExecuting(alg, parameters, context):
return checkMovingWindow(alg, parameters, context)


def processCommand(alg, parameters):
configFile(alg, parameters)
def processCommand(alg, parameters, context):
configFile(alg, parameters, context)
@@ -28,13 +28,13 @@
from .r_li import checkMovingWindow, configFile, moveOutputTxtFile


def checkParameterValuesBeforeExecuting(alg):
return checkMovingWindow(alg, True)
def checkParameterValuesBeforeExecuting(alg, parameters, context):
return checkMovingWindow(alg, parameters, context, True)


def processCommand(alg, parameters):
configFile(alg, parameters, True)
def processCommand(alg, parameters, context):
configFile(alg, parameters, context, True)


def processOutputs(alg):
moveOutputTxtFile(alg)
def processOutputs(alg, parameters, context):
moveOutputTxtFile(alg, parameters, context)
@@ -28,9 +28,10 @@
from .r_li import checkMovingWindow, configFile


def checkParameterValuesBeforeExecuting(alg):
return checkMovingWindow(alg)
def checkParameterValuesBeforeExecuting(alg, parameters, context):
return checkMovingWindow(alg, parameters, context)


def processCommand(alg, parameters):
configFile(alg, parameters)
def processCommand(alg, parameters, context):
configFile(alg, parameters, context)

0 comments on commit 1f8fbf3

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