Skip to content
Permalink
Browse files

Added tests

  • Loading branch information
NEDJIMAbelgacem authored and nyalldawson committed Jan 4, 2021
1 parent c6ad05d commit 9bd4673e35d6396137aed96625472b1019dc6926
@@ -321,6 +321,29 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
QgsGeometry extentGeometry,
const QgsDoubleRange extentZRange, int pointsLimit )
{
if ( extentGeometry.type() == QgsWkbTypes::GeometryType::PointGeometry )
{
QgsPointXY pt = extentGeometry.asPoint();
qDebug() << qSetRealNumberPrecision( 20 ) << __PRETTY_FUNCTION__ << " " << maxErrorInMapCoords << " " << pt.x() << " " << pt.y();
}
else if ( extentGeometry.type() == QgsWkbTypes::GeometryType::PolygonGeometry )
{
QPolygonF polygon = extentGeometry.asQPolygonF();
qDebug() << qSetRealNumberPrecision( 20 ) << __PRETTY_FUNCTION__ << " " << maxErrorInMapCoords;
qDebug() << "Polygon size: " << polygon.size();
qDebug() << "============================================";
qDebug() << " QPolygonF polygon;";
for ( QPointF p : polygon )
{
qDebug() << " polygon.push_back( QgsPointF( " << qSetRealNumberPrecision( 20 ) << p.x() << ", " << p.y() << " ) );";
}
qDebug() << "float maxErrorInMapCoords = " << qSetRealNumberPrecision( 20 ) << maxErrorInMapCoords;
qDebug() << "============================================";
}
else
{
qDebug() << __PRETTY_FUNCTION__ << "Unknown geometry";
}
QVector<QMap<QString, QVariant>> acceptedPoints;

QgsPointCloudIndex *index = this->index();
@@ -340,6 +363,21 @@ QVector<QMap<QString, QVariant>> QgsPointCloudDataProvider::identify(
qgis::overload<const QVector<QMap<QString, QVariant>>&>::of( &QVector<QMap<QString, QVariant>>::append ),
QtConcurrent::UnorderedReduce );

qDebug() << "------------------------------------------------------------------";
qDebug() << "QVector<QMap<QString, QVariant>> expected;";
for ( QMap<QString, QVariant> pt : acceptedPoints )
{
qDebug() << "{";
qDebug() << " " << "QMap<QString, QVariant> point;";
for ( QString key : pt.keys() )
{
qDebug() << qSetRealNumberPrecision( 20 ) << " point[ QStringLiteral(" << key << ") ] = " << pt[key].toString() << ";";
}
qDebug() << " expected.push_back(point);";
qDebug() << "}";
}
qDebug() << "------------------------------------------------------------------";

return acceptedPoints;
}

@@ -85,7 +85,7 @@ class CORE_EXPORT QgsPointCloudDataProvider: public QgsDataProvider
* \note this function does not handle elevation properties and you need to
* change elevation coordinates yourself after returning from the function
*/
QVector<QMap<QString, QVariant>> identify( float maxErrorInMapCoords, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange, int pointsLimit = 1000 ) SIP_SKIP;
QVector<QMap<QString, QVariant>> identify( float maxErrorInMapCoords, QgsGeometry extentGeometry, const QgsDoubleRange extentZRange = QgsDoubleRange(), int pointsLimit = 1000 ) SIP_SKIP;

/**
* Returns flags containing the supported capabilities for the data provider.
@@ -255,7 +255,7 @@ QVector<QMap<QString, QVariant>> QgsPointCloudRenderer::identify( QgsPointCloudL
}
}

selectedPoints = layer->dataProvider()->identify( maxErrorInMapCoordinates, selectionGeometry, QgsDoubleRange() );
selectedPoints = layer->dataProvider()->identify( maxErrorInMapCoordinates, selectionGeometry );

selectedPoints.erase( std::remove_if( selectedPoints.begin(), selectedPoints.end(), [this]( const QMap<QString, QVariant> &point ) { return !this->willRenderPoint( point ); } ), selectedPoints.end() );

@@ -57,6 +57,7 @@ class TestQgsEptProvider : public QObject
void validLayerWithEptHierarchy();
void attributes();
void calculateZRange();
void testIdentify();

private:
QString mTestDataDir;
@@ -255,6 +256,150 @@ void TestQgsEptProvider::calculateZRange()
QGSCOMPARENEAR( range.upper(), 160.54, 0.01 );
}

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

// identify 1 point click (rectangular point shape)
{
QgsPolygonXY polygon;
QVector<QgsPointXY> ring;
ring.push_back( QgsPointXY( 498062.50018404237926, 7050996.5845294082537 ) );
ring.push_back( QgsPointXY( 498062.5405028705718, 7050996.5845294082537 ) );
ring.push_back( QgsPointXY( 498062.5405028705718, 7050996.6248482363299 ) );
ring.push_back( QgsPointXY( 498062.50018404237926, 7050996.6248482363299 ) );
ring.push_back( QgsPointXY( 498062.50018404237926, 7050996.5845294082537 ) );
polygon.push_back( ring );
float maxErrorInMapCoords = 0.0022857920266687870026;
QVector<QMap<QString, QVariant>> points = layer->dataProvider()->identify( maxErrorInMapCoords, QgsGeometry::fromPolygonXY( polygon ) );
qDebug() << "Points count : " << points.size();
int i = 1;
for ( QMap<QString, QVariant> pt : points )
{
qDebug() << "Point " << i; ++i;
for ( QString attr : pt.keys() )
{
qDebug() << qSetRealNumberPrecision( 20 ) << attr << " -> " << pt[attr];
}
qDebug() << "--------------------------------";
}
QCOMPARE( points.size(), 1 );
QMap<QString, QVariant> identifiedPoint = points[0];
QMap<QString, QVariant> expected;

expected[ QStringLiteral( "Blue" ) ] = 0;
expected[ QStringLiteral( "Classification" ) ] = 2;
expected[ QStringLiteral( "EdgeOfFlightLine" ) ] = 0;
expected[ QStringLiteral( "GpsTime" ) ] = 268793.37257748609409;
expected[ QStringLiteral( "Green" ) ] = 0;
expected[ QStringLiteral( "Intensity" ) ] = 1765;
expected[ QStringLiteral( "NumberOfReturns" ) ] = 1;
expected[ QStringLiteral( "PointSourceId" ) ] = 7041;
expected[ QStringLiteral( "Red" ) ] = 0;
expected[ QStringLiteral( "ReturnNumber" ) ] = 1;
expected[ QStringLiteral( "ScanAngleRank" ) ] = -28;
expected[ QStringLiteral( "ScanDirectionFlag" ) ] = 1;
expected[ QStringLiteral( "UserData" ) ] = 17;
expected[ QStringLiteral( "X" ) ] = 498062.52000005543232;
expected[ QStringLiteral( "Y" ) ] = 7050996.6099999640137;
expected[ QStringLiteral( "Z" ) ] = 75.000000044703483582;
QVERIFY( identifiedPoint == expected );
}

// identify 1 point (circular point shape)
{
QPolygonF polygon;
polygon.push_back( QPointF( 498066.28873652569018, 7050994.9709538575262 ) );
polygon.push_back( QPointF( 498066.21890226693358, 7050995.0112726856023 ) );
polygon.push_back( QPointF( 498066.21890226693358, 7050995.0919103417546 ) );
polygon.push_back( QPointF( 498066.28873652569018, 7050995.1322291698307 ) );
polygon.push_back( QPointF( 498066.35857078444678, 7050995.0919103417546 ) );
polygon.push_back( QPointF( 498066.35857078444678, 7050995.0112726856023 ) );
polygon.push_back( QPointF( 498066.28873652569018, 7050994.9709538575262 ) );
float maxErrorInMapCoords = 0.0091431681066751480103;
QVector<QMap<QString, QVariant>> identifiedPoints = layer->dataProvider()->identify( maxErrorInMapCoords, QgsGeometry::fromQPolygonF( polygon ) );
QVector<QMap<QString, QVariant>> expected;
{
QMap<QString, QVariant> point;
point[ QStringLiteral( "Blue" ) ] = "0" ;
point[ QStringLiteral( "Classification" ) ] = "2" ;
point[ QStringLiteral( "EdgeOfFlightLine" ) ] = "0" ;
point[ QStringLiteral( "GpsTime" ) ] = "268793.3373408913" ;
point[ QStringLiteral( "Green" ) ] = "0" ;
point[ QStringLiteral( "Intensity" ) ] = "278" ;
point[ QStringLiteral( "NumberOfReturns" ) ] = "1" ;
point[ QStringLiteral( "PointSourceId" ) ] = "7041" ;
point[ QStringLiteral( "Red" ) ] = "0" ;
point[ QStringLiteral( "ReturnNumber" ) ] = "1" ;
point[ QStringLiteral( "ScanAngleRank" ) ] = "-28" ;
point[ QStringLiteral( "ScanDirectionFlag" ) ] = "1" ;
point[ QStringLiteral( "UserData" ) ] = "17" ;
point[ QStringLiteral( "X" ) ] = "498066.2699999716" ;
point[ QStringLiteral( "Y" ) ] = "7050995.059999999" ;
point[ QStringLiteral( "Z" ) ] = "74.60000005364418" ;
expected.push_back( point );
}

QVERIFY( identifiedPoints == expected );
}

// test rectangle selection
{
QPolygonF polygon;
polygon.push_back( QPointF( 498063.24382022250211, 7050996.8638040581718 ) );
polygon.push_back( QPointF( 498063.02206666755956, 7050996.8638040581718 ) );
polygon.push_back( QPointF( 498063.02206666755956, 7050996.6360026793554 ) );
polygon.push_back( QPointF( 498063.24382022250211, 7050996.6360026793554 ) );
polygon.push_back( QPointF( 498063.24382022250211, 7050996.8638040581718 ) );

float maxErrorInMapCoords = 0.0022857920266687870026;
QVector<QMap<QString, QVariant>> identifiedPoints = layer->dataProvider()->identify( maxErrorInMapCoords, QgsGeometry::fromQPolygonF( polygon ) );
QVector<QMap<QString, QVariant>> expected;
{
QMap<QString, QVariant> point;
point[ QStringLiteral( "Blue" ) ] = "0" ;
point[ QStringLiteral( "Classification" ) ] = "2" ;
point[ QStringLiteral( "EdgeOfFlightLine" ) ] = "0" ;
point[ QStringLiteral( "GpsTime" ) ] = "268793.3813974548" ;
point[ QStringLiteral( "Green" ) ] = "0" ;
point[ QStringLiteral( "Intensity" ) ] = "1142" ;
point[ QStringLiteral( "NumberOfReturns" ) ] = "1" ;
point[ QStringLiteral( "PointSourceId" ) ] = "7041" ;
point[ QStringLiteral( "Red" ) ] = "0" ;
point[ QStringLiteral( "ReturnNumber" ) ] = "1" ;
point[ QStringLiteral( "ScanAngleRank" ) ] = "-28" ;
point[ QStringLiteral( "ScanDirectionFlag" ) ] = "1" ;
point[ QStringLiteral( "UserData" ) ] = "17" ;
point[ QStringLiteral( "X" ) ] = "498063.1400000416" ;
point[ QStringLiteral( "Y" ) ] = "7050996.78999996" ;
point[ QStringLiteral( "Z" ) ] = "74.89000004716218" ;
expected.push_back( point );
}
{
QMap<QString, QVariant> point;
point[ QStringLiteral( "Blue" ) ] = "0" ;
point[ QStringLiteral( "Classification" ) ] = "3" ;
point[ QStringLiteral( "EdgeOfFlightLine" ) ] = "0" ;
point[ QStringLiteral( "GpsTime" ) ] = "269160.5176644815" ;
point[ QStringLiteral( "Green" ) ] = "0" ;
point[ QStringLiteral( "Intensity" ) ] = "1631" ;
point[ QStringLiteral( "NumberOfReturns" ) ] = "1" ;
point[ QStringLiteral( "PointSourceId" ) ] = "7042" ;
point[ QStringLiteral( "Red" ) ] = "0" ;
point[ QStringLiteral( "ReturnNumber" ) ] = "1" ;
point[ QStringLiteral( "ScanAngleRank" ) ] = "-12" ;
point[ QStringLiteral( "ScanDirectionFlag" ) ] = "1" ;
point[ QStringLiteral( "UserData" ) ] = "17" ;
point[ QStringLiteral( "X" ) ] = "498063.11000004224" ;
point[ QStringLiteral( "Y" ) ] = "7050996.749999961" ;
point[ QStringLiteral( "Z" ) ] = "74.90000004693866" ;
expected.push_back( point );
}

QVERIFY( identifiedPoints == expected );
}
}


QGSTEST_MAIN( TestQgsEptProvider )
#include "testqgseptprovider.moc"

0 comments on commit 9bd4673

Please sign in to comment.
You can’t perform that action at this time.