Skip to content

Commit

Permalink
Add test for Identify tool on VPC
Browse files Browse the repository at this point in the history
  • Loading branch information
dvdkon authored and wonder-sk committed Oct 25, 2024
1 parent 71b2591 commit 6a273f0
Show file tree
Hide file tree
Showing 6 changed files with 882 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/src/app/testqgsidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class TestQgsIdentify : public QObject
void testLineStringZ();
void testPolygonZ();
void identifyPointCloud();
void identifyVirtualPointCloud();

private:
void doAction();
Expand Down Expand Up @@ -1303,6 +1304,34 @@ void TestQgsIdentify::identifyPointCloud()
#endif
}

void TestQgsIdentify::identifyVirtualPointCloud()
{
#ifdef HAVE_COPC
std::unique_ptr< QgsPointCloudLayer > pointCloud = std::make_unique< QgsPointCloudLayer >( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/virtual/sunshine-coast/combined.vpc", QStringLiteral( "pointcloud" ), QStringLiteral( "vpc" ) );
QVERIFY( pointCloud->isValid() );
pointCloud->setCrs( QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:28356" ) ) );
QCOMPARE( pointCloud->crs3D().horizontalCrs().authid(), QStringLiteral( "EPSG:28356" ) );

for ( int i = 0; i < pointCloud->dataProvider()->subIndexes().size(); i++ )
pointCloud->dataProvider()->loadSubIndex( i );

// set project CRS and ellipsoid
// Note that using a different CRS here (a world-wide WGS84-based one) caused
// problems on some machines due to insufficient precision in reprojection.
QgsProject::instance()->setCrs( pointCloud->crs() );
canvas->setDestinationCrs( pointCloud->crs() );
canvas->setExtent( QgsRectangle::fromCenterAndSize( QgsPointXY( 498065.5, 7050992.5 ), 1, 1 ) );

const QgsPointXY mapPoint = canvas->getCoordinateTransform()->transform( 498065.23, 7050992.90 );

std::unique_ptr< QgsMapToolIdentifyAction > action( new QgsMapToolIdentifyAction( canvas ) );
QList<QgsMapToolIdentify::IdentifyResult> result = action->identify( static_cast< int >( mapPoint.x() ), static_cast< int >( mapPoint.y() ), QList<QgsMapLayer *>() << pointCloud.get() );
QCOMPARE( result.length(), 1 );
double z = result.at( 0 ).mDerivedAttributes[ QStringLiteral( "Z" )].toDouble();
QGSCOMPARENEAR( z, 74.91, 0.001 );
#endif
}

QGSTEST_MAIN( TestQgsIdentify )
#include "testqgsidentify.moc"

Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 6a273f0

Please sign in to comment.