Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] add point cloud output and point cloud destination param…
…eter

to Processing. These are useful for 3rd party tools as outputs can be
automatically loaded on algorithm completion.

It is an API change not visible for users.
  • Loading branch information
alexbruy authored and nyalldawson committed Nov 26, 2021
1 parent e7ae0f4 commit 88d7a62
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 72 deletions.
38 changes: 26 additions & 12 deletions python/core/auto_generated/processing/qgsprocessingoutputs.sip.in
Expand Up @@ -31,6 +31,8 @@ as generated layers or calculated values.
sipType = sipType_QgsProcessingOutputVectorLayer;
else if ( sipCpp->type() == QgsProcessingOutputRasterLayer::typeName() )
sipType = sipType_QgsProcessingOutputRasterLayer;
else if ( sipCpp->type() == QgsProcessingOutputPointCloudLayer::typeName() )
sipType = sipType_QgsProcessingOutputPointCloudLayer;
else if ( sipCpp->type() == QgsProcessingOutputMapLayer::typeName() )
sipType = sipType_QgsProcessingOutputMapLayer;
else if ( sipCpp->type() == QgsProcessingOutputMultipleLayers::typeName() )
Expand Down Expand Up @@ -122,7 +124,6 @@ Returns ``True`` if the output was automatically created when adding a parameter




};

typedef QList< const QgsProcessingOutputDefinition * > QgsProcessingOutputDefinitions;
Expand Down Expand Up @@ -155,7 +156,6 @@ Returns the type name for the output class.

virtual QString type() const;


};

class QgsProcessingOutputVectorLayer : QgsProcessingOutputDefinition
Expand Down Expand Up @@ -221,8 +221,31 @@ Constructor for QgsProcessingOutputRasterLayer.
Returns the type name for the output class.
%End
virtual QString type() const;
};

class QgsProcessingOutputPointCloudLayer : QgsProcessingOutputDefinition
{
%Docstring(signature="appended")
A pointcloud layer output for processing algorithms.

.. versionadded:: 3.24
%End

%TypeHeaderCode
#include "qgsprocessingoutputs.h"
%End
public:

QgsProcessingOutputPointCloudLayer( const QString &name, const QString &description = QString() );
%Docstring
Constructor for QgsProcessingOutputPointCloudLayer.
%End

static QString typeName();
%Docstring
Returns the type name for the output class.
%End
virtual QString type() const;
};

class QgsProcessingOutputMultipleLayers : QgsProcessingOutputDefinition
Expand All @@ -234,7 +257,7 @@ the number and nature of the output layers is not predefined.
.. note::

Always prefer to explicitly define :py:class:`QgsProcessingOutputVectorLayer`,
QgsProcessingOutputRasterLayer or QgsProcessingOutputMapLayer where possible. :py:class:`QgsProcessingOutputMultipleLayers`
:py:class:`QgsProcessingOutputRasterLayer` or :py:class:`QgsProcessingOutputMapLayer` where possible. :py:class:`QgsProcessingOutputMultipleLayers`
should only ever be used when the number of output layers is not
fixed - e.g. as a result of processing all layers in a specified
folder.
Expand All @@ -258,7 +281,6 @@ Returns the type name for the output class.
%End
virtual QString type() const;


};

class QgsProcessingOutputHtml : QgsProcessingOutputDefinition
Expand All @@ -284,7 +306,6 @@ Constructor for QgsProcessingOutputHtml.
Returns the type name for the output class.
%End
virtual QString type() const;

};

class QgsProcessingOutputNumber : QgsProcessingOutputDefinition
Expand Down Expand Up @@ -335,7 +356,6 @@ Constructor for QgsProcessingOutputString.
Returns the type name for the output class.
%End
virtual QString type() const;

};

class QgsProcessingOutputBoolean : QgsProcessingOutputDefinition
Expand Down Expand Up @@ -387,7 +407,6 @@ Constructor for QgsProcessingOutputFolder.
Returns the type name for the output class.
%End
virtual QString type() const;

};

class QgsProcessingOutputFile : QgsProcessingOutputDefinition
Expand All @@ -413,7 +432,6 @@ Constructor for QgsProcessingOutputFile.
Returns the type name for the output class.
%End
virtual QString type() const;

};

class QgsProcessingOutputConditionalBranch : QgsProcessingOutputDefinition
Expand All @@ -440,12 +458,8 @@ Constructor for QgsProcessingOutputConditionalBranch.
Returns the type name for the output class.
%End
virtual QString type() const;

};




