Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
use ept files for tests and make point cloud tests conditional
  • Loading branch information
alexbruy committed Aug 6, 2021
1 parent aef9ef7 commit 7a7c347
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/core/processing/qgsprocessingutils.cpp
Expand Up @@ -240,7 +240,7 @@ QgsMapLayer *QgsProcessingUtils::loadMapLayerFromString( const QString &string,

QString name;
// for disk based sources, we use the filename to determine a layer name
if ( !useProvider || ( provider == QLatin1String( "ogr" ) || provider == QLatin1String( "gdal" ) || provider == QLatin1String( "mdal" ) || provider == QLatin1String( "pdal" ) ) )
if ( !useProvider || ( provider == QLatin1String( "ogr" ) || provider == QLatin1String( "gdal" ) || provider == QLatin1String( "mdal" ) || provider == QLatin1String( "pdal" ) || provider == QLatin1String( "ept" ) ) )
{
QStringList components = uri.split( '|' );
if ( components.isEmpty() )
Expand Down
38 changes: 28 additions & 10 deletions tests/src/analysis/testqgsprocessing.cpp
Expand Up @@ -662,7 +662,9 @@ class TestQgsProcessing: public QObject
void parameterMeshDatasetGroups();
void parameterMeshDatasetTime();
void parameterDxfLayers();
#ifdef WITH_EPT
void parameterPointCloudLayer();
#endif
void checkParamValues();
void combineLayerExtent();
void processingFeatureSource();
Expand Down Expand Up @@ -860,16 +862,20 @@ void TestQgsProcessing::compatibleLayers()
QgsMeshLayer *m2 = new QgsMeshLayer( fm.filePath(), "mA", "mdal" );
QVERIFY( m2->isValid() );

QFileInfo fpc( testDataDir + "/point_clouds/las/cloud.las" );
QgsPointCloudLayer *pc1 = new QgsPointCloudLayer( fpc.filePath(), "PCX", "pdal" );
QVERIFY( m1->isValid() );
QgsPointCloudLayer *pc2 = new QgsPointCloudLayer( fpc.filePath(), "pcA", "pdal" );
QVERIFY( m2->isValid() );
#ifdef WITH_EPT
QFileInfo fpc( testDataDir + "/point_clouds/ept/sunshine-coast/ept.json" );
QgsPointCloudLayer *pc1 = new QgsPointCloudLayer( fpc.filePath(), "PCX", "ept" );
QgsPointCloudLayer *pc2 = new QgsPointCloudLayer( fpc.filePath(), "pcA", "ept" );
#endif

DummyPluginLayer *pl1 = new DummyPluginLayer( "dummylayer", "PX" );
DummyPluginLayer *pl2 = new DummyPluginLayer( "dummylayer", "pA" );

#ifdef WITH_EPT
p.addMapLayers( QList<QgsMapLayer *>() << r1 << r2 << r3 << v1 << v2 << v3 << v4 << m1 << m2 << pl1 << pl2 << pc1 << pc2 );
#else
p.addMapLayers( QList<QgsMapLayer *>() << r1 << r2 << r3 << v1 << v2 << v3 << v4 << m1 << m2 << pl1 << pl2 );
#endif

// compatibleRasterLayers
QVERIFY( QgsProcessingUtils::compatibleRasterLayers( nullptr ).isEmpty() );
Expand Down Expand Up @@ -932,6 +938,7 @@ void TestQgsProcessing::compatibleLayers()
lIds << pl->name();
QCOMPARE( lIds, QStringList() << "PX" << "pA" );

#ifdef WITH_EPT
// compatiblePointCloudLayers
QVERIFY( QgsProcessingUtils::compatiblePointCloudLayers( nullptr ).isEmpty() );

Expand All @@ -946,6 +953,7 @@ void TestQgsProcessing::compatibleLayers()
for ( QgsPointCloudLayer *pcl : QgsProcessingUtils::compatiblePointCloudLayers( &p, false ) )
lIds << pcl->name();
QCOMPARE( lIds, QStringList() << "PCX" << "pcA" );
#endif

// point only
lIds.clear();
Expand Down Expand Up @@ -990,13 +998,21 @@ void TestQgsProcessing::compatibleLayers()
lIds.clear();
for ( QgsMapLayer *l : QgsProcessingUtils::compatibleLayers( &p ) )
lIds << l->name();
#ifdef WITH_EPT
QCOMPARE( lIds, QStringList() << "ar2" << "mA" << "MX" << "pA" << "pcA" << "PCX" << "PX" << "R1" << "v1" << "v3" << "V4" << "vvvv4" << "zz" );
#else
QCOMPARE( lIds, QStringList() << "ar2" << "mA" << "MX" << "pA" << "PX" << "R1" << "v1" << "v3" << "V4" << "vvvv4" << "zz" );
#endif

// unsorted
lIds.clear();
for ( QgsMapLayer *l : QgsProcessingUtils::compatibleLayers( &p, false ) )
lIds << l->name();
#ifdef WITH_EPT
QCOMPARE( lIds, QStringList() << "R1" << "ar2" << "zz" << "V4" << "v1" << "v3" << "vvvv4" << "MX" << "mA" << "PCX" << "pcA" << "PX" << "pA" );
#else
QCOMPARE( lIds, QStringList() << "R1" << "ar2" << "zz" << "V4" << "v1" << "v3" << "vvvv4" << "MX" << "mA" << "PX" << "pA" );
#endif
}

void TestQgsProcessing::encodeDecodeUriProvider()
Expand Down Expand Up @@ -9026,6 +9042,7 @@ void TestQgsProcessing::parameterDxfLayers()
QCOMPARE( dxfList.at( 0 ).layerOutputAttributeIndex(), dxfLayer.layerOutputAttributeIndex() );
}

