Skip to content

Commit 3dfa397

Browse files
committedApr 6, 2023
add method to list available pointcloud attribute names without the need
to index point cloud first
1 parent 80ab370 commit 3dfa397

File tree

11 files changed

+77
-0
lines changed

11 files changed

+77
-0
lines changed
 

‎python/core/auto_generated/pointcloud/qgspointclouddataprovider.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ Returns flags containing the supported capabilities for the data provider.
9696
%Docstring
9797
Returns the attributes available from this data provider.
9898
May return empty collection until :py:func:`~QgsPointCloudDataProvider.pointCloudIndexLoaded` is emitted
99+
%End
100+
101+
virtual QStringList attributeNames() const = 0;
102+
%Docstring
103+
Returns names of the attributes available from this data provider.
104+
105+
.. versionadded:: 3.32
99106
%End
100107

101108
virtual void loadIndex( ) = 0;

‎python/core/auto_generated/pointcloud/qgspointcloudlayer.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ QgsPointCloudLayer cannot be copied.
122122
QgsPointCloudAttributeCollection attributes() const;
123123
%Docstring
124124
Returns the attributes available from the layer.
125+
%End
126+
127+
QStringList attributeNames() const;
128+
%Docstring
129+
Returns the names of the attributes available from the layer.
130+
131+
.. versionadded:: 3.32
125132
%End
126133

127134
qint64 pointCount() const;

‎src/core/pointcloud/qgspointclouddataprovider.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,13 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
132132
*/
133133
virtual QgsPointCloudAttributeCollection attributes() const = 0;
134134

135+
/**
136+
* Returns names of the attributes available from this data provider.
137+
*
138+
* \since QGIS 3.32
139+
*/
140+
virtual QStringList attributeNames() const = 0;
141+
135142
/**
136143
* Triggers loading of the point cloud index
137144
*

‎src/core/pointcloud/qgspointcloudlayer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,13 @@ QgsPointCloudAttributeCollection QgsPointCloudLayer::attributes() const
726726
return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
727727
}
728728

729+
QStringList QgsPointCloudLayer::attributeNames() const
730+
{
731+
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
732+
733+
return mDataProvider ? mDataProvider->attributeNames() : QStringList();
734+
}
735+
729736
qint64 QgsPointCloudLayer::pointCount() const
730737
{
731738
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

‎src/core/pointcloud/qgspointcloudlayer.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,13 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer, public QgsAbstractPro
162162
*/
163163
QgsPointCloudAttributeCollection attributes() const;
164164

165+
/**
166+
* Returns the names of the attributes available from the layer.
167+
*
168+
* \since QGIS 3.32
169+
*/
170+
QStringList attributeNames() const;
171+
165172
/**
166173
* Returns the total number of points available in the layer.
167174
*/

‎src/core/providers/copc/qgscopcprovider.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ QgsPointCloudAttributeCollection QgsCopcProvider::attributes() const
7878
return mIndex->attributes();
7979
}
8080

81+
QStringList QgsCopcProvider::attributeNames() const
82+
{
83+
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
84+
85+
QStringList attributeNames;
86+
const QVector<QgsPointCloudAttribute> attrs = mIndex->attributes().attributes();
87+
for ( const QgsPointCloudAttribute &a : attrs )
88+
{
89+
attributeNames << a.name();
90+
}
91+
return attributeNames;
92+
}
93+
8194
bool QgsCopcProvider::isValid() const
8295
{
8396
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

‎src/core/providers/copc/qgscopcprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QgsCopcProvider: public QgsPointCloudDataProvider
4343

4444
QgsRectangle extent() const override;
4545
QgsPointCloudAttributeCollection attributes() const override;
46+
QStringList attributeNames() const override;
4647
bool isValid() const override;
4748
QString name() const override;
4849
QString description() const override;

‎src/core/providers/ept/qgseptprovider.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,19 @@ QgsPointCloudAttributeCollection QgsEptProvider::attributes() const
7474
return mIndex->attributes();
7575
}
7676

77+
QStringList QgsEptProvider::attributeNames() const
78+
{
79+
QGIS_PROTECT_QOBJECT_THREAD_ACCESS
80+
81+
QStringList attributeNames;
82+
QVector<QgsPointCloudAttribute> attrs = mIndex->attributes().attributes();
83+
for ( const QgsPointCloudAttribute &a : attrs )
84+
{
85+
attributeNames << a.name();
86+
}
87+
return attributeNames;
88+
}
89+
7790
bool QgsEptProvider::isValid() const
7891
{
7992
QGIS_PROTECT_QOBJECT_THREAD_ACCESS

‎src/core/providers/ept/qgseptprovider.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QgsEptProvider: public QgsPointCloudDataProvider
4343

4444
QgsRectangle extent() const override;
4545
QgsPointCloudAttributeCollection attributes() const override;
46+
QStringList attributeNames() const override;
4647
bool isValid() const override;
4748
QString name() const override;
4849
QString description() const override;

‎src/providers/pdal/qgspdalprovider.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ QgsPointCloudAttributeCollection QgsPdalProvider::attributes() const
8282
return mIndex ? mIndex->attributes() : QgsPointCloudAttributeCollection();
8383
}
8484

85+
QStringList QgsPdalProvider::attributeNames() const
86+
{
87+
return mAttributeNames;
88+
}
89+
8590
static QString _outEptDir( const QString &filename )
8691
{
8792
const QFileInfo fi( filename );
@@ -308,6 +313,13 @@ bool QgsPdalProvider::load( const QString &uri )
308313
// projection
309314
const QString wkt = QString::fromStdString( quickInfo.m_srs.getWKT() );
310315
mCrs = QgsCoordinateReferenceSystem::fromWkt( wkt );
316+
317+
// attribute names
318+
for ( auto &dim : quickInfo.m_dimNames )
319+
{
320+
mAttributeNames << QString::fromStdString( dim );
321+
}
322+
311323
return quickInfo.valid();
312324
}
313325
else

‎src/providers/pdal/qgspdalprovider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
3737
QgsCoordinateReferenceSystem crs() const override;
3838
QgsRectangle extent() const override;
3939
QgsPointCloudAttributeCollection attributes() const override;
40+
QStringList attributeNames() const override;
4041
qint64 pointCount() const override;
4142
QVariantMap originalMetadata() const override;
4243
bool isValid() const override;
@@ -60,6 +61,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
6061
qint64 mPointCount = 0;
6162

6263
QVariantMap mOriginalMetadata;
64+
QStringList mAttributeNames;
6365
std::unique_ptr<QgsPointCloudIndex> mIndex;
6466
QgsPdalIndexingTask *mRunningIndexingTask = nullptr;
6567
bool mGenerateCopc = true;

0 commit comments

Comments
 (0)
Please sign in to comment.