Skip to content

Commit

Permalink
Merge pull request #44583 from alexbruy/processing-pointcloud
Browse files Browse the repository at this point in the history
Point cloud parameter for Processing
  • Loading branch information
alexbruy committed Aug 6, 2021
2 parents e2ba24c + 7a7c347 commit 00dad40
Show file tree
Hide file tree
Showing 21 changed files with 900 additions and 30 deletions.
5 changes: 4 additions & 1 deletion python/core/auto_additions/qgsprocessingutils.py
Expand Up @@ -12,5 +12,8 @@
QgsProcessingUtils.Mesh = QgsProcessingUtils.LayerHint.Mesh
QgsProcessingUtils.Mesh.is_monkey_patched = True
QgsProcessingUtils.LayerHint.Mesh.__doc__ = "Mesh layer type, since QGIS 3.6"
QgsProcessingUtils.LayerHint.__doc__ = 'Layer type hints.\n\n.. versionadded:: 3.4\n\n' + '* ``UnknownType``: ' + QgsProcessingUtils.LayerHint.UnknownType.__doc__ + '\n' + '* ``Vector``: ' + QgsProcessingUtils.LayerHint.Vector.__doc__ + '\n' + '* ``Raster``: ' + QgsProcessingUtils.LayerHint.Raster.__doc__ + '\n' + '* ``Mesh``: ' + QgsProcessingUtils.LayerHint.Mesh.__doc__
QgsProcessingUtils.PointCloud = QgsProcessingUtils.LayerHint.PointCloud
QgsProcessingUtils.PointCloud.is_monkey_patched = True
QgsProcessingUtils.LayerHint.PointCloud.__doc__ = "Point cloud layer type, since QGIS 3.22"
QgsProcessingUtils.LayerHint.__doc__ = 'Layer type hints.\n\n.. versionadded:: 3.4\n\n' + '* ``UnknownType``: ' + QgsProcessingUtils.LayerHint.UnknownType.__doc__ + '\n' + '* ``Vector``: ' + QgsProcessingUtils.LayerHint.Vector.__doc__ + '\n' + '* ``Raster``: ' + QgsProcessingUtils.LayerHint.Raster.__doc__ + '\n' + '* ``Mesh``: ' + QgsProcessingUtils.LayerHint.Mesh.__doc__ + '\n' + '* ``PointCloud``: ' + QgsProcessingUtils.LayerHint.PointCloud.__doc__
# --
3 changes: 2 additions & 1 deletion python/core/auto_generated/processing/qgsprocessing.sip.in
Expand Up @@ -37,7 +37,8 @@ and parameters.
TypeFile,
TypeVector,
TypeMesh,
TypePlugin
TypePlugin,
TypePointCloud
};

enum PythonOutputType
Expand Down
Expand Up @@ -795,7 +795,6 @@ need to handle deletion of the returned layer.
.. versionadded:: 3.6
%End


QString parameterAsOutputLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a output layer destination.
Expand Down Expand Up @@ -887,8 +886,6 @@ Returns the coordinate reference system associated with a geometry parameter val
.. seealso:: :py:func:`parameterAsGeometry`
%End



QString parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a file/folder name.
Expand Down Expand Up @@ -981,6 +978,16 @@ Evaluates the parameter with matching ``name`` to a DateTime, or returns an inva
.. versionadded:: 3.14
%End

QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
%Docstring
Evaluates the parameter with matching ``name`` to a point cloud layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

static QString invalidSourceError( const QVariantMap &parameters, const QString &name );
%Docstring
Expand Down
Expand Up @@ -321,6 +321,8 @@ their acceptable ranges, defaults, etc.
sipType = sipType_QgsProcessingParameterMeshDatasetGroups;
else if ( sipCpp->type() == QgsProcessingParameterMeshDatasetTime::typeName() )
sipType = sipType_QgsProcessingParameterMeshDatasetTime;
else if ( sipCpp->type() == QgsProcessingParameterPointCloudLayer::typeName() )
sipType = sipType_QgsProcessingParameterPointCloudLayer;
else
sipType = nullptr;
%End
Expand Down Expand Up @@ -1194,7 +1196,6 @@ need to handle deletion of the returned layer.
.. versionadded:: 3.6
%End


