[processing][API]introduce QgsProcessingOutputFile output and fix gdal2xyz test

This commit is contained in:
Alexander Bruy 2017-09-27 11:29:00 +03:00
parent 79c26c384d
commit 2104b273af
5 changed files with 75 additions and 15 deletions

View File

@ -39,6 +39,8 @@ class QgsProcessingOutputDefinition
sipType = sipType_QgsProcessingOutputString;
else if ( sipCpp->type() == QgsProcessingOutputFolder::typeName() )
sipType = sipType_QgsProcessingOutputFolder;
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
sipType = sipType_QgsProcessingOutputFile;
else
sipType = nullptr;
%End
@ -265,6 +267,33 @@ class QgsProcessingOutputFolder : QgsProcessingOutputDefinition
};
class QgsProcessingOutputFile : QgsProcessingOutputDefinition
{
%Docstring
A file output for processing algorithms.
.. versionadded:: 3.0
%End
%TypeHeaderCode
#include "qgsprocessingoutputs.h"
%End
public:
QgsProcessingOutputFile( const QString &name, const QString &description = QString() );
%Docstring
Constructor for QgsProcessingOutputFile.
%End
static QString typeName();
%Docstring
Returns the type name for the output class.
:rtype: str
%End
virtual QString type() const;
};
/************************************************************************

View File

@ -29,7 +29,8 @@ from qgis.core import (QgsProcessing,
QgsProcessingParameterRasterLayer,
QgsProcessingParameterBand,
QgsProcessingParameterBoolean,
QgsProcessingParameterFileDestination)
QgsProcessingParameterFileDestination,
QgsProcessingOutputFile)
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.algs.gdal.GdalUtils import GdalUtils
from processing.tools.system import isWindows
@ -57,6 +58,7 @@ class gdal2xyz(GdalAlgorithm):
self.addParameter(QgsProcessingParameterFileDestination(self.OUTPUT,
self.tr('XYZ ASCII file'),
self.tr('CSV files (*.csv)')))
self.addOutput(QgsProcessingOutputFile(self.OUTPUT, self.tr('XYZ ASCII file')))
def name(self):
return 'gdal2xyz'

View File

@ -123,18 +123,18 @@ tests:
- 'Band 1 Block=373x5 Type=Float32, ColorInterp=Gray'
- ' NoData Value=-99999'
# - algorithm: gdal:gdal2xyz
# name: gdal2xyz
# params:
# BAND: 1
# CSV: false
# INPUT:
# name: dem.tif
# type: raster
# results:
# OUTPUT:
# name: expected/gdal/xyz.csv
# type: file
- algorithm: gdal:gdal2xyz
name: gdal2xyz
params:
BAND: 1
CSV: false
INPUT:
name: dem.tif
type: raster
results:
OUTPUT:
name: expected/gdal/xyz.csv
type: file
- algorithm: gdal:tileindex
name: Tile index (gdaltindex)

View File

@ -57,5 +57,8 @@ QgsProcessingOutputString::QgsProcessingOutputString( const QString &name, const
QgsProcessingOutputFolder::QgsProcessingOutputFolder( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{
}
{}
QgsProcessingOutputFile::QgsProcessingOutputFile( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{}

View File

@ -55,6 +55,8 @@ class CORE_EXPORT QgsProcessingOutputDefinition
sipType = sipType_QgsProcessingOutputString;
else if ( sipCpp->type() == QgsProcessingOutputFolder::typeName() )
sipType = sipType_QgsProcessingOutputFolder;
else if ( sipCpp->type() == QgsProcessingOutputFile::typeName() )
sipType = sipType_QgsProcessingOutputFile;
else
sipType = nullptr;
SIP_END
@ -269,6 +271,30 @@ class CORE_EXPORT QgsProcessingOutputFolder : public QgsProcessingOutputDefiniti
};
/**
* \class QgsProcessingOutputFile
* \ingroup core
* A file output for processing algorithms.
* \since QGIS 3.0
*/
class CORE_EXPORT QgsProcessingOutputFile : public QgsProcessingOutputDefinition
{
public:
/**
* Constructor for QgsProcessingOutputFile.
*/
QgsProcessingOutputFile( const QString &name, const QString &description = QString() );
/**
* Returns the type name for the output class.
*/
static QString typeName() { return QStringLiteral( "outputFile" ); }
QString type() const override { return typeName(); }
};
#endif // QGSPROCESSINGOUTPUTS_H