Skip to content

Commit

Permalink
add method to list available pointcloud attribute names without the need
Browse files Browse the repository at this point in the history
to index point cloud first
  • Loading branch information
alexbruy committed Apr 6, 2023
1 parent 80ab370 commit 3dfa397
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 0 deletions.
Expand Up @@ -96,6 +96,13 @@ Returns flags containing the supported capabilities for the data provider.
%Docstring
Returns the attributes available from this data provider.
May return empty collection until :py:func:`~QgsPointCloudDataProvider.pointCloudIndexLoaded` is emitted
%End

virtual QStringList attributeNames() const = 0;
%Docstring
Returns names of the attributes available from this data provider.

.. versionadded:: 3.32
%End

virtual void loadIndex( ) = 0;
Expand Down
Expand Up @@ -122,6 +122,13 @@ QgsPointCloudLayer cannot be copied.
QgsPointCloudAttributeCollection attributes() const;
%Docstring
Returns the attributes available from the layer.
%End

QStringList attributeNames() const;
%Docstring
Returns the names of the attributes available from the layer.

.. versionadded:: 3.32
%End

qint64 pointCount() const;
Expand Down
7 changes: 7 additions & 0 deletions src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -132,6 +132,13 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
*/
virtual QgsPointCloudAttributeCollection attributes() const = 0;

/**
* Returns names of the attributes available from this data provider.
*
* \since QGIS 3.32
*/
virtual QStringList attributeNames() const = 0;

/**
* Triggers loading of the point cloud index
*
Expand Down
7 changes: 7 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -726,6 +726,13 @@ QgsPointCloudAttributeCollection QgsPointCloudLayer::attributes() const
return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
}

QStringList QgsPointCloudLayer::attributeNames() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

return mDataProvider ? mDataProvider->attributeNames() : QStringList();
}

qint64 QgsPointCloudLayer::pointCount() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Expand Down
7 changes: 7 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.h
Expand Up @@ -162,6 +162,13 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer, public QgsAbstractPro
*/
QgsPointCloudAttributeCollection attributes() const;

/**
* Returns the names of the attributes available from the layer.
*
* \since QGIS 3.32
*/
QStringList attributeNames() const;

/**
* Returns the total number of points available in the layer.
*/
Expand Down
13 changes: 13 additions & 0 deletions src/core/providers/copc/qgscopcprovider.cpp
Expand Up @@ -78,6 +78,19 @@ QgsPointCloudAttributeCollection QgsCopcProvider::attributes() const
return mIndex->attributes();
}

QStringList QgsCopcProvider::attributeNames() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

QStringList attributeNames;
const QVector<QgsPointCloudAttribute> attrs = mIndex->attributes().attributes();
for ( const QgsPointCloudAttribute &a : attrs )
{
attributeNames << a.name();
}
return attributeNames;
}

bool QgsCopcProvider::isValid() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/copc/qgscopcprovider.h
Expand Up @@ -43,6 +43,7 @@ class QgsCopcProvider: public QgsPointCloudDataProvider

QgsRectangle extent() const override;
QgsPointCloudAttributeCollection attributes() const override;
QStringList attributeNames() const override;
bool isValid() const override;
QString name() const override;
QString description() const override;
Expand Down
13 changes: 13 additions & 0 deletions src/core/providers/ept/qgseptprovider.cpp
Expand Up @@ -74,6 +74,19 @@ QgsPointCloudAttributeCollection QgsEptProvider::attributes() const
return mIndex->attributes();
}

QStringList QgsEptProvider::attributeNames() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

QStringList attributeNames;
QVector<QgsPointCloudAttribute> attrs = mIndex->attributes().attributes();
for ( const QgsPointCloudAttribute &a : attrs )
{
attributeNames << a.name();
}
return attributeNames;
}

bool QgsEptProvider::isValid() const
{
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/ept/qgseptprovider.h
Expand Up @@ -43,6 +43,7 @@ class QgsEptProvider: public QgsPointCloudDataProvider

QgsRectangle extent() const override;
QgsPointCloudAttributeCollection attributes() const override;
QStringList attributeNames() const override;
bool isValid() const override;
QString name() const override;
QString description() const override;
Expand Down
12 changes: 12 additions & 0 deletions src/providers/pdal/qgspdalprovider.cpp
Expand Up @@ -82,6 +82,11 @@ QgsPointCloudAttributeCollection QgsPdalProvider::attributes() const
return mIndex ? mIndex->attributes() : QgsPointCloudAttributeCollection();
}

QStringList QgsPdalProvider::attributeNames() const
{
return mAttributeNames;
}

static QString _outEptDir( const QString &filename )
{
const QFileInfo fi( filename );
Expand Down Expand Up @@ -308,6 +313,13 @@ bool QgsPdalProvider::load( const QString &uri )
// projection
const QString wkt = QString::fromStdString( quickInfo.m_srs.getWKT() );
mCrs = QgsCoordinateReferenceSystem::fromWkt( wkt );

// attribute names
for ( auto &dim : quickInfo.m_dimNames )
{
mAttributeNames << QString::fromStdString( dim );
}

return quickInfo.valid();
}
else
Expand Down
2 changes: 2 additions & 0 deletions src/providers/pdal/qgspdalprovider.h
Expand Up @@ -37,6 +37,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
QgsCoordinateReferenceSystem crs() const override;
QgsRectangle extent() const override;
QgsPointCloudAttributeCollection attributes() const override;
QStringList attributeNames() const override;
qint64 pointCount() const override;
QVariantMap originalMetadata() const override;
bool isValid() const override;
Expand All @@ -60,6 +61,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
qint64 mPointCount = 0;

QVariantMap mOriginalMetadata;
QStringList mAttributeNames;
std::unique_ptr<QgsPointCloudIndex> mIndex;
QgsPdalIndexingTask *mRunningIndexingTask = nullptr;
bool mGenerateCopc = true;
Expand Down

0 comments on commit 3dfa397

Please sign in to comment.