Skip to content

Commit f801cb6

Browse files
committedAug 5, 2021
[processing] new pont cloud parameter for processing
1 parent d01aa28 commit f801cb6

12 files changed

+338
-15
lines changed
 

‎python/core/auto_additions/qgsprocessingutils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,8 @@
1212
QgsProcessingUtils.Mesh = QgsProcessingUtils.LayerHint.Mesh
1313
QgsProcessingUtils.Mesh.is_monkey_patched = True
1414
QgsProcessingUtils.LayerHint.Mesh.__doc__ = "Mesh layer type, since QGIS 3.6"
15-
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__
15+
QgsProcessingUtils.PointCloud = QgsProcessingUtils.LayerHint.PointCloud
16+
QgsProcessingUtils.PointCloud.is_monkey_patched = True
17+
QgsProcessingUtils.LayerHint.PointCloud.__doc__ = "Point cloud layer type, since QGIS 3.22"
18+
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__
1619
# --

‎python/core/auto_generated/processing/qgsprocessingalgorithm.sip.in

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ need to handle deletion of the returned layer.
795795
.. versionadded:: 3.6
796796
%End
797797

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

890-
891-
892889
QString parameterAsFile( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
893890
%Docstring
894891
Evaluates the parameter with matching ``name`` to a file/folder name.
@@ -981,6 +978,16 @@ Evaluates the parameter with matching ``name`` to a DateTime, or returns an inva
981978
.. versionadded:: 3.14
982979
%End
983980

981+
QgsPointCloudLayer *parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
982+
%Docstring
983+
Evaluates the parameter with matching ``name`` to a point cloud layer.
984+
985+
Layers will either be taken from ``context``'s active project, or loaded from external
986+
sources and stored temporarily in the ``context``. In either case, callers do not
987+
need to handle deletion of the returned layer.
988+
989+
.. versionadded:: 3.22
990+
%End
984991

985992
static QString invalidSourceError( const QVariantMap &parameters, const QString &name );
986993
%Docstring

‎python/core/auto_generated/processing/qgsprocessingparameters.sip.in

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ their acceptable ranges, defaults, etc.
321321
sipType = sipType_QgsProcessingParameterMeshDatasetGroups;
322322
else if ( sipCpp->type() == QgsProcessingParameterMeshDatasetTime::typeName() )
323323
sipType = sipType_QgsProcessingParameterMeshDatasetTime;
324+
else if ( sipCpp->type() == QgsProcessingParameterPointCloudLayer::typeName() )
325+
sipType = sipType_QgsProcessingParameterPointCloudLayer;
324326
else
325327
sipType = nullptr;
326328
%End
@@ -1194,7 +1196,6 @@ need to handle deletion of the returned layer.
11941196
.. versionadded:: 3.6
11951197
%End
11961198

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

1519+
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1520+
%Docstring
1521+
Evaluates the parameter with matching ``definition`` to a point cloud layer.
1522+
1523+
Layers will either be taken from ``context``'s active project, or loaded from external
1524+
sources and stored temporarily in the ``context``. In either case, callers do not
1525+
need to handle deletion of the returned layer.
1526+
1527+
.. versionadded:: 3.22
1528+
%End
1529+
1530+
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1531+
%Docstring
1532+
Evaluates the parameter with matching ``definition`` and ``value`` to a point cloud layer.
1533+
1534+
Layers will either be taken from ``context``'s active project, or loaded from external
1535+
sources and stored temporarily in the ``context``. In either case, callers do not
1536+
need to handle deletion of the returned layer.
1537+
1538+
.. versionadded:: 3.22
1539+
%End
1540+
1541+
15181542
static QgsProcessingParameterDefinition *parameterFromVariantMap( const QVariantMap &map ) /Factory/;
15191543
%Docstring
15201544
Creates a new :py:class:`QgsProcessingParameterDefinition` using the configuration from a
@@ -4445,6 +4469,46 @@ a new (non-existing) tables.
44454469
};
44464470

44474471

