Skip to content

Commit

Permalink
Fix a TODO
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson authored and PeterPetrik committed Dec 3, 2020
1 parent f64f687 commit 97f73fb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/core/pointcloud/qgspointcloudlayerelevationproperties.cpp
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgspointcloudlayerelevationproperties.h"
#include "qgspointcloudlayer.h"

QgsPointCloudLayerElevationProperties::QgsPointCloudLayerElevationProperties( QObject *parent )
: QgsMapLayerElevationProperties( parent )
Expand Down Expand Up @@ -44,8 +45,21 @@ bool QgsPointCloudLayerElevationProperties::isVisibleInZRange( const QgsDoubleRa
return true;
}

QgsDoubleRange QgsPointCloudLayerElevationProperties::calculateZRange( QgsMapLayer * ) const
QgsDoubleRange QgsPointCloudLayerElevationProperties::calculateZRange( QgsMapLayer *layer ) const
{
// TODO - retrieve range from point cloud data provider
if ( QgsPointCloudLayer *pcLayer = qobject_cast< QgsPointCloudLayer * >( layer ) )
{
if ( pcLayer->dataProvider() )
{
// try to fetch z range from provider metadata
const QVariant zMin = pcLayer->dataProvider()->metadataStatistic( QStringLiteral( "Z" ), QgsStatisticalSummary::Min );
const QVariant zMax = pcLayer->dataProvider()->metadataStatistic( QStringLiteral( "Z" ), QgsStatisticalSummary::Max );
if ( zMin.isValid() && zMax.isValid() )
{
return QgsDoubleRange( zMin.toDouble(), zMax.toDouble() );
}
}
}

return QgsDoubleRange();
}
12 changes: 12 additions & 0 deletions tests/src/providers/testqgseptprovider.cpp
Expand Up @@ -30,6 +30,7 @@
#include "qgseptprovider.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudindex.h"
#include "qgspointcloudlayerelevationproperties.h"

/**
* \ingroup UnitTests
Expand All @@ -55,6 +56,7 @@ class TestQgsEptProvider : public QObject
void validLayer();
void validLayerWithEptHierarchy();
void attributes();
void calculateZRange();

private:
QString mTestDataDir;
Expand Down Expand Up @@ -236,6 +238,16 @@ void TestQgsEptProvider::attributes()
QCOMPARE( attributes.at( 15 ).type(), QgsPointCloudAttribute::UShort );
}

void TestQgsEptProvider::calculateZRange()
{
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() );

QgsDoubleRange range = layer->elevationProperties()->calculateZRange( layer.get() );
QGSCOMPARENEAR( range.lower(), 1, 74.34 );
QGSCOMPARENEAR( range.upper(), 2, 80.02 );
}


QGSTEST_MAIN( TestQgsEptProvider )
#include "testqgseptprovider.moc"

0 comments on commit 97f73fb

Please sign in to comment.