From 69895b4ffdbb813d3ef0a4d251bf4ff72e002a21 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 23 Oct 2023 19:56:22 +0300 Subject: [PATCH] pass a text file with input data files to build vpc tool (fix #53970) --- .../pdal/qgsalgorithmpdalbuildvpc.cpp | 15 ++++++- .../analysis/testqgsprocessingpdalalgs.cpp | 45 ++++++++++++++----- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp b/src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp index fb651236dc9..6a19f72ecb2 100644 --- a/src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp +++ b/src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp @@ -117,11 +117,24 @@ QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &pa applyThreadsParameter( args, context ); + const QString fileName = QgsProcessingUtils::generateTempFilename( QStringLiteral( "inputFiles.txt" ), &context ); + QFile listFile( fileName ); + if ( !listFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) ) + { + throw QgsProcessingException( QObject::tr( "Could not create input file list %1" ).arg( fileName ) ); + } + + QTextStream out( &listFile ); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + out.setCodec( "UTF-8" ); +#endif for ( const QgsMapLayer *layer : std::as_const( layers ) ) { - args << layer->source(); + out << layer->source() << "\n"; } + args << QStringLiteral( "--input-file-list=%1" ).arg( fileName ); + return args; } diff --git a/tests/src/analysis/testqgsprocessingpdalalgs.cpp b/tests/src/analysis/testqgsprocessingpdalalgs.cpp index cdee468cd53..d5d36df7d5a 100644 --- a/tests/src/analysis/testqgsprocessingpdalalgs.cpp +++ b/tests/src/analysis/testqgsprocessingpdalalgs.cpp @@ -58,6 +58,8 @@ class TestQgsProcessingPdalAlgs: public QgsTest void tile(); private: + void updateFileListArg( QStringList &args, const QString &fileName ); + QString mPointCloudLayerPath; }; @@ -89,6 +91,26 @@ void TestQgsProcessingPdalAlgs::init() { } +void TestQgsProcessingPdalAlgs::updateFileListArg( QStringList &args, const QString &fileName ) +{ + int i = 0; + bool found = false; + for ( const QString &arg : args ) + { + if ( arg.contains( fileName, Qt::CaseInsensitive ) ) + { + found = true; + break; + } + i++; + } + + if ( found ) + { + args[ i ] = QStringLiteral( "--input-file-list=%1" ).arg( fileName ); + } +} + void TestQgsProcessingPdalAlgs::info() { QgsPdalAlgorithmBase *alg = const_cast( static_cast< const QgsPdalAlgorithmBase * >( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "pdal:info" ) ) ) ); @@ -998,64 +1020,65 @@ void TestQgsProcessingPdalAlgs::buildVpc() parameters.insert( QStringLiteral( "OUTPUT" ), outputFile ); QStringList args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) - << pointCloud1 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // multiple layers parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 << pointCloud2 ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) - << pointCloud1 - << pointCloud2 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // calculate exact boundaries parameters.insert( QStringLiteral( "BOUNDARY" ), true ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) << QStringLiteral( "--boundary" ) - << pointCloud1 - << pointCloud2 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // calculate statistics parameters.insert( QStringLiteral( "STATISTICS" ), true ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) << QStringLiteral( "--boundary" ) << QStringLiteral( "--stats" ) - << pointCloud1 - << pointCloud2 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // build overview parameters.insert( QStringLiteral( "OVERVIEW" ), true ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) << QStringLiteral( "--boundary" ) << QStringLiteral( "--stats" ) << QStringLiteral( "--overview" ) - << pointCloud1 - << pointCloud2 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // set max threads to 2, a --threads argument should be added context->setMaximumThreads( 2 ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" ) << QStringLiteral( "--output=%1" ).arg( outputFile ) << QStringLiteral( "--boundary" ) << QStringLiteral( "--stats" ) << QStringLiteral( "--overview" ) << QStringLiteral( "--threads=2" ) - << pointCloud1 - << pointCloud2 + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); }