#ifdef WITH_EPT
void TestQgsProcessing::parameterPointCloudLayer()
{
// setup a context
Expand All @@ -9034,13 +9051,13 @@ void TestQgsProcessing::parameterPointCloudLayer()
QString testDataDir = QStringLiteral( TEST_DATA_DIR ) + '/'; //defined in CmakeLists.txt
QString vector1 = testDataDir + "multipoint.shp";
QString raster = testDataDir + "landsat.tif";
QString pointCloud = testDataDir + "point_clouds/las/cloud.las";
QString pointCloud = testDataDir + "point_clouds/ept/sunshine-coast/ept.json";
QFileInfo fi1( raster );
QFileInfo fi2( vector1 );
QFileInfo fi3( pointCloud );
QgsRasterLayer *r1 = new QgsRasterLayer( fi1.filePath(), "R1" );
QgsVectorLayer *v1 = new QgsVectorLayer( fi2.filePath(), "V4", "ogr" );
QgsPointCloudLayer *pc1 = new QgsPointCloudLayer( fi3.filePath(), "PC1", "pdal" );
QgsPointCloudLayer *pc1 = new QgsPointCloudLayer( fi3.filePath(), "PC1", "ept" );
Q_ASSERT( pc1 );
p.addMapLayers( QList<QgsMapLayer *>() << v1 << r1 << pc1 );
QgsProcessingContext context;
Expand Down Expand Up @@ -9097,9 +9114,9 @@ void TestQgsProcessing::parameterPointCloudLayer()
QVERIFY( !QgsProcessingParameters::parameterAsPointCloudLayer( def.get(), params, context ) );

QCOMPARE( def->valueAsPythonString( QVariant(), context ), QStringLiteral( "None" ) );
QCOMPARE( def->valueAsPythonString( pointCloud, context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/las/cloud.las'" ) ) );
QCOMPARE( def->valueAsPythonString( pc1->id(), context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/las/cloud.las'" ) ) );
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( pc1 ), context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/las/cloud.las'" ) ) );
QCOMPARE( def->valueAsPythonString( pointCloud, context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/ept/sunshine-coast/ept.json'" ) ) );
QCOMPARE( def->valueAsPythonString( pc1->id(), context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/ept/sunshine-coast/ept.json'" ) ) );
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( pc1 ), context ), QString( QString( "'" ) + testDataDir + QStringLiteral( "point_clouds/ept/sunshine-coast/ept.json'" ) ) );
QCOMPARE( def->valueAsPythonString( QVariant::fromValue( QgsProperty::fromExpression( "\"a\"=1" ) ), context ), QStringLiteral( "QgsProperty.fromExpression('\"a\"=1')" ) );
QCOMPARE( def->valueAsPythonString( QStringLiteral( "c:\\test\\new data\\test.las" ), context ), QStringLiteral( "'c:\\\\test\\\\new data\\\\test.las'" ) );

Expand Down Expand Up @@ -9154,6 +9171,7 @@ void TestQgsProcessing::parameterPointCloudLayer()
def.reset( new QgsProcessingParameterPointCloudLayer( "optional", QString(), QVariant::fromValue( pc1 ), true ) );
QCOMPARE( QgsProcessingParameters::parameterAsPointCloudLayer( def.get(), params, context )->id(), pc1->id() );
}
#endif

void TestQgsProcessing::checkParamValues()
{
Expand Down
21 changes: 18 additions & 3 deletions tests/src/gui/testprocessinggui.cpp
Expand Up @@ -3511,8 +3511,11 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
QgsProject::instance()->addMapLayer( raster );
DummyPluginLayer *plugin = new DummyPluginLayer( "dummylayer", "plugin" );
QgsProject::instance()->addMapLayer( plugin );
QgsPointCloudLayer *pointCloud = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/las/cloud.las", QStringLiteral( "pointcloud" ), QStringLiteral( "pdal" ) );

#ifdef WITH_EPT
QgsPointCloudLayer *pointCloud = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/ept/sunshine-coast/ept.json", QStringLiteral( "pointcloud" ), QStringLiteral( "ept" ) );
QgsProject::instance()->addMapLayer( pointCloud );
#endif

dlg->setProject( QgsProject::instance() );
// should be filtered to raster layers only
Expand Down Expand Up @@ -3574,13 +3577,15 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ) ).toString(), QStringLiteral( "plugin" ) );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ), Qt::UserRole ).toString(), plugin->id() );

#ifdef WITH_EPT
// point cloud
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypePointCloud );
dlg = std::make_unique< QgsProcessingMultipleInputPanelWidget >( param.get(), QVariantList(), QList<QgsProcessingModelChildParameterSource >() );
dlg->setProject( QgsProject::instance() );
QCOMPARE( dlg->mModel->rowCount(), 1 );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ) ).toString(), QStringLiteral( "pointcloud [EPSG:28356]" ) );
QCOMPARE( dlg->mModel->data( dlg->mModel->index( 0, 0 ), Qt::UserRole ).toString(), pointCloud->id() );
#endif