4472+
class QgsProcessingParameterPointCloudLayer : QgsProcessingParameterDefinition, QgsFileFilterGenerator
4473+
{
4474+
%Docstring(signature="appended")
4475+
A point cloud layer parameter for processing algorithms.
4476+
4477+
.. versionadded:: 3.22
4478+
%End
4479+
4480+
%TypeHeaderCode
4481+
#include "qgsprocessingparameters.h"
4482+
%End
4483+
public:
4484+
4485+
QgsProcessingParameterPointCloudLayer( const QString &name, const QString &description = QString(),
4486+
const QVariant &defaultValue = QVariant(), bool optional = false );
4487+
%Docstring
4488+
Constructor for QgsProcessingParameterPointCloudLayer.
4489+
%End
4490+
4491+
static QString typeName();
4492+
%Docstring
4493+
Returns the type name for the parameter class.
4494+
%End
4495+
virtual QgsProcessingParameterDefinition *clone() const /Factory/;
4496+
4497+
virtual QString type() const;
4498+
virtual bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = 0 ) const;
4499+
4500+
virtual QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const;
4501+
4502+
virtual QString createFileFilter() const;
4503+
4504+
4505+
static QgsProcessingParameterPointCloudLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) /Factory/;
4506+
%Docstring
4507+
Creates a new parameter using the definition from a script code.
4508+
%End
4509+
};
4510+
4511+
44484512

44494513

44504514

‎python/core/auto_generated/processing/qgsprocessingutils.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ Decodes a provider key and layer ``uri`` from an encoded string, for use with
145145
Vector,
146146
Raster,
147147
Mesh,
148+
PointCloud,
148149
};
149150

150151
static QgsMapLayer *mapLayerFromString( const QString &string, QgsProcessingContext &context, bool allowLoadingNewLayers = true, QgsProcessingUtils::LayerHint typeHint = QgsProcessingUtils::LayerHint::UnknownType );

‎src/core/processing/qgsprocessingalgorithm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "qgsvectorlayer.h"
2929
#include "qgsprocessingfeedback.h"
3030
#include "qgsmeshlayer.h"
31+
#include "qgspointcloudlayer.h"
3132
#include "qgsexpressioncontextutils.h"
3233

3334

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

799+
QgsPointCloudLayer *QgsProcessingAlgorithm::parameterAsPointCloudLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const
800+
{
801+
return QgsProcessingParameters::parameterAsPointCloudLayer( parameterDefinition( name ), parameters, context );
802+
}
803+
798804
QString QgsProcessingAlgorithm::invalidSourceError( const QVariantMap &parameters, const QString &name )
799805
{
800806
if ( !parameters.contains( name ) )

‎src/core/processing/qgsprocessingalgorithm.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QgsFeatureSink;
3535
class QgsProcessingModelAlgorithm;
3636
class QgsProcessingAlgorithmConfigurationWidget;
3737
class QgsMeshLayer;
38+
class QgsPointCloudLayer;
3839

3940
#ifdef SIP_RUN
4041
% ModuleHeaderCode
@@ -797,7 +798,6 @@ class CORE_EXPORT QgsProcessingAlgorithm
797798
*/
798799
QgsMeshLayer *parameterAsMeshLayer( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context ) const;
799800

800-
801801
/**
802802
* Evaluates the parameter with matching \a name to a output layer destination.
803803
*/
@@ -889,8 +889,6 @@ class CORE_EXPORT QgsProcessingAlgorithm
889889
*/
890890
QgsCoordinateReferenceSystem parameterAsGeometryCrs( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );
891891

892-
893-
894892
/**
895893
* Evaluates the parameter with matching \a name to a file/folder name.
896894
*/
@@ -979,6 +977,16 @@ class CORE_EXPORT QgsProcessingAlgorithm
979977
*/
980978
QDateTime parameterAsDateTime( const QVariantMap &parameters, const QString &name, QgsProcessingContext &context );
981979

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

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

‎src/core/processing/qgsprocessingparameters.cpp

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "qgsrasterfilewriter.h"
3131
#include "qgsvectorlayer.h"
3232
#include "qgsmeshlayer.h"
33+
#include "qgspointcloudlayer.h"
3334
#include "qgsapplication.h"
3435
#include "qgslayoutmanager.h"
3536
#include "qgsprintlayout.h"
@@ -2156,6 +2157,17 @@ QString QgsProcessingParameters::parameterAsDatabaseTableName( const QgsProcessi
21562157
return parameterAsString( definition, value, context );
21572158
}
21582159

2160+
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context )
2161+
{
2162+
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, parameters, context, QgsProcessingUtils::LayerHint::PointCloud ) );
2163+
}
2164+
2165+
QgsPointCloudLayer *QgsProcessingParameters::parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context )
2166+
{
2167+
return qobject_cast< QgsPointCloudLayer *>( parameterAsLayer( definition, value, context, QgsProcessingUtils::LayerHint::PointCloud ) );
2168+
}
2169+
2170+
21592171
QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantMap( const QVariantMap &map )
21602172
{
21612173
QString type = map.value( QStringLiteral( "parameter_type" ) ).toString();
@@ -2223,6 +2235,8 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromVariantM
22232235
def.reset( new QgsProcessingParameterColor( name ) );
22242236
else if ( type == QgsProcessingParameterCoordinateOperation::typeName() )
22252237
def.reset( new QgsProcessingParameterCoordinateOperation( name ) );
2238+
else if ( type == QgsProcessingParameterPointCloudLayer::typeName() )
2239+
def.reset( new QgsProcessingParameterPointCloudLayer( name ) );
22262240
else
22272241
{
22282242
QgsProcessingParameterType *paramType = QgsApplication::instance()->processingRegistry()->parameterType( type );
@@ -2333,6 +2347,8 @@ QgsProcessingParameterDefinition *QgsProcessingParameters::parameterFromScriptCo
23332347
return QgsProcessingParameterDatabaseSchema::fromScriptCode( name, description, isOptional, definition );
23342348
else if ( type == QLatin1String( "databasetable" ) )
23352349
return QgsProcessingParameterDatabaseTable::fromScriptCode( name, description, isOptional, definition );
2350+
else if ( type == QLatin1String( "pointcloud" ) )
2351+
return QgsProcessingParameterPointCloudLayer::fromScriptCode( name, description, isOptional, definition );
23362352

23372353
return nullptr;
23382354
}
@@ -5004,10 +5020,8 @@ QgsProcessingParameterVectorLayer *QgsProcessingParameterVectorLayer::fromScript
50045020
return new QgsProcessingParameterVectorLayer( name, description, QList< int>(), definition.isEmpty() ? QVariant() : definition, isOptional );
50055021
}
50065022

