Skip to content

Commit

Permalink
[processing][API]introduce QgsProcessingOutputFile output and fix gda…
Browse files Browse the repository at this point in the history
…l2xyz test
  • Loading branch information
alexbruy committed Oct 11, 2017
1 parent 79c26c3 commit 2104b27
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 15 deletions.
29 changes: 29 additions & 0 deletions python/core/processing/qgsprocessingoutputs.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

};




/************************************************************************
Expand Down
4 changes: 3 additions & 1 deletion python/plugins/processing/algs/gdal/gdal2xyz.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
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
Expand Down Expand Up @@ -57,6 +58,7 @@ def initAlgorithm(self, config=None):
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'
Expand Down
24 changes: 12 additions & 12 deletions python/plugins/processing/tests/testdata/gdal_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions src/core/processing/qgsprocessingoutputs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{}
26 changes: 26 additions & 0 deletions src/core/processing/qgsprocessingoutputs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


0 comments on commit 2104b27

Please sign in to comment.