Skip to content

Commit 0fce157

Browse files
alexbruynyalldawson
authored andcommitted
pass a text file with input data files to tile tool (refs #53970)
1 parent 3ed8b17 commit 0fce157

File tree

2 files changed

+28
-32
lines changed

2 files changed

+28
-32
lines changed

src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,24 @@ QStringList QgsPdalTileAlgorithm::createArgumentLists( const QVariantMap &parame
106106

107107
applyThreadsParameter( args, context );
108108

109+
const QString fileName = QgsProcessingUtils::generateTempFilename( QStringLiteral( "inputFiles.txt" ), &context );
110+
QFile listFile( fileName );
111+
if ( !listFile.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
112+
{
113+
throw QgsProcessingException( QObject::tr( "Could not create input file list %1" ).arg( fileName ) );
114+
}
115+
116+
QTextStream out( &listFile );
117+
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
118+
out.setCodec( "UTF-8" );
119+
#endif
109120
for ( const QgsMapLayer *layer : std::as_const( layers ) )
110121
{
111-
args << layer->source();
122+
out << layer->source() << "\n";
112123
}
113124

125+
args << QStringLiteral( "--input-file-list=%1" ).arg( fileName );
126+
114127
return args;
115128
}
116129

tests/src/analysis/testqgsprocessingpdalalgs.cpp

+14-31
Original file line numberDiff line numberDiff line change
@@ -687,54 +687,59 @@ void TestQgsProcessingPdalAlgs::tile()
687687
parameters.insert( QStringLiteral( "OUTPUT" ), outputDir );
688688

689689
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
690+
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
690691
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
691692
<< QStringLiteral( "--length=1000" )
692693
<< QStringLiteral( "--output=%1" ).arg( outputDir )
693694
<< QStringLiteral( "--temp_dir=%1" ).arg( tempFolder )
694-
<< mPointCloudLayerPath
695+
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
695696
);
696697

697698
// override temp folder
698699
context->setTemporaryFolder( tempDir );
699700
args = alg->createArgumentLists( parameters, *context, &feedback );
701+
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
700702
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
701703
<< QStringLiteral( "--length=1000" )
702704
<< QStringLiteral( "--output=%1" ).arg( outputDir )
703705
<< QStringLiteral( "--temp_dir=%1" ).arg( tempDir )
704-
<< mPointCloudLayerPath
706+
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
705707
);
706708

707709
// set tile length
708710
parameters.insert( QStringLiteral( "LENGTH" ), 150 );
709711
args = alg->createArgumentLists( parameters, *context, &feedback );
712+
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
710713
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
711714
<< QStringLiteral( "--length=150" )
712715
<< QStringLiteral( "--output=%1" ).arg( outputDir )
713716
<< QStringLiteral( "--temp_dir=%1" ).arg( tempDir )
714-
<< mPointCloudLayerPath
717+
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
715718
);
716719

717720
// assign crs
718721
parameters.insert( QStringLiteral( "CRS" ), QStringLiteral( "EPSG:4326" ) );
719722
args = alg->createArgumentLists( parameters, *context, &feedback );
723+
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
720724
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
721725
<< QStringLiteral( "--length=150" )
722726
<< QStringLiteral( "--output=%1" ).arg( outputDir )
723727
<< QStringLiteral( "--temp_dir=%1" ).arg( tempDir )
724728
<< QStringLiteral( "--a_srs=EPSG:4326" )
725-
<< mPointCloudLayerPath
729+
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
726730
);
727731

728732
// set max threads to 2, a --threads argument should be added
729733
context->setMaximumThreads( 2 );
730734
args = alg->createArgumentLists( parameters, *context, &feedback );
735+
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
731736
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
732737
<< QStringLiteral( "--length=150" )
733738
<< QStringLiteral( "--output=%1" ).arg( outputDir )
734739
<< QStringLiteral( "--temp_dir=%1" ).arg( tempDir )
735740
<< QStringLiteral( "--a_srs=EPSG:4326" )
736741
<< QStringLiteral( "--threads=2" )
737-
<< mPointCloudLayerPath
742+
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
738743
);
739744
}
740745

@@ -942,13 +947,11 @@ void TestQgsProcessingPdalAlgs::merge()
942947

943948
QgsProcessingFeedback feedback;
944949

945-
const QString pointCloud1 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/lone-star.copc.laz";
946-
const QString pointCloud2 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb16.copc.laz";
947950
const QString outputFile = QDir::tempPath() + "/merged.las";
948951

949-
// single layer
952+
// default parameters
950953
QVariantMap parameters;
951-
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 );
954+
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << mPointCloudLayerPath );
952955
parameters.insert( QStringLiteral( "OUTPUT" ), outputFile );
953956

954957
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
@@ -958,15 +961,6 @@ void TestQgsProcessingPdalAlgs::merge()
958961
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
959962
);
960963

961-
// multiple layers
962-
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 << pointCloud2 );
963-
args = alg->createArgumentLists( parameters, *context, &feedback );
964-
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
965-
QCOMPARE( args, QStringList() << QStringLiteral( "merge" )
966-
<< QStringLiteral( "--output=%1" ).arg( outputFile )
967-
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
968-
);
969-
970964
// filter expression
971965
parameters.insert( QStringLiteral( "FILTER_EXPRESSION" ), QStringLiteral( "Intensity > 50" ) );
972966
args = alg->createArgumentLists( parameters, *context, &feedback );
@@ -1011,13 +1005,11 @@ void TestQgsProcessingPdalAlgs::buildVpc()
10111005

10121006
QgsProcessingFeedback feedback;
10131007

1014-
const QString pointCloud1 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/lone-star.copc.laz";
1015-
const QString pointCloud2 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb16.copc.laz";
10161008
const QString outputFile = QDir::tempPath() + "/test.vpc";
10171009

1018-
// single layer
1010+
// default parameters
10191011
QVariantMap parameters;
1020-
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 );
1012+
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << mPointCloudLayerPath );
10211013
parameters.insert( QStringLiteral( "OUTPUT" ), outputFile );
10221014

10231015
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
@@ -1027,15 +1019,6 @@ void TestQgsProcessingPdalAlgs::buildVpc()
10271019
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
10281020
);
10291021

1030-
// multiple layers
1031-
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 << pointCloud2 );
1032-
args = alg->createArgumentLists( parameters, *context, &feedback );
1033-
updateFileListArg( args, QStringLiteral( "inputFiles.txt" ) );
1034-
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
1035-
<< QStringLiteral( "--output=%1" ).arg( outputFile )
1036-
<< QStringLiteral( "--input-file-list=inputFiles.txt" )
1037-
);
1038-
10391022
// calculate exact boundaries
10401023
parameters.insert( QStringLiteral( "BOUNDARY" ), true );
10411024
args = alg->createArgumentLists( parameters, *context, &feedback );

0 commit comments

Comments
 (0)