Skip to content

Commit

Permalink
pass a text file with input data files to tile tool (refs #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 3ed8b17 commit 0fce157
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
15 changes: 14 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,24 @@ QStringList QgsPdalTileAlgorithm::createArgumentLists( const QVariantMap &parame

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: 14 additions & 31 deletions tests/src/analysis/testqgsprocessingpdalalgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
);
}

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

0 comments on commit 0fce157

Please sign in to comment.