/************************************************************************
* This file has been generated automatically from *
* *
Expand Down
Expand Up @@ -285,6 +285,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterVectorDestination;
else if ( sipCpp->type() == QgsProcessingParameterRasterDestination::typeName() )
sipType = sipType_QgsProcessingParameterRasterDestination;
else if ( sipCpp->type() == QgsProcessingParameterPointCloudDestination::typeName() )
sipType = sipType_QgsProcessingParameterPointCloudDestination;
else if ( sipCpp->type() == QgsProcessingParameterFileDestination::typeName() )
sipType = sipType_QgsProcessingParameterFileDestination;
else if ( sipCpp->type() == QgsProcessingParameterFolderDestination::typeName() )
Expand Down Expand Up @@ -4581,6 +4583,62 @@ Creates a new parameter using the definition from a script code.
%End
};

class QgsProcessingParameterPointCloudDestination : QgsProcessingDestinationParameter
{
%Docstring(signature="appended")
A point cloud layer destination parameter, for specifying the destination path for a point cloud layer
created by the algorithm.

.. versionadded:: 3.24
%End

%TypeHeaderCode
#include "qgsprocessingparameters.h"
%End
public:

QgsProcessingParameterPointCloudDestination( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(),
bool optional = false,
bool createByDefault = true );
%Docstring
Constructor for QgsProcessingParameterPointCloudDestination.

If ``createByDefault`` is ``False`` and the parameter is ``optional``, then this destination
output will not be created by default.
%End

static QString typeName();
%Docstring
Returns the type name for the parameter class.
%End
virtual QgsProcessingParameterDefinition *clone() const /Factory/;

virtual QString type() const;
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;

virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;

virtual QgsProcessingOutputDefinition *toOutputDefinition() const /Factory/;

virtual QString defaultFileExtension() const;

virtual QString createFileFilter() const;


virtual QStringList supportedOutputPointCloudLayerExtensions() const;
%Docstring
Returns a list of the point cloud format file extensions supported for this parameter.

.. seealso:: :py:func:`defaultFileExtension`
%End

static QgsProcessingParameterPointCloudDestination *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
%Docstring
Creates a new parameter using the definition from a script code.
%End
};




Expand Down
43 changes: 43 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingprovider.sip.in
Expand Up @@ -158,6 +158,25 @@ Returns a list of the vector format file extensions supported by this provider.
.. seealso:: :py:func:`supportedOutputRasterLayerExtensions`

.. seealso:: :py:func:`supportsNonFileBasedOutput`

.. seealso:: :py:func:`supportedOutputPointCloudLayerExtensions`
%End

virtual QStringList supportedOutputPointCloudLayerExtensions() const;
%Docstring
Returns a list of the point cloud format file extensions supported by this provider.

.. seealso:: :py:func:`supportedOutputVectorLayerExtensions`

.. seealso:: :py:func:`supportedOutputRasterLayerExtensions`

.. seealso:: :py:func:`supportedOutputTableExtensions`

.. seealso:: :py:func:`defaultVectorFileExtension`

.. seealso:: :py:func:`supportsNonFileBasedOutput`

.. versionadded:: 3.24
%End

virtual QStringList supportedOutputTableExtensions() const;
Expand All @@ -175,6 +194,8 @@ formats for geometry-less layers can override this method to return a different

.. seealso:: :py:func:`supportsNonFileBasedOutput`

.. seealso:: :py:func:`supportedOutputPointCloudLayerExtensions`

.. versionadded:: 3.4.3
%End

Expand Down Expand Up @@ -202,6 +223,8 @@ Otherwise the first reported supported vector format will be used.
.. seealso:: :py:func:`supportedOutputVectorLayerExtensions`

.. seealso:: :py:func:`defaultRasterFileExtension`

.. seealso:: :py:func:`defaultPointCloudFileExtension`
%End

virtual QString defaultRasterFileExtension() const;
Expand All @@ -216,6 +239,26 @@ Otherwise the first reported supported raster format will be used.
.. seealso:: :py:func:`supportedOutputRasterLayerExtensions`

.. seealso:: :py:func:`defaultVectorFileExtension`

.. seealso:: :py:func:`defaultPointCloudFileExtension`
%End

virtual QString defaultPointCloudFileExtension() const;
%Docstring
Returns the default file extension to use for point cloud outputs created by the
provider.

The default implementation returns the user's default Processing point cloud output format
setting, if it's supported by the provider (see :py:func:`~QgsProcessingProvider.supportedOutputPointCloudLayerExtensions`).
Otherwise the first reported supported point cloud format will be used.

.. seealso:: :py:func:`supportedOutputPointCloudLayerExtensions`

.. seealso:: :py:func:`defaultVectorFileExtension`

.. seealso:: :py:func:`defaultRasterFileExtension`

.. versionadded:: 3.24
%End

virtual bool supportsNonFileBasedOutput() const;
Expand Down
19 changes: 19 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingutils.sip.in
Expand Up @@ -456,6 +456,8 @@ a fallback value of "gpkg".

.. seealso:: :py:func:`defaultRasterExtension`

.. seealso:: :py:func:`defaultPointCloudExtension`

.. versionadded:: 3.10
%End

Expand All @@ -469,9 +471,26 @@ a fallback value of "tif".

.. seealso:: :py:func:`defaultVectorExtension`

.. seealso:: :py:func:`defaultPointCloudExtension`

.. versionadded:: 3.10
%End

static QString defaultPointCloudExtension();
%Docstring
Returns the default point cloud extension to use, in the absence of all other constraints (e.g.
provider based support for extensions).

This method returns a fallback value of "las".

.. seealso:: :py:func:`defaultVectorExtension`

.. seealso:: :py:func:`defaultRasterExtension`

.. versionadded:: 3.24
%End


};

class QgsProcessingFeatureSource : QgsFeatureSource
Expand Down
3 changes: 2 additions & 1 deletion python/plugins/processing/core/Processing.py
Expand Up @@ -38,6 +38,7 @@
QgsProcessingParameterDefinition,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputRasterLayer,
QgsProcessingOutputPointCloudLayer,
QgsProcessingOutputMapLayer,
QgsProcessingOutputMultipleLayers,
QgsProcessingFeedback,
Expand Down Expand Up @@ -172,7 +173,7 @@ def runAlgorithm(algOrName, parameters, onFinish=None, feedback=None, context=No
if out.name() not in results:
continue

if isinstance(out, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer, QgsProcessingOutputMapLayer)):
if isinstance(out, (QgsProcessingOutputVectorLayer, QgsProcessingOutputRasterLayer, QgsProcessingOutputPointCloudLayer, QgsProcessingOutputMapLayer)):
result = results[out.name()]
if not isinstance(result, QgsMapLayer):
layer = context.takeResultLayer(result) # transfer layer ownership out of context
Expand Down
5 changes: 4 additions & 1 deletion python/plugins/processing/core/outputs.py
Expand Up @@ -40,7 +40,8 @@
QgsProcessingOutputString,
QgsProcessingOutputBoolean,
QgsProcessingOutputFolder,
QgsProcessingOutputMultipleLayers)
QgsProcessingOutputMultipleLayers,
QgsProcessingOutputPointCloudLayer)


def getOutputFromString(s):
Expand Down Expand Up @@ -92,6 +93,8 @@ def getOutputFromString(s):
out = QgsProcessingOutputString(name, description)
elif token.lower().strip().startswith('outputboolean'):
out = QgsProcessingOutputBoolean(name, description)
elif token.lower().strip().startswith('outputPointCloud'):
out = QgsProcessingOutputPointCloudLayer(name, description)
# elif token.lower().strip().startswith('extent'):
# out = OutputExtent()

Expand Down
8 changes: 8 additions & 0 deletions python/plugins/processing/core/parameters.py
Expand Up @@ -54,6 +54,7 @@
QgsProcessingParameterFileDestination,
QgsProcessingParameterFolderDestination,
QgsProcessingParameterRasterDestination,
QgsProcessingParameterPointCloudDestination,
QgsProcessingParameterString,
QgsProcessingParameterMapLayer,
QgsProcessingParameterMultipleLayers,
Expand Down Expand Up @@ -91,6 +92,7 @@
PARAMETER_FILE_DESTINATION = 'fileDestination'
PARAMETER_FOLDER_DESTINATION = 'folderDestination'
PARAMETER_RASTER_DESTINATION = 'rasterDestination'
PARAMETER_POINTCLOUD_DESTINATION = 'pointCloudDestination'


def getParameterFromString(s, context=''):
Expand Down Expand Up @@ -267,6 +269,12 @@ def getParameterFromString(s, context=''):
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
params[4] = True if params[4].lower() == 'true' else False
elif clazz == QgsProcessingParameterPointCloudDestination:
print(params)
if len(params) > 3:
params[3] = True if params[3].lower() == 'true' else False
if len(params) > 4:
params[4] = True if params[4].lower() == 'true' else False
elif clazz == QgsProcessingParameterVectorDestination:
if len(params) > 2:
try:
Expand Down
12 changes: 6 additions & 6 deletions src/core/processing/qgsprocessingoutputs.cpp
Expand Up @@ -20,9 +20,7 @@
QgsProcessingOutputDefinition::QgsProcessingOutputDefinition( const QString &name, const QString &description )
: mName( name )
, mDescription( description )
{

}
{}

QgsProcessingOutputVectorLayer::QgsProcessingOutputVectorLayer( const QString &name, const QString &description, QgsProcessing::SourceType type )
: QgsProcessingOutputDefinition( name, description )
Expand All @@ -43,6 +41,10 @@ QgsProcessingOutputRasterLayer::QgsProcessingOutputRasterLayer( const QString &n
: QgsProcessingOutputDefinition( name, description )
{}

QgsProcessingOutputPointCloudLayer::QgsProcessingOutputPointCloudLayer( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{}

QgsProcessingOutputHtml::QgsProcessingOutputHtml( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{}
Expand Down Expand Up @@ -87,6 +89,4 @@ QString QgsProcessingOutputMultipleLayers::type() const

QgsProcessingOutputConditionalBranch::QgsProcessingOutputConditionalBranch( const QString &name, const QString &description )
: QgsProcessingOutputDefinition( name, description )
{

}
{}

0 comments on commit 88d7a62

Please sign in to comment.