Skip to content

Commit

Permalink
add a special handling for output layers if input is a VPC and a
Browse files Browse the repository at this point in the history
temporary output is generated. In this case we force output to be a VPC
too in order to provide better UX. Later, when pdal_wrench will be able
to create las/laz/copc files from VPC inputs this handling will be
removed.
  • Loading branch information
alexbruy committed Apr 18, 2023
1 parent c6d3488 commit 0750088
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 7 deletions.
23 changes: 19 additions & 4 deletions src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp
Expand Up @@ -63,7 +63,7 @@ void QgsPdalBuildVpcAlgorithm::initAlgorithm( const QVariantMap & )
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "BOUNDARY" ), QObject::tr( "Calculate boundary polygons" ), false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "STATISTICS" ), QObject::tr( "Calculate statistics" ), false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "OVERVIEW" ), QObject::tr( "Build overview point cloud" ), false ) );
addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Virtual point cloud file" ), QObject::tr( "VPC files (*.vpc *.VPC)" ) ) );
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Virtual point cloud file" ) ) );
}

QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
Expand All @@ -76,14 +76,29 @@ QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &pa
feedback->reportError( QObject::tr( "No layers selected" ), true );
}

const QString outputFile = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT" ), context );
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QString outputFileName( outputName );

QFileInfo fi( outputFileName );
if ( fi.suffix() != QStringLiteral( "vpc" ) )
{
outputFileName = fi.path() + '/' + fi.completeBaseName() + QStringLiteral( ".vpc" );
if ( context.willLoadLayerOnCompletion( outputName ) )
{
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoad = context.layersToLoadOnCompletion();
QgsProcessingContext::LayerDetails details = layersToLoad.take( outputName );
layersToLoad[ outputFileName ] = details;
context.setLayersToLoadOnCompletion( layersToLoad );
}
}

setOutputValue( QStringLiteral( "OUTPUT" ), outputFileName );

QStringList args;
args.reserve( layers.count() + 5 );

args << QStringLiteral( "build_vpc" )
<< QStringLiteral( "--output=%1" ).arg( outputFile );
<< QStringLiteral( "--output=%1" ).arg( outputFileName );

if ( parameterAsBool( parameters, QStringLiteral( "BOUNDARY" ), context ) )
{
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalclip.cpp
Expand Up @@ -79,7 +79,8 @@ QStringList QgsPdalClipAlgorithm::createArgumentLists( const QVariantMap &parame
QgsVectorFileWriter::supportedFormatExtensions()[0],
feedback );

const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QString outputFile = fixOutputFileName( layer->source(), outputName, context );
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );

QStringList args = { QStringLiteral( "clip" ),
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalfilter.cpp
Expand Up @@ -73,7 +73,8 @@ QStringList QgsPdalFilterAlgorithm::createArgumentLists( const QVariantMap &para
if ( !layer )
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );

const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QString outputFile = fixOutputFileName( layer->source(), outputName, context );
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );

QStringList args = { QStringLiteral( "translate" ),
Expand Down
3 changes: 2 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalthin.cpp
Expand Up @@ -74,7 +74,8 @@ QStringList QgsPdalThinAlgorithm::createArgumentLists( const QVariantMap &parame
if ( !layer )
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );

const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QString outputFile = fixOutputFileName( layer->source(), outputName, context );
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );

int mode = parameterAsInt( parameters, QStringLiteral( "MODE" ), context );
Expand Down
21 changes: 21 additions & 0 deletions src/analysis/processing/pdal/qgspdalalgorithmbase.cpp
Expand Up @@ -99,6 +99,27 @@ void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments )
}
}

QString QgsPdalAlgorithmBase::fixOutputFileName( const QString &inputFileName, const QString &outputFileName, QgsProcessingContext &context )
{
bool inputIsVpc = inputFileName.endsWith( QStringLiteral( ".vpc" ), Qt::CaseInsensitive );
bool isTempOutput = outputFileName.startsWith( QgsProcessingUtils::tempFolder(), Qt::CaseInsensitive );
if ( inputIsVpc && isTempOutput )
{
QFileInfo fi( outputFileName );
QString newFileName = fi.path() + '/' + fi.completeBaseName() + QStringLiteral( ".vpc" );

if ( context.willLoadLayerOnCompletion( outputFileName ) )
{
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoad = context.layersToLoadOnCompletion();
QgsProcessingContext::LayerDetails details = layersToLoad.take( outputFileName );
layersToLoad[ newFileName ] = details;
context.setLayersToLoadOnCompletion( layersToLoad );
}
return newFileName;
}
return outputFileName;
}

QStringList QgsPdalAlgorithmBase::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( parameters );
Expand Down
11 changes: 11 additions & 0 deletions src/analysis/processing/pdal/qgspdalalgorithmbase.h
Expand Up @@ -57,6 +57,17 @@ class QgsPdalAlgorithmBase : public QgsProcessingAlgorithm
*/
void applyThreadsParameter( QStringList &arguments );

/**
* "Fixes" output file name by changing suffix to .vpc if input file
* is a VPC and output is a temporary output.
*
* This is necessary as pdal_wrench at the moment can create only VPC
* output if input file is a VPC. We automatically adjust output file
* extension for temporary outputs to provide better UX. For normal outputs
* user will see a error if output files is not a VPC.
*/
QString fixOutputFileName( const QString &inputFileName, const QString &outputFileName, QgsProcessingContext &context );

/**
* Returns path to the pdal_wrench executable binary.
*/
Expand Down

0 comments on commit 0750088

Please sign in to comment.