Skip to content

Commit

Permalink
Add attributes() member to QgsPointCloudDataProvider, QgsPointCloudLayer
Browse files Browse the repository at this point in the history
Gives direct access to point cloud attributes
  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent 819fc50 commit b9a7a36
Show file tree
Hide file tree
Showing 11 changed files with 83 additions and 2 deletions.
Expand Up @@ -37,6 +37,11 @@ Ctor

~QgsPointCloudDataProvider();

virtual QgsPointCloudAttributeCollection attributes() const = 0;
%Docstring
Returns the attributes available from this data provider.
%End

};

/************************************************************************
Expand Down
Expand Up @@ -94,6 +94,11 @@ QgsPointCloudLayer cannot be copied.
virtual QString htmlMetadata() const;


QgsPointCloudAttributeCollection attributes() const;
%Docstring
Returns the attributes available from the layer.
%End

private:
QgsPointCloudLayer( const QgsPointCloudLayer &rhs );
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/pointcloud/qgspointcloudattributemodel.cpp
Expand Up @@ -28,10 +28,10 @@ QgsPointCloudAttributeModel::QgsPointCloudAttributeModel( QObject *parent )

void QgsPointCloudAttributeModel::setLayer( QgsPointCloudLayer *layer )
{
if ( layer && layer->dataProvider() && layer->dataProvider()->index() )
if ( layer )
{
mLayer = layer;
setAttributes( layer->dataProvider()->index()->attributes() );
setAttributes( layer->attributes() );
}
else
setAttributes( QgsPointCloudAttributeCollection() );
Expand Down
6 changes: 6 additions & 0 deletions src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -20,6 +20,7 @@

#include "qgis_core.h"
#include "qgsdataprovider.h"
#include "qgspointcloudattribute.h"
#include <memory>

class QgsPointCloudIndex;
Expand All @@ -45,6 +46,11 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider

~QgsPointCloudDataProvider() override;

/**
* Returns the attributes available from this data provider.
*/
virtual QgsPointCloudAttributeCollection attributes() const = 0;

/**
* Returns the point cloud index associated with the provider.
*
Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -302,3 +302,8 @@ QString QgsPointCloudLayer::htmlMetadata() const
myMetadata += QLatin1String( "\n</body>\n</html>\n" );
return myMetadata;
}

QgsPointCloudAttributeCollection QgsPointCloudLayer::attributes() const
{
return mDataProvider ? mDataProvider->attributes() : QgsPointCloudAttributeCollection();
}
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.h
Expand Up @@ -121,6 +121,11 @@ class CORE_EXPORT QgsPointCloudLayer : public QgsMapLayer
void setDataSource( const QString &dataSource, const QString &baseName, const QString &provider, const QgsDataProvider::ProviderOptions &options, bool loadDefaultStyleFlag = false ) override;
QString htmlMetadata() const override;

/**
* Returns the attributes available from the layer.
*/
QgsPointCloudAttributeCollection attributes() const;

private:

bool isReadOnly() const override {return true;}
Expand Down
5 changes: 5 additions & 0 deletions src/core/providers/ept/qgseptprovider.cpp
Expand Up @@ -53,6 +53,11 @@ QgsRectangle QgsEptProvider::extent() const
return mIndex->extent();
}

QgsPointCloudAttributeCollection QgsEptProvider::attributes() const
{
return mIndex->attributes();
}

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

QgsRectangle extent() const override;
QgsPointCloudAttributeCollection attributes() const override;

bool isValid() const override;

Expand Down
6 changes: 6 additions & 0 deletions src/providers/pdal/qgspdalprovider.cpp
Expand Up @@ -55,6 +55,12 @@ QgsRectangle QgsPdalProvider::extent() const
return mExtent;
}

QgsPointCloudAttributeCollection QgsPdalProvider::attributes() const
{
// TODO
return QgsPointCloudAttributeCollection();
}

