Skip to content

Commit

Permalink
pass a text file with input data files to build vpc tool (fix #53970)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbruy authored and nyalldawson committed Oct 24, 2023
1 parent c9da9b7 commit 69895b4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
15 changes: 14 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
45 changes: 34 additions & 11 deletions tests/src/analysis/testqgsprocessingpdalalgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ class TestQgsProcessingPdalAlgs: public QgsTest
void tile();

private:
void updateFileListArg( QStringList &args, const QString &fileName );

QString mPointCloudLayerPath;
};

Expand Down Expand Up @@ -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" ) ) ) );
Expand Down Expand Up @@ -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" )
);
}

Expand Down

0 comments on commit 69895b4

Please sign in to comment.