Skip to content
Permalink
Browse files

Add attributes() member to QgsPointCloudDataProvider, QgsPointCloudLayer

Gives direct access to point cloud attributes
  • Loading branch information
nyalldawson committed Nov 12, 2020
1 parent 819fc50 commit b9a7a365c0610707f49bf9ed9721be81a273f4fe
@@ -37,6 +37,11 @@ Ctor

~QgsPointCloudDataProvider();

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

};

/************************************************************************
@@ -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 );
};
@@ -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() );
@@ -20,6 +20,7 @@

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

class QgsPointCloudIndex;
@@ -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.
*
@@ -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();
}
@@ -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;}
@@ -53,6 +53,11 @@ QgsRectangle QgsEptProvider::extent() const
return mIndex->extent();
}

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

bool QgsEptProvider::isValid() const
{
return mIsValid;
@@ -43,6 +43,7 @@ class QgsEptProvider: public QgsPointCloudDataProvider
QgsCoordinateReferenceSystem crs() const override;

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

bool isValid() const override;

@@ -55,6 +55,12 @@ QgsRectangle QgsPdalProvider::extent() const
return mExtent;
}

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

bool QgsPdalProvider::isValid() const
{
return mIsValid;
@@ -36,6 +36,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
QgsCoordinateReferenceSystem crs() const override;

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

bool isValid() const override;

@@ -54,6 +54,7 @@ class TestQgsEptProvider : public QObject
void brokenPath();
void validLayer();
void validLayerWithEptHierarchy();
void attributes();

private:
QString mTestDataDir;
@@ -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.
You can’t perform that action at this time.