bool QgsPdalProvider::isValid() const
{
return mIsValid;
Expand Down
1 change: 1 addition & 0 deletions src/providers/pdal/qgspdalprovider.h
Expand Up @@ -36,6 +36,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
QgsCoordinateReferenceSystem crs() const override;

QgsRectangle extent() const override;
QgsPointCloudAttributeCollection attributes() const override;

bool isValid() const override;

Expand Down
42 changes: 42 additions & 0 deletions tests/src/providers/testqgseptprovider.cpp
Expand Up @@ -54,6 +54,7 @@ class TestQgsEptProvider : public QObject
void brokenPath();
void validLayer();
void validLayerWithEptHierarchy();
void attributes();

private:
QString mTestDataDir;
Expand Down Expand Up @@ -191,6 +192,47 @@ void TestQgsEptProvider::validLayerWithEptHierarchy()
QVERIFY( layer->dataProvider()->index()->hasNode( IndexedPointCloudNode::fromString( "2-3-3-1" ) ) );
}

void TestQgsEptProvider::attributes()
{
std::unique_ptr< QgsPointCloudLayer > layer = qgis::make_unique< QgsPointCloudLayer >( mTestDataDir + QStringLiteral( "point_clouds/ept/sunshine-coast/ept.json" ), QStringLiteral( "layer" ), QStringLiteral( "ept" ) );
QVERIFY( layer->isValid() );

const QgsPointCloudAttributeCollection attributes = layer->attributes();
QCOMPARE( attributes.count(), 16 );
QCOMPARE( attributes.at( 0 ).name(), QStringLiteral( "X" ) );
QCOMPARE( attributes.at( 0 ).type(), QgsPointCloudAttribute::Int32 );
QCOMPARE( attributes.at( 1 ).name(), QStringLiteral( "Y" ) );
QCOMPARE( attributes.at( 1 ).type(), QgsPointCloudAttribute::Int32 );
QCOMPARE( attributes.at( 2 ).name(), QStringLiteral( "Z" ) );
QCOMPARE( attributes.at( 2 ).type(), QgsPointCloudAttribute::Int32 );
QCOMPARE( attributes.at( 3 ).name(), QStringLiteral( "Intensity" ) );
QCOMPARE( attributes.at( 3 ).type(), QgsPointCloudAttribute::Short );
QCOMPARE( attributes.at( 4 ).name(), QStringLiteral( "ReturnNumber" ) );
QCOMPARE( attributes.at( 4 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 5 ).name(), QStringLiteral( "NumberOfReturns" ) );
QCOMPARE( attributes.at( 5 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 6 ).name(), QStringLiteral( "ScanDirectionFlag" ) );
QCOMPARE( attributes.at( 6 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 7 ).name(), QStringLiteral( "EdgeOfFlightLine" ) );
QCOMPARE( attributes.at( 7 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 8 ).name(), QStringLiteral( "Classification" ) );
QCOMPARE( attributes.at( 8 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 9 ).name(), QStringLiteral( "ScanAngleRank" ) );
QCOMPARE( attributes.at( 9 ).type(), QgsPointCloudAttribute::Float );
QCOMPARE( attributes.at( 10 ).name(), QStringLiteral( "UserData" ) );
QCOMPARE( attributes.at( 10 ).type(), QgsPointCloudAttribute::Char );
QCOMPARE( attributes.at( 11 ).name(), QStringLiteral( "PointSourceId" ) );
QCOMPARE( attributes.at( 11 ).type(), QgsPointCloudAttribute::Short );
QCOMPARE( attributes.at( 12 ).name(), QStringLiteral( "GpsTime" ) );
QCOMPARE( attributes.at( 12 ).type(), QgsPointCloudAttribute::Double );
QCOMPARE( attributes.at( 13 ).name(), QStringLiteral( "Red" ) );
QCOMPARE( attributes.at( 13 ).type(), QgsPointCloudAttribute::Short );
QCOMPARE( attributes.at( 14 ).name(), QStringLiteral( "Green" ) );
QCOMPARE( attributes.at( 14 ).type(), QgsPointCloudAttribute::Short );
QCOMPARE( attributes.at( 15 ).name(), QStringLiteral( "Blue" ) );
QCOMPARE( attributes.at( 15 ).type(), QgsPointCloudAttribute::Short );
}


QGSTEST_MAIN( TestQgsEptProvider )
#include "testqgseptprovider.moc"

0 comments on commit b9a7a36

Please sign in to comment.