static QgsCoordinateReferenceSystem parameterAsCrs( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a coordinate reference system.
Expand Down Expand Up @@ -1515,6 +1516,29 @@ Evaluates the parameter with matching ``definition`` and ``value`` to a database
.. versionadded:: 3.14
%End

static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` to a point cloud layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End

static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
%Docstring
Evaluates the parameter with matching ``definition`` and ``value`` to a point cloud layer.

Layers will either be taken from ``context``'s active project, or loaded from external
sources and stored temporarily in the ``context``. In either case, callers do not
need to handle deletion of the returned layer.

.. versionadded:: 3.22
%End


static QgsProcessingParameterDefinition *parameterFromVariantMap( const QVariantMap &map ) /Factory/;
%Docstring
Creates a new :py:class:`QgsProcessingParameterDefinition` using the configuration from a
Expand Down Expand Up @@ -4445,6 +4469,46 @@ a new (non-existing) tables.
};


class QgsProcessingParameterPointCloudLayer : QgsProcessingParameterDefinition, QgsFileFilterGenerator
{
%Docstring(signature="appended")
A point cloud layer parameter for processing algorithms.

.. versionadded:: 3.22
%End

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

QgsProcessingParameterPointCloudLayer( const QString &name, const QString &description = QString(),
const QVariant &defaultValue = QVariant(), bool optional = false );
%Docstring
Constructor for QgsProcessingParameterPointCloudLayer.
%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 QString createFileFilter() const;


static QgsProcessingParameterPointCloudLayer *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
30 changes: 30 additions & 0 deletions python/core/auto_generated/processing/qgsprocessingutils.sip.in
Expand Up @@ -39,6 +39,8 @@ value.

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatiblePointCloudLayers`

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

Expand All @@ -63,6 +65,8 @@ value.

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatiblePointCloudLayers`

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

Expand All @@ -80,6 +84,8 @@ value.

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.6
Expand All @@ -99,6 +105,29 @@ value.

.. seealso:: :py:func:`compatibleMeshLayers`

.. seealso:: :py:func:`compatiblePointCloudLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.22
%End

static QList<QgsPointCloudLayer *> compatiblePointCloudLayers( QgsProject *project, bool sort = true );
%Docstring
Returns a list of point cloud layers from a ``project`` which are compatible with the processing
framework.

If the ``sort`` argument is ``True`` then the layers will be sorted by their :py:func:`QgsMapLayer.name()`
value.

.. seealso:: :py:func:`compatibleRasterLayers`

.. seealso:: :py:func:`compatibleVectorLayers`

.. seealso:: :py:func:`compatibleMeshLayers`

.. seealso:: :py:func:`compatiblePluginLayers`

.. seealso:: :py:func:`compatibleLayers`

.. versionadded:: 3.22
Expand Down Expand Up @@ -145,6 +174,7 @@ Decodes a provider key and layer ``uri`` from an encoded string, for use with
Vector,
Raster,
Mesh,
PointCloud,
};

static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType );
Expand Down
6 changes: 5 additions & 1 deletion python/processing/algfactory.py
Expand Up @@ -66,6 +66,7 @@
QgsProcessingParameterDatabaseSchema,
QgsProcessingParameterDatabaseTable,
QgsProcessingParameterCoordinateOperation,
QgsProcessingParameterPointCloudLayer,
QgsProcessingOutputString,
QgsProcessingOutputBoolean,
QgsProcessingOutputFile,
Expand Down Expand Up @@ -344,6 +345,7 @@ class ProcessingAlgFactory():
DATABASE_SCHEMA = "DATABASE_SCHEMA"
DATABASE_TABLE = "DATABASE_TABLE"
COORDINATE_OPERATION = "COORDINATE_OPERATION"
POINT_CLOUD_LAYER = "POINT_CLOUD_LAYER"

def __init__(self):
self._current = None
Expand Down Expand Up @@ -483,6 +485,7 @@ def input(self, type, *args, **kwargs):
alg.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema
alg.DATABASE_TABLE: QgsProcessingParameterDatabaseTable
alg.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation
alg.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer
:param type: The type of the input. This should be a type define on `alg` like alg.STRING, alg.DISTANCE
:keyword label: The label of the output. Translates into `description` arg.
Expand Down Expand Up @@ -540,7 +543,8 @@ def dec(f):
ProcessingAlgFactory.PROVIDER_CONNECTION: QgsProcessingParameterProviderConnection,
ProcessingAlgFactory.DATABASE_SCHEMA: QgsProcessingParameterDatabaseSchema,
ProcessingAlgFactory.DATABASE_TABLE: QgsProcessingParameterDatabaseTable,
ProcessingAlgFactory.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation
ProcessingAlgFactory.COORDINATE_OPERATION: QgsProcessingParameterCoordinateOperation,
ProcessingAlgFactory.POINT_CLOUD_LAYER: QgsProcessingParameterPointCloudLayer
}