5007-
QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name,
5008-
const QString &description,
5009-
const QVariant &defaultValue,
5010-
bool optional )
5023+
QgsProcessingParameterMeshLayer::QgsProcessingParameterMeshLayer( const QString &name, const QString &description,
5024+
const QVariant &defaultValue, bool optional )
50115025
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
50125026
{
50135027

@@ -8157,3 +8171,78 @@ void QgsProcessingParameterDatabaseTable::setAllowNewTableNames( bool allowNewTa
81578171
{
81588172
mAllowNewTableNames = allowNewTableNames;
81598173
}
8174+
8175+
QgsProcessingParameterPointCloudLayer::QgsProcessingParameterPointCloudLayer( const QString &name, const QString &description,
8176+
const QVariant &defaultValue, bool optional )
8177+
: QgsProcessingParameterDefinition( name, description, defaultValue, optional )
8178+
{
8179+
}
8180+
8181+
QgsProcessingParameterDefinition *QgsProcessingParameterPointCloudLayer::clone() const
8182+
{
8183+
return new QgsProcessingParameterPointCloudLayer( *this );
8184+
}
8185+
8186+
bool QgsProcessingParameterPointCloudLayer::checkValueIsAcceptable( const QVariant &v, QgsProcessingContext *context ) const
8187+
{
8188+
if ( !v.isValid() )
8189+
return mFlags & FlagOptional;
8190+
8191+
QVariant var = v;
8192+
8193+
if ( var.canConvert<QgsProperty>() )
8194+
{
8195+
QgsProperty p = var.value< QgsProperty >();
8196+
if ( p.propertyType() == QgsProperty::StaticProperty )
8197+
{
8198+
var = p.staticValue();
8199+
}
8200+
else
8201+
{
8202+
return true;
8203+
}
8204+
}
8205+
8206+
if ( qobject_cast< QgsPointCloudLayer * >( qvariant_cast<QObject *>( var ) ) )
8207+
return true;
8208+
8209+
if ( var.type() != QVariant::String || var.toString().isEmpty() )
8210+
return mFlags & FlagOptional;
8211+
8212+
if ( !context )
8213+
{
8214+
// that's as far as we can get without a context
8215+
return true;
8216+
}
8217+
8218+
// try to load as layer
8219+
if ( QgsProcessingUtils::mapLayerFromString( var.toString(), *context, true, QgsProcessingUtils::LayerHint::PointCloud ) )
8220+
return true;
8221+
8222+
return false;
8223+
}
8224+
8225+
QString QgsProcessingParameterPointCloudLayer::valueAsPythonString( const QVariant &val, QgsProcessingContext &context ) const
8226+
{
8227+
if ( !val.isValid() )
8228+
return QStringLiteral( "None" );
8229+
8230+
if ( val.canConvert<QgsProperty>() )
8231+
return QStringLiteral( "QgsProperty.fromExpression('%1')" ).arg( val.value< QgsProperty >().asExpression() );
8232+
8233+
QVariantMap p;
8234+
p.insert( name(), val );
8235+
QgsPointCloudLayer *layer = QgsProcessingParameters::parameterAsPointCloudLayer( this, p, context );
8236+
return layer ? QgsProcessingUtils::stringToPythonLiteral( QgsProcessingUtils::normalizeLayerSource( layer->source() ) )
8237+
: QgsProcessingUtils::stringToPythonLiteral( val.toString() );
8238+
}
8239+
8240+
QString QgsProcessingParameterPointCloudLayer::createFileFilter() const
8241+
{
8242+
return QgsProviderRegistry::instance()->filePointCloudFilters() + QStringLiteral( ";;" ) + QObject::tr( "All files (*.*)" );
8243+
}
8244+
8245+
QgsProcessingParameterPointCloudLayer *QgsProcessingParameterPointCloudLayer::fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition )
8246+
{
8247+
return new QgsProcessingParameterPointCloudLayer( name, description, definition.isEmpty() ? QVariant() : definition, isOptional );
8248+
}

‎src/core/processing/qgsprocessingparameters.h

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class QgsProcessingFeedback;
4242
class QgsProcessingProvider;
4343
class QgsPrintLayout;
4444
class QgsLayoutItem;
45+
class QgsPointCloudLayer;
4546

4647
/**
4748
* \class QgsProcessingFeatureSourceDefinition
@@ -430,6 +431,8 @@ class CORE_EXPORT QgsProcessingParameterDefinition
430431
sipType = sipType_QgsProcessingParameterMeshDatasetGroups;
431432
else if ( sipCpp->type() == QgsProcessingParameterMeshDatasetTime::typeName() )
432433
sipType = sipType_QgsProcessingParameterMeshDatasetTime;
434+
else if ( sipCpp->type() == QgsProcessingParameterPointCloudLayer::typeName() )
435+
sipType = sipType_QgsProcessingParameterPointCloudLayer;
433436
else
434437
sipType = nullptr;
435438
SIP_END
@@ -1269,7 +1272,6 @@ class CORE_EXPORT QgsProcessingParameters
12691272
*/
12701273
static QgsMeshLayer *parameterAsMeshLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
12711274

1272-
12731275
/**
12741276
* Evaluates the parameter with matching \a definition to a coordinate reference system.
12751277
*/
@@ -1569,6 +1571,29 @@ class CORE_EXPORT QgsProcessingParameters
15691571
*/
15701572
static QString parameterAsDatabaseTableName( const QgsProcessingParameterDefinition *definition, const QVariant &value, const QgsProcessingContext &context );
15711573

1574+
/**
1575+
* Evaluates the parameter with matching \a definition to a point cloud layer.
1576+
*
1577+
* Layers will either be taken from \a context's active project, or loaded from external
1578+
* sources and stored temporarily in the \a context. In either case, callers do not
1579+
* need to handle deletion of the returned layer.
1580+
*
1581+
* \since QGIS 3.22
1582+
*/
1583+
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariantMap &parameters, QgsProcessingContext &context );
1584+
1585+
/**
1586+
* Evaluates the parameter with matching \a definition and \a value to a point cloud layer.
1587+
*
1588+
* Layers will either be taken from \a context's active project, or loaded from external
1589+
* sources and stored temporarily in the \a context. In either case, callers do not
1590+
* need to handle deletion of the returned layer.
1591+
*
1592+
* \since QGIS 3.22
1593+
*/
1594+
static QgsPointCloudLayer *parameterAsPointCloudLayer( const QgsProcessingParameterDefinition *definition, const QVariant &value, QgsProcessingContext &context );
1595+
1596+
15721597
/**
15731598
* Creates a new QgsProcessingParameterDefinition using the configuration from a
15741599
* supplied variant \a map.
@@ -4151,6 +4176,39 @@ class CORE_EXPORT QgsProcessingParameterDatabaseTable : public QgsProcessingPara
41514176
};
41524177

41534178

4179+
/**
4180+
* \class QgsProcessingParameterPointCloudLayer
4181+
* \ingroup core
4182+
* \brief A point cloud layer parameter for processing algorithms.
4183+
* \since QGIS 3.22
4184+
*/
4185+
class CORE_EXPORT QgsProcessingParameterPointCloudLayer : public QgsProcessingParameterDefinition, public QgsFileFilterGenerator
4186+
{
4187+
public:
4188+
4189+
/**
4190+
* Constructor for QgsProcessingParameterPointCloudLayer.
4191+
*/
4192+
QgsProcessingParameterPointCloudLayer( const QString &name, const QString &description = QString(),
4193+
const QVariant &defaultValue = QVariant(), bool optional = false );
4194+
4195+
/**
4196+
* Returns the type name for the parameter class.
4197+
*/
4198+
static QString typeName() { return QStringLiteral( "pointcloud" ); }
4199+
QgsProcessingParameterDefinition *clone() const override SIP_FACTORY;
4200+
QString type() const override { return typeName(); }
4201+
bool checkValueIsAcceptable( const QVariant &input, QgsProcessingContext *context = nullptr ) const override;
4202+
QString valueAsPythonString( const QVariant &value, QgsProcessingContext &context ) const override;
4203+
QString createFileFilter() const override;
4204+
4205+
/**
4206+
* Creates a new parameter using the definition from a script code.
4207+
*/
4208+
static QgsProcessingParameterPointCloudLayer *fromScriptCode( const QString &name, const QString &description, bool isOptional, const QString &definition ) SIP_FACTORY;
4209+
};
4210+
4211+
41544212
// clazy:excludeall=qstring-allocations
41554213