// vector points
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeVectorPoint );
Expand Down Expand Up @@ -3620,13 +3625,23 @@ void TestProcessingGui::testMultipleFileSelectionDialog()
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeMapLayer );
dlg = std::make_unique< QgsProcessingMultipleInputPanelWidget >( param.get(), QVariantList(), QList<QgsProcessingModelChildParameterSource >() );
dlg->setProject( QgsProject::instance() );
#ifdef WITH_EPT
QCOMPARE( dlg->mModel->rowCount(), 8 );
#else
QCOMPARE( dlg->mModel->rowCount(), 7 );
#endif

titles.clear();
for ( int i = 0; i < dlg->mModel->rowCount(); ++i )
titles << dlg->mModel->data( dlg->mModel->index( i, 0 ) ).toString();
#ifdef WITH_EPT
QCOMPARE( titles, QSet<QString>() << QStringLiteral( "polygon [EPSG:4326]" ) << QStringLiteral( "point [EPSG:4326]" ) << QStringLiteral( "line [EPSG:4326]" )
<< QStringLiteral( "nogeom" ) << QStringLiteral( "raster [EPSG:4326]" ) << QStringLiteral( "mesh" ) << QStringLiteral( "plugin" )
<< QStringLiteral( "pointcloud [EPSG:28356]" ) );
#else
QCOMPARE( titles, QSet<QString>() << QStringLiteral( "polygon [EPSG:4326]" ) << QStringLiteral( "point [EPSG:4326]" ) << QStringLiteral( "line [EPSG:4326]" )
<< QStringLiteral( "nogeom" ) << QStringLiteral( "raster [EPSG:4326]" ) << QStringLiteral( "mesh" ) << QStringLiteral( "plugin" ) );
#endif

// files
param = std::make_unique< QgsProcessingParameterMultipleLayers >( QString(), QString(), QgsProcessing::TypeFile );
Expand Down Expand Up @@ -9904,10 +9919,10 @@ void TestProcessingGui::testPointCloudLayerWrapper()
{
// setup a project with a range of layer types
QgsProject::instance()->removeAllMapLayers();
QgsPointCloudLayer *cloud1 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/las/cloud.las", QStringLiteral( "cloud1" ), QStringLiteral( "pdal" ) );
QgsPointCloudLayer *cloud1 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/ept/sunshine-coast/ept.json", QStringLiteral( "cloud1" ), QStringLiteral( "ept" ) );
QVERIFY( cloud1->isValid() );
QgsProject::instance()->addMapLayer( cloud1 );
QgsPointCloudLayer *cloud2 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/las/cloud.las", QStringLiteral( "cloud2" ), QStringLiteral( "pdal" ) );
QgsPointCloudLayer *cloud2 = new QgsPointCloudLayer( QStringLiteral( TEST_DATA_DIR ) + "/point_clouds/ept/sunshine-coast/ept.json", QStringLiteral( "cloud2" ), QStringLiteral( "ept" ) );
QVERIFY( cloud2->isValid() );
QgsProject::instance()->addMapLayer( cloud2 );

Expand Down

0 comments on commit 7a7c347

Please sign in to comment.