mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-14 00:07:35 -04:00
Add i.cca algorithm (segfaults from GRASS)
This commit is contained in:
parent
02bbcbb81a
commit
1d1534279f
@ -0,0 +1,6 @@
|
||||
i.cca
|
||||
Canonical components analysis (CCA) program for image processing.
|
||||
Imagery (i.*)
|
||||
ParameterMultipleInput|input|Input rasters (2 to 8)|3|False
|
||||
ParameterFile|signature|File containing spectral signatures|False|False
|
||||
OutputDirectory|output|Output Directory
|
@ -4,9 +4,9 @@
|
||||
***************************************************************************
|
||||
i.py
|
||||
----
|
||||
Date : February 2016
|
||||
Date : April 2016
|
||||
Copyright : (C) 2016 by Médéric Ribreux
|
||||
Email : medspx at medspx dot fr
|
||||
Email : mederic dot ribreux at medspx dot fr
|
||||
***************************************************************************
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or modify *
|
||||
@ -18,7 +18,7 @@
|
||||
"""
|
||||
|
||||
__author__ = 'Médéric Ribreux'
|
||||
__date__ = 'March 2016'
|
||||
__date__ = 'April 2016'
|
||||
__copyright__ = '(C) 2016, Médéric Ribreux'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
@ -94,12 +94,13 @@ def orderedInput(alg, inputParameter, targetParameterDef):
|
||||
return rootFilename
|
||||
|
||||
|
||||
def regroupRasters(alg, field, groupField, subgroupField=None, sigsetField=None):
|
||||
def regroupRasters(alg, field, groupField, subgroupField=None, extFile=None):
|
||||
"""
|
||||
Group multiple input rasters into a group
|
||||
* If there is a subgroupField, a subgroup will automatically created.
|
||||
* When a sigset file is provided, the file is copied into the sigset
|
||||
* When an external file is provided, the file is copied into the respective
|
||||
directory of the subgroup.
|
||||
* extFile is a dict of the form 'parameterName':'directory name'.
|
||||
"""
|
||||
# List of rasters names
|
||||
rasters = alg.getParameterFromName(field)
|
||||
@ -123,24 +124,32 @@ def regroupRasters(alg, field, groupField, subgroupField=None, sigsetField=None)
|
||||
)
|
||||
alg.commands.append(command)
|
||||
|
||||
# If there is a sigset and a subgroupField, we copy the sigset file
|
||||
if subgroupField and sigsetField:
|
||||
sigsetFile = alg.getParameterValue(sigsetField)
|
||||
shortSigsetFile = path.basename(sigsetFile)
|
||||
if sigsetFile:
|
||||
interSigsetFile = path.join(Grass7Utils.grassMapsetFolder(),
|
||||
'PERMANENT',
|
||||
'group', group.value,
|
||||
'subgroup', subgroup.value,
|
||||
'sigset', shortSigsetFile)
|
||||
copyFile(alg, sigsetFile, interSigsetFile)
|
||||
alg.setParameterValue(sigsetField, shortSigsetFile)
|
||||
# Handle external files
|
||||
origExtParams = {}
|
||||
if subgroupField and extFile:
|
||||
for ext in extFile.keys():
|
||||
extFileName = alg.getParameterValue(ext)
|
||||
if extFileName:
|
||||
shortFileName = path.basename(extFileName)
|
||||
destPath = path.join(Grass7Utils.grassMapsetFolder(),
|
||||
'PERMANENT',
|
||||
'group', group.value,
|
||||
'subgroup', subgroup.value,
|
||||
extFile[ext], shortFileName)
|
||||
copyFile(alg, extFileName, destPath)
|
||||
origExtParams[ext] = extFileName
|
||||
alg.setParameterValue(ext, shortFileName)
|
||||
|
||||
# modify parameters values
|
||||
alg.processCommand()
|
||||
|
||||
# Re-add input rasters
|
||||
alg.addParameter(rasters)
|
||||
|
||||
# replace external files value with original value
|
||||
for param in origExtParams.keys():
|
||||
alg.setParameterValue(param, origExtParams[param])
|
||||
|
||||
# Delete group:
|
||||
alg.parameters.remove(group)
|
||||
if subgroupField:
|
||||
|
58
python/plugins/processing/algs/grass7/ext/i_cca.py
Normal file
58
python/plugins/processing/algs/grass7/ext/i_cca.py
Normal file
@ -0,0 +1,58 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
***************************************************************************
|
||||
i_cca.py
|
||||
--------
|
||||
Date : March 2016
|
||||
Copyright : (C) 2016 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__ = 'March 2016'
|
||||
__copyright__ = '(C) 2016, Médéric Ribreux'
|
||||
|
||||
# This will get replaced with a git SHA1 when you do a git archive
|
||||
|
||||
__revision__ = '$Format:%H$'
|
||||
|
||||
from i import multipleOutputDir, verifyRasterNum, regroupRasters
|
||||
from processing.core.parameters import getParameterFromString
|
||||
|
||||
|
||||
def checkParameterValuesBeforeExecuting(alg):
|
||||
return verifyRasterNum(alg, 'input', 2, 8)
|
||||
|
||||
|
||||
def processCommand(alg):
|
||||
# Remove output
|
||||
output = alg.getOutputFromName('output')
|
||||
alg.removeOutputFromName('output')
|
||||
|
||||
# Create output parameter
|
||||
param = getParameterFromString("ParameterString|output|output basename|None|False|False")
|
||||
param.value = alg.getTempFilename()
|
||||
alg.addParameter(param)
|
||||
|
||||
# Regroup rasters
|
||||
regroupRasters(alg, 'input', 'group', 'subgroup', {'signature': 'sig'})
|
||||
|
||||
# re-add output
|
||||
alg.addOutput(output)
|
||||
|
||||
|
||||
def processOutputs(alg):
|
||||
param = alg.getParameterFromName('output')
|
||||
multipleOutputDir(alg, 'output', param.value)
|
||||
|
||||
# Delete output parameter
|
||||
alg.parameters.remove(param)
|
@ -30,4 +30,4 @@ from i import regroupRasters, file2Output
|
||||
|
||||
def processCommand(alg):
|
||||
# Regroup rasters
|
||||
regroupRasters(alg, 'input', 'group', 'subgroup', 'signaturefile')
|
||||
regroupRasters(alg, 'input', 'group', 'subgroup', {'signaturefile': 'sigset'})
|
||||
|
Loading…
x
Reference in New Issue
Block a user