Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add method to retrieve point count for layers
  • Loading branch information
nyalldawson committed Dec 2, 2020
1 parent 84d77e6 commit ecd4864
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 1 deletion.
Expand Up @@ -60,6 +60,11 @@ Returns the attributes available from this data provider.
%End


virtual int pointCount() const = 0;
%Docstring
Returns the total number of points available in the dataset.
%End

virtual QgsPointCloudRenderer *createRenderer( const QVariantMap &configuration = QVariantMap() ) const /Factory/;
%Docstring
Creates a new 2D point cloud renderer, using provider backend specific information.
Expand Down
5 changes: 5 additions & 0 deletions src/core/pointcloud/qgspointclouddataprovider.h
Expand Up @@ -81,6 +81,11 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
*/
virtual QgsPointCloudIndex *index() const SIP_SKIP {return nullptr;}

/**
* Returns the total number of points available in the dataset.
*/
virtual int pointCount() const = 0;

/**
* Creates a new 2D point cloud renderer, using provider backend specific information.
*
Expand Down
9 changes: 9 additions & 0 deletions src/core/pointcloud/qgspointcloudlayer.cpp
Expand Up @@ -410,6 +410,15 @@ QString QgsPointCloudLayer::htmlMetadata() const
// unit
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" ) + tr( "Unit" ) + QStringLiteral( "</td><td>" ) + QgsUnitTypes::toString( crs().mapUnits() ) + QStringLiteral( "</td></tr>\n" );

// feature count
QLocale locale = QLocale();
locale.setNumberOptions( locale.numberOptions() &= ~QLocale::NumberOption::OmitGroupSeparator );
const int pointCount = mDataProvider ? mDataProvider->pointCount() : -1;
myMetadata += QStringLiteral( "<tr><td class=\"highlight\">" )
+ tr( "Point count" ) + QStringLiteral( "</td><td>" )
+ ( pointCount < 0 ? tr( "unknown" ) : locale.toString( static_cast<qlonglong>( pointCount ) ) )
+ QStringLiteral( "</td></tr>\n" );

// End Provider section
myMetadata += QLatin1String( "</table>\n<br><br>" );

Expand Down
6 changes: 6 additions & 0 deletions src/core/providers/ept/qgseptpointcloudindex.cpp
Expand Up @@ -66,6 +66,7 @@ bool QgsEptPointCloudIndex::load( const QString &fileName )
return false;

mSpan = result.value( QLatin1String( "span" ) ).toInt();
mPointCount = result.value( QLatin1String( "points" ) ).toInt();

// WKT
QJsonObject srs = result.value( QLatin1String( "srs" ) ).toObject();
Expand Down Expand Up @@ -243,6 +244,11 @@ QgsCoordinateReferenceSystem QgsEptPointCloudIndex::crs() const
return QgsCoordinateReferenceSystem::fromWkt( mWkt );
}

int QgsEptPointCloudIndex::pointCount() const
{
return mPointCount;
}

QVariant QgsEptPointCloudIndex::metadataStatistic( const QString &attribute, QgsStatisticalSummary::Statistic statistic ) const
{
if ( !mMetadataStats.contains( attribute ) )
Expand Down
3 changes: 3 additions & 0 deletions src/core/providers/ept/qgseptpointcloudindex.h
Expand Up @@ -48,6 +48,7 @@ class QgsEptPointCloudIndex: public QgsPointCloudIndex
QgsPointCloudBlock *nodeData( const IndexedPointCloudNode &n, const QgsPointCloudRequest &request ) override;

QgsCoordinateReferenceSystem crs() const;
int pointCount() const;
QVariant metadataStatistic( const QString &attribute, QgsStatisticalSummary::Statistic statistic ) const;
QVariantList metadataClasses( const QString &attribute ) const;
QVariant metadataClassStatistic( const QString &attribute, const QVariant &value, QgsStatisticalSummary::Statistic statistic ) const;
Expand All @@ -59,6 +60,8 @@ class QgsEptPointCloudIndex: public QgsPointCloudIndex
QString mDirectory;
QString mWkt;

int mPointCount = 0;

struct AttributeStatistics
{
int count = -1;
Expand Down
5 changes: 5 additions & 0 deletions src/core/providers/ept/qgseptprovider.cpp
Expand Up @@ -78,6 +78,11 @@ QgsPointCloudIndex *QgsEptProvider::index() const
return mIndex.get();
}

int QgsEptProvider::pointCount() const
{
return mIndex->pointCount();
}

QVariantList QgsEptProvider::metadataClasses( const QString &attribute ) const
{
return mIndex->metadataClasses( attribute );
Expand Down
1 change: 1 addition & 0 deletions src/core/providers/ept/qgseptprovider.h
Expand Up @@ -52,6 +52,7 @@ class QgsEptProvider: public QgsPointCloudDataProvider
QString description() const override;

QgsPointCloudIndex *index() const override;
int pointCount() const override;
QVariant metadataStatistic( const QString &attribute, QgsStatisticalSummary::Statistic statistic ) const override;
QVariantList metadataClasses( const QString &attribute ) const override;
QVariant metadataClassStatistic( const QString &attribute, const QVariant &value, QgsStatisticalSummary::Statistic statistic ) const override;
Expand Down
7 changes: 6 additions & 1 deletion src/providers/pdal/qgspdalprovider.cpp
Expand Up @@ -61,6 +61,11 @@ QgsPointCloudAttributeCollection QgsPdalProvider::attributes() const
return QgsPointCloudAttributeCollection();
}

int QgsPdalProvider::pointCount() const
{
return mPointCount;
}

bool QgsPdalProvider::isValid() const
{
return mIsValid;
Expand Down Expand Up @@ -112,7 +117,7 @@ bool QgsPdalProvider::load( const QString &uri )
double ymax = las_header.maxY();
mExtent = QgsRectangle( xmin, ymin, xmax, ymax );

// unsigned int nFeatures = las_header.pointCount();
mPointCount = las_header.pointCount();

// projection
QString wkt = QString::fromStdString( las_reader.getSpatialReference().getWKT() );
Expand Down
2 changes: 2 additions & 0 deletions src/providers/pdal/qgspdalprovider.h
Expand Up @@ -37,6 +37,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider

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

bool isValid() const override;

Expand All @@ -51,6 +52,7 @@ class QgsPdalProvider: public QgsPointCloudDataProvider
QgsCoordinateReferenceSystem mCrs;
QgsRectangle mExtent;
bool mIsValid = false;
int mPointCount = 0;
};

class QgsPdalProviderMetadata : public QgsProviderMetadata
Expand Down
1 change: 1 addition & 0 deletions tests/src/providers/testqgseptprovider.cpp
Expand Up @@ -169,6 +169,7 @@ void TestQgsEptProvider::validLayer()
QGSCOMPARENEAR( layer->extent().yMinimum(), 7050992.0, 0.1 );
QGSCOMPARENEAR( layer->extent().xMaximum(), 498068.0, 0.1 );
QGSCOMPARENEAR( layer->extent().yMaximum(), 7050998.0, 0.1 );
QCOMPARE( layer->dataProvider()->pointCount(), 253 );

QVERIFY( layer->dataProvider()->index() );
// all hierarchy is stored in a single node
Expand Down
2 changes: 2 additions & 0 deletions tests/src/providers/testqgspdalprovider.cpp
Expand Up @@ -170,6 +170,8 @@ void TestQgsPdalProvider::validLayer()
QGSCOMPARENEAR( layer->extent().yMinimum(), 7050992.84, 0.1 );
QGSCOMPARENEAR( layer->extent().xMaximum(), 498067.39, 0.1 );
QGSCOMPARENEAR( layer->extent().yMaximum(), 7050997.04, 0.1 );

QCOMPARE( layer->dataProvider()->pointCount(), 253 );
}

QGSTEST_MAIN( TestQgsPdalProvider )
Expand Down

0 comments on commit ecd4864

Please sign in to comment.