pass a text file with input data files to build vpc tool (fix #53970)

This commit is contained in:
Alexander Bruy 2023-10-23 19:56:22 +03:00 committed by Nyall Dawson
parent c9da9b7680
commit 69895b4ffd
2 changed files with 48 additions and 12 deletions

View File

@ -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;
}

View File

@ -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<QgsPdalAlgorithmBase *>( 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" )
);
}