output_type_mapping = {
Expand Down
7 changes: 5 additions & 2 deletions src/core/processing/qgsprocessing.h
Expand Up @@ -44,7 +44,7 @@ class CORE_EXPORT QgsProcessing
//! Data source types enum
enum SourceType
{
TypeMapLayer = -2, //!< Any map layer type (raster or vector or mesh)
TypeMapLayer = -2, //!< Any map layer type (raster, vector, mesh, point cloud or plugin layer)
TypeVectorAnyGeometry = -1, //!< Any vector layer with geometry
TypeVectorPoint = 0, //!< Vector point layers
TypeVectorLine = 1, //!< Vector line layers
Expand All @@ -53,7 +53,8 @@ class CORE_EXPORT QgsProcessing
TypeFile = 4, //!< Files (i.e. non map layer sources, such as text files)
TypeVector = 5, //!< Tables (i.e. vector layers with or without geometry). When used for a sink this indicates the sink has no geometry.
TypeMesh = 6, //!< Mesh layers \since QGIS 3.6
TypePlugin = 7 //!< Plugin layers \since QGIS 3.22
TypePlugin = 7, //!< Plugin layers \since QGIS 3.22
TypePointCloud = 8 //!< Point cloud layers \since QGIS 3.22
};

//! Available Python output types
Expand Down Expand Up @@ -91,6 +92,8 @@ class CORE_EXPORT QgsProcessing
return QStringLiteral( "TypeMesh" );
case QgsProcessing::TypePlugin:
return QStringLiteral( "TypePlugin" );
case QgsProcessing::TypePointCloud:
return QStringLiteral( "TypePointCloud" );
}
return QString();
}
Expand Down
6 changes: 6 additions & 0 deletions src/core/processing/qgsprocessingalgorithm.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsvectorlayer.h"
#include "qgsprocessingfeedback.h"
#include "qgsmeshlayer.h"
#include "qgspointcloudlayer.h"
#include "qgsexpressioncontextutils.h"


Expand Down Expand Up @@ -795,6 +796,11 @@ QString QgsProcessingAlgorithm::parameterAsDatabaseTableName( const QVariantMap
return QgsProcessingParameters::parameterAsDatabaseTableName( parameterDefinition( name ), parameters, context );
}

QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
{
return QgsProcessingParameters::parameterAsPointCloudLayer( parameterDefinition( name ), parameters, context );
}

QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
{
if ( !parameters.contains( name ) )
Expand Down
14 changes: 11 additions & 3 deletions src/core/processing/qgsprocessingalgorithm.h
Expand Up @@ -35,6 +35,7 @@ class QgsFeatureSink;
class QgsProcessingModelAlgorithm;
class QgsProcessingAlgorithmConfigurationWidget;
class QgsMeshLayer;
class QgsPointCloudLayer;

#ifdef SIP_RUN
% ModuleHeaderCode
Expand Down Expand Up @@ -797,7 +798,6 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsMeshLayer *parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;


/**
* Evaluates the parameter with matching \a name to a output layer destination.
*/
Expand Down Expand Up @@ -889,8 +889,6 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );



/**
* Evaluates the parameter with matching \a name to a file/folder name.
*/
Expand Down Expand Up @@ -979,6 +977,16 @@ class CORE_EXPORT QgsProcessingAlgorithm
*/
QDateTime parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );

/**
* Evaluates the parameter with matching \a name to a point cloud layer.
*
* Layers will either be taken from \a context's active project, or loaded from external
* sources and stored temporarily in the \a context. In either case, callers do not
* need to handle deletion of the returned layer.
*
* \since QGIS 3.22
*/
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;

/**
* Returns a user-friendly string to use as an error when a source parameter could
Expand Down

0 comments on commit 00dad40

Please sign in to comment.