41564214
#endif // QGSPROCESSINGPARAMETERS_H

‎src/core/processing/qgsprocessingparametertypeimpl.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,4 +2102,59 @@ class CORE_EXPORT QgsProcessingParameterTypeDatabaseTable: public QgsProcessingP
21022102
}
21032103

21042104
};
2105+
2106+
2107+
/**
2108+
* \brief A point cloud layer parameter for processing algorithms.
2109+
*
2110+
* \ingroup core
2111+
* \note No Python bindings available. Get your copy from QgsApplication.processingRegistry().parameterType('mesh')
2112+
* \since QGIS 3.22
2113+
*/
2114+
class CORE_EXPORT QgsProcessingParameterTypePointCloudLayer : public QgsProcessingParameterType
2115+
{
2116+
QgsProcessingParameterDefinition *create( const QString &name ) const override SIP_FACTORY
2117+
{
2118+
return new QgsProcessingParameterPointCloudLayer( name );
2119+
}
2120+
2121+
QString description() const override
2122+
{
2123+
return QCoreApplication::translate( "Processing", "A point cloud layer parameter." );
2124+
}
2125+
2126+
QString name() const override
2127+
{
2128+
return QCoreApplication::translate( "Processing", "Point Cloud Layer" );
2129+
}
2130+
2131+
QString pythonImportString() const override
2132+
{
2133+
return QStringLiteral( "from qgis.core import QgsProcessingParameterPointCloudLayer" );
2134+
}
2135+
2136+
QString className() const override
2137+
{
2138+
return QStringLiteral( "QgsProcessingParameterPointCloudLayer" );
2139+
}
2140+
2141+
QString id() const override
2142+
{
2143+
return QStringLiteral( "pointcloud" );
2144+
}
2145+
2146+
QStringList acceptedPythonTypes() const override
2147+
{
2148+
return QStringList() << QObject::tr( "str: layer ID" )
2149+
<< QObject::tr( "str: layer name" )
2150+
<< QObject::tr( "str: layer source" )
2151+
<< QStringLiteral( "QgsPointCloudLayer" );
2152+
}
2153+
2154+
QStringList acceptedStringValues() const override
2155+
{
2156+
return QStringList() << QObject::tr( "Path to a point cloud layer" );
2157+
}
2158+
};
2159+
21052160
#endif // QGSPROCESSINGPARAMETERTYPEIMPL_H

‎src/core/processing/qgsprocessingregistry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ QgsProcessingRegistry::QgsProcessingRegistry( QObject *parent SIP_TRANSFERTHIS )
7373
addParameterType( new QgsProcessingParameterTypeDxfLayers() );
7474
addParameterType( new QgsProcessingParameterTypeMeshDatasetGroups() );
7575
addParameterType( new QgsProcessingParameterTypeMeshDatasetTime() );
76+
addParameterType( new QgsProcessingParameterTypePointCloudLayer() );
7677
}
7778

7879
QgsProcessingRegistry::~QgsProcessingRegistry()

‎src/core/processing/qgsprocessingutils.cpp

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "qgsreferencedgeometry.h"
3636
#include "qgsrasterfilewriter.h"
3737
#include "qgsvectortilelayer.h"
38+
#include "qgspointcloudlayer.h"
3839
#include <QRegularExpression>
3940
#include <QUuid>
4041

@@ -178,7 +179,7 @@ QgsMapLayer *QgsProcessingUtils::mapLayerFromStore( const QString &string, QgsMa
178179
case QgsMapLayerType::AnnotationLayer:
179180
return true;
180181
case QgsMapLayerType::PointCloudLayer:
181-
return true;
182+
return !canUseLayer( qobject_cast< QgsPointCloudLayer * >( layer ) );
182183
}
183184
return true;
184185
} ), layers.end() );
@@ -198,6 +199,9 @@ QgsMapLayer *QgsProcessingUtils::mapLayerFromStore( const QString &string, QgsMa
198199

199200
case LayerHint::Mesh:
200201
return l->type() == QgsMapLayerType::MeshLayer;
202+
203+
case LayerHint::PointCloud:
204+
return l->type() == QgsMapLayerType::PointCloudLayer;
201205
}
202206
return true;
203207
};
@@ -230,7 +234,7 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string,
230234

231235
QString name;
232236
// for disk based sources, we use the filename to determine a layer name
233-
if ( !useProvider || ( provider == QLatin1String( "ogr" ) || provider == QLatin1String( "gdal" ) || provider == QLatin1String( "mdal" ) ) )
237+
if ( !useProvider || ( provider == QLatin1String( "ogr" ) || provider == QLatin1String( "gdal" ) || provider == QLatin1String( "mdal" ) || provider == QLatin1String( "pdal" ) ) )
234238
{
235239
QStringList components = uri.split( '|' );
236240
if ( components.isEmpty() )
@@ -313,6 +317,25 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string,
313317
return meshLayer.release();
314318
}
315319
}
320+
if ( typeHint == LayerHint::UnknownType || typeHint == LayerHint::PointCloud )
321+
{
322+
QgsPointCloudLayer::LayerOptions pointCloudOptions;
323+
pointCloudOptions.skipCrsValidation = true;
324+
325+
std::unique_ptr< QgsPointCloudLayer > pointCloudLayer;
326+
if ( useProvider )
327+
{
328+
pointCloudLayer = std::make_unique< QgsPointCloudLayer >( uri, name, provider, pointCloudOptions );
329+
}
330+
else
331+
{
332+
pointCloudLayer = std::make_unique< QgsPointCloudLayer >( uri, name, QStringLiteral( "pointcloud" ), pointCloudOptions );
333+
}
334+
if ( pointCloudLayer->isValid() )
335+
{
336+
return pointCloudLayer.release();
337+
}
338+
}
316339
return nullptr;
317340
}
318341

@@ -507,6 +530,11 @@ bool QgsProcessingUtils::canUseLayer( const QgsRasterLayer *layer )
507530
return layer && layer->isValid();
508531
}
509532

533+
bool QgsProcessingUtils::canUseLayer( const QgsPointCloudLayer *layer )
534+
{
535+
return layer && layer->isValid();
536+
}
537+
510538
bool QgsProcessingUtils::canUseLayer( const QgsVectorLayer *layer, const QList<int> &sourceTypes )
511539
{
512540
return layer && layer->isValid() &&

‎src/core/processing/qgsprocessingutils.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QgsProcessingFeedback;
3838
class QgsProcessingFeatureSource;
3939
class QgsProcessingAlgorithm;
4040
class QgsVectorTileLayer;
41+
class QgsPointCloudLayer;
4142

4243
#include <QString>
4344
#include <QVariant>
@@ -159,6 +160,7 @@ class CORE_EXPORT QgsProcessingUtils
159160
Vector, //!< Vector layer type
160161
Raster, //!< Raster layer type
161162
Mesh, //!< Mesh layer type, since QGIS 3.6
163+
PointCloud, //!< Point cloud layer type, since QGIS 3.22
162164
};
163165

164166
/**
@@ -437,6 +439,7 @@ class CORE_EXPORT QgsProcessingUtils
437439
static bool canUseLayer( const QgsMeshLayer *layer );
438440
static bool canUseLayer( const QgsPluginLayer *layer );
439441
static bool canUseLayer( const QgsVectorTileLayer *layer );
442+
static bool canUseLayer( const QgsPointCloudLayer *layer );
440443
static bool canUseLayer( const QgsVectorLayer *layer,
441444
const QList< int > &sourceTypes = QList< int >() );
442445

0 commit comments

Comments
 (0)
Please sign in to comment.