From 0fce157836243ae58ecfb4f627db8cc206f97f39 Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Mon, 23 Oct 2023 20:08:36 +0300 Subject: [PATCH] pass a text file with input data files to tile tool (refs #53970) --- .../processing/pdal/qgsalgorithmpdaltile.cpp | 15 ++++++- .../analysis/testqgsprocessingpdalalgs.cpp | 45 ++++++------------- 2 files changed, 28 insertions(+), 32 deletions(-) diff --git a/src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp b/src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp index 08f6ba2c028a..a4e227bdacb4 100644 --- a/src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp +++ b/src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp @@ -106,11 +106,24 @@ QStringList QgsPdalTileAlgorithm::createArgumentLists( const QVariantMap ¶me 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 f242468eac0d..f390e860f397 100644 --- a/tests/src/analysis/testqgsprocessingpdalalgs.cpp +++ b/tests/src/analysis/testqgsprocessingpdalalgs.cpp @@ -687,54 +687,59 @@ void TestQgsProcessingPdalAlgs::tile() parameters.insert( QStringLiteral( "OUTPUT" ), outputDir ); QStringList args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "tile" ) << QStringLiteral( "--length=1000" ) << QStringLiteral( "--output=%1" ).arg( outputDir ) << QStringLiteral( "--temp_dir=%1" ).arg( tempFolder ) - << mPointCloudLayerPath + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // override temp folder context->setTemporaryFolder( tempDir ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "tile" ) << QStringLiteral( "--length=1000" ) << QStringLiteral( "--output=%1" ).arg( outputDir ) << QStringLiteral( "--temp_dir=%1" ).arg( tempDir ) - << mPointCloudLayerPath + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // set tile length parameters.insert( QStringLiteral( "LENGTH" ), 150 ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "tile" ) << QStringLiteral( "--length=150" ) << QStringLiteral( "--output=%1" ).arg( outputDir ) << QStringLiteral( "--temp_dir=%1" ).arg( tempDir ) - << mPointCloudLayerPath + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); // assign crs parameters.insert( QStringLiteral( "CRS" ), QStringLiteral( "EPSG:4326" ) ); args = alg->createArgumentLists( parameters, *context, &feedback ); + updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) ); QCOMPARE( args, QStringList() << QStringLiteral( "tile" ) << QStringLiteral( "--length=150" ) << QStringLiteral( "--output=%1" ).arg( outputDir ) << QStringLiteral( "--temp_dir=%1" ).arg( tempDir ) << QStringLiteral( "--a_srs=EPSG:4326" ) - << mPointCloudLayerPath + << 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( "tile" ) << QStringLiteral( "--length=150" ) << QStringLiteral( "--output=%1" ).arg( outputDir ) << QStringLiteral( "--temp_dir=%1" ).arg( tempDir ) << QStringLiteral( "--a_srs=EPSG:4326" ) << QStringLiteral( "--threads=2" ) - << mPointCloudLayerPath + << QStringLiteral( "--input-file-list=inputFiles.txt" ) ); } @@ -942,13 +947,11 @@ void TestQgsProcessingPdalAlgs::merge() QgsProcessingFeedback feedback; - const QString pointCloud1 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/lone-star.copc.laz"; - const QString pointCloud2 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb16.copc.laz"; const QString outputFile = QDir::tempPath() + "/merged.las"; - // single layer + // default parameters QVariantMap parameters; - parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 ); + parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << mPointCloudLayerPath ); parameters.insert( QStringLiteral( "OUTPUT" ), outputFile ); QStringList args = alg->createArgumentLists( parameters, *context, &feedback ); @@ -958,15 +961,6 @@ void TestQgsProcessingPdalAlgs::merge() << 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( "merge" ) - << QStringLiteral( "--output=%1" ).arg( outputFile ) - << QStringLiteral( "--input-file-list=inputFiles.txt" ) - ); - // filter expression parameters.insert( QStringLiteral( "FILTER_EXPRESSION" ), QStringLiteral( "Intensity > 50" ) ); args = alg->createArgumentLists( parameters, *context, &feedback ); @@ -1011,13 +1005,11 @@ void TestQgsProcessingPdalAlgs::buildVpc() QgsProcessingFeedback feedback; - const QString pointCloud1 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/lone-star.copc.laz"; - const QString pointCloud2 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb16.copc.laz"; const QString outputFile = QDir::tempPath() + "/test.vpc"; - // single layer + // default parameters QVariantMap parameters; - parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 ); + parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << mPointCloudLayerPath ); parameters.insert( QStringLiteral( "OUTPUT" ), outputFile ); QStringList args = alg->createArgumentLists( parameters, *context, &feedback ); @@ -1027,15 +1019,6 @@ void TestQgsProcessingPdalAlgs::buildVpc() << 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 ) - << QStringLiteral( "--input-file-list=inputFiles.txt" ) - ); - // calculate exact boundaries parameters.insert( QStringLiteral( "BOUNDARY" ), true ); args = alg->createArgumentLists( parameters, *context, &feedback );