Skip to content

Commit f35a0ba

Browse files
authoredApr 19, 2023
Merge pull request #52763 from alexbruy/processing-pdal-fixes
A few fixes for PDAL provider
2 parents 2924f3e + 0750088 commit f35a0ba

11 files changed

+66
-16
lines changed
 

‎src/analysis/processing/pdal/qgsalgorithmpdalboundary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ QgsPdalBoundaryAlgorithm *QgsPdalBoundaryAlgorithm::createInstance() const
6060
void QgsPdalBoundaryAlgorithm::initAlgorithm( const QVariantMap & )
6161
{
6262
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
63-
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of cells used to calculate boundary" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
63+
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of cells used to calculate boundary" ), QgsProcessingParameterNumber::Double, QVariant(), true, 1 ) );
6464
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "THRESHOLD" ), QObject::tr( "Minimal number of points in a cell to consider cell occupied" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
6565
createCommonParameters();
6666
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Boundary" ), QgsProcessing::TypeVectorPolygon ) );
@@ -92,7 +92,7 @@ QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &pa
9292

9393
if ( hasResolution )
9494
{
95-
args << QStringLiteral( "--resolution=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context ) );
95+
args << QStringLiteral( "--resolution=%1" ).arg( parameterAsDouble( parameters, QStringLiteral( "RESOLUTION" ), context ) );
9696
}
9797

9898
if ( hasThreshold )

‎src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void QgsPdalBuildVpcAlgorithm::initAlgorithm( const QVariantMap & )
6363
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "BOUNDARY" ), QObject::tr( "Calculate boundary polygons" ), false ) );
6464
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "STATISTICS" ), QObject::tr( "Calculate statistics" ), false ) );
6565
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "OVERVIEW" ), QObject::tr( "Build overview point cloud" ), false ) );
66-
addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Virtual point cloud file" ), QObject::tr( "VPC files (*.vpc *.VPC)" ) ) );
66+
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Virtual point cloud file" ) ) );
6767
}
6868

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

79-
const QString outputFile = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT" ), context );
80-
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
79+
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
80+
QString outputFileName( outputName );
81+
82+
QFileInfo fi( outputFileName );
83+
if ( fi.suffix() != QStringLiteral( "vpc" ) )
84+
{
85+
outputFileName = fi.path() + '/' + fi.completeBaseName() + QStringLiteral( ".vpc" );
86+
if ( context.willLoadLayerOnCompletion( outputName ) )
87+
{
88+
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoad = context.layersToLoadOnCompletion();
89+
QgsProcessingContext::LayerDetails details = layersToLoad.take( outputName );
90+
layersToLoad[ outputFileName ] = details;
91+
context.setLayersToLoadOnCompletion( layersToLoad );
92+
}
93+
}
94+
95+
setOutputValue( QStringLiteral( "OUTPUT" ), outputFileName );
8196

8297
QStringList args;
8398
args.reserve( layers.count() + 5 );
8499

85100
args << QStringLiteral( "build_vpc" )
86-
<< QStringLiteral( "--output=%1" ).arg( outputFile );
101+
<< QStringLiteral( "--output=%1" ).arg( outputFileName );
87102

88103
if ( parameterAsBool( parameters, QStringLiteral( "BOUNDARY" ), context ) )
89104
{

‎src/analysis/processing/pdal/qgsalgorithmpdalclip.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ QStringList QgsPdalClipAlgorithm::createArgumentLists( const QVariantMap &parame
7979
QgsVectorFileWriter::supportedFormatExtensions()[0],
8080
feedback );
8181

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

8586
QStringList args = { QStringLiteral( "clip" ),

‎src/analysis/processing/pdal/qgsalgorithmpdaldensity.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void QgsPdalDensityAlgorithm::initAlgorithm( const QVariantMap & )
6363
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of the density raster" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) );
6464
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TILE_SIZE" ), QObject::tr( "Tile size for parallel runs" ), QgsProcessingParameterNumber::Integer, 1000, false, 1 ) );
6565

66-
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
66+
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
6767
paramOriginX->setFlags( paramOriginX->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
6868
addParameter( paramOriginX.release() );
6969
std::unique_ptr< QgsProcessingParameterNumber > paramOriginY = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_Y" ), QObject::tr( "Y origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
@@ -94,7 +94,7 @@ QStringList QgsPdalDensityAlgorithm::createArgumentLists( const QVariantMap &par
9494
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
9595
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
9696

97-
int resolution = parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context );
97+
int resolution = parameterAsDouble( parameters, QStringLiteral( "RESOLUTION" ), context );
9898
int tileSize = parameterAsInt( parameters, QStringLiteral( "TILE_SIZE" ), context );
9999

100100
QStringList args = { QStringLiteral( "density" ),

‎src/analysis/processing/pdal/qgsalgorithmpdalexportraster.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ void QgsPdalExportRasterAlgorithm::initAlgorithm( const QVariantMap & )
6464
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of the density raster" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) );
6565
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TILE_SIZE" ), QObject::tr( "Tile size for parallel runs" ), QgsProcessingParameterNumber::Integer, 1000, false, 1 ) );
6666

67-
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
67+
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
6868
paramOriginX->setFlags( paramOriginX->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
6969
addParameter( paramOriginX.release() );
7070
std::unique_ptr< QgsProcessingParameterNumber > paramOriginY = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_Y" ), QObject::tr( "Y origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
@@ -96,7 +96,7 @@ QStringList QgsPdalExportRasterAlgorithm::createArgumentLists( const QVariantMap
9696
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
9797

9898
const QString attribute = parameterAsString( parameters, QStringLiteral( "ATTRIBUTE" ), context );
99-
const int resolution = parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context );
99+
const int resolution = parameterAsDouble( parameters, QStringLiteral( "RESOLUTION" ), context );
100100
const int tileSize = parameterAsInt( parameters, QStringLiteral( "TILE_SIZE" ), context );
101101

102102
QStringList args = { QStringLiteral( "to_raster" ),

‎src/analysis/processing/pdal/qgsalgorithmpdalexportrastertin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void QgsPdalExportRasterTinAlgorithm::initAlgorithm( const QVariantMap & )
6363
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of the density raster" ), QgsProcessingParameterNumber::Integer, 1, false, 1 ) );
6464
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "TILE_SIZE" ), QObject::tr( "Tile size for parallel runs" ), QgsProcessingParameterNumber::Integer, 1000, false, 1 ) );
6565

66-
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
66+
std::unique_ptr< QgsProcessingParameterNumber > paramOriginX = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_X" ), QObject::tr( "X origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Double, QVariant(), true, 0 );
6767
paramOriginX->setFlags( paramOriginX->flags() | QgsProcessingParameterDefinition::FlagAdvanced );
6868
addParameter( paramOriginX.release() );
6969
std::unique_ptr< QgsProcessingParameterNumber > paramOriginY = std::make_unique< QgsProcessingParameterNumber >( QStringLiteral( "ORIGIN_Y" ), QObject::tr( "Y origin of a tile for parallel runs" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 0 );
@@ -94,7 +94,7 @@ QStringList QgsPdalExportRasterTinAlgorithm::createArgumentLists( const QVariant
9494
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
9595
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
9696

97-
int resolution = parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context );
97+
int resolution = parameterAsDouble( parameters, QStringLiteral( "RESOLUTION" ), context );
9898
int tileSize = parameterAsInt( parameters, QStringLiteral( "TILE_SIZE" ), context );
9999

100100
QStringList args = { QStringLiteral( "to_raster_tin" ),

‎src/analysis/processing/pdal/qgsalgorithmpdalfilter.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ QStringList QgsPdalFilterAlgorithm::createArgumentLists( const QVariantMap &para
7373
if ( !layer )
7474
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );
7575

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

7980
QStringList args = { QStringLiteral( "translate" ),

‎src/analysis/processing/pdal/qgsalgorithmpdalthin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ QStringList QgsPdalThinAlgorithm::createArgumentLists( const QVariantMap &parame
7474
if ( !layer )
7575
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );
7676

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

8081
int mode = parameterAsInt( parameters, QStringLiteral( "MODE" ), context );

‎src/analysis/processing/pdal/qgspdalalgorithmbase.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,27 @@ void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments )
9999
}
100100
}
101101

102+
QString QgsPdalAlgorithmBase::fixOutputFileName( const QString &inputFileName, const QString &outputFileName, QgsProcessingContext &context )
103+
{
104+
bool inputIsVpc = inputFileName.endsWith( QStringLiteral( ".vpc" ), Qt::CaseInsensitive );
105+
bool isTempOutput = outputFileName.startsWith( QgsProcessingUtils::tempFolder(), Qt::CaseInsensitive );
106+
if ( inputIsVpc && isTempOutput )
107+
{
108+
QFileInfo fi( outputFileName );
109+
QString newFileName = fi.path() + '/' + fi.completeBaseName() + QStringLiteral( ".vpc" );
110+
111+
if ( context.willLoadLayerOnCompletion( outputFileName ) )
112+
{
113+
QMap< QString, QgsProcessingContext::LayerDetails > layersToLoad = context.layersToLoadOnCompletion();
114+
QgsProcessingContext::LayerDetails details = layersToLoad.take( outputFileName );
115+
layersToLoad[ newFileName ] = details;
116+
context.setLayersToLoadOnCompletion( layersToLoad );
117+
}
118+
return newFileName;
119+
}
120+
return outputFileName;
121+
}
122+
102123
QStringList QgsPdalAlgorithmBase::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
103124
{
104125
Q_UNUSED( parameters );

‎src/analysis/processing/pdal/qgspdalalgorithmbase.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ class QgsPdalAlgorithmBase : public QgsProcessingAlgorithm
5757
*/
5858
void applyThreadsParameter( QStringList &arguments );
5959

60+
/**
61+
* "Fixes" output file name by changing suffix to .vpc if input file
62+
* is a VPC and output is a temporary output.
63+
*
64+
* This is necessary as pdal_wrench at the moment can create only VPC
65+
* output if input file is a VPC. We automatically adjust output file
66+
* extension for temporary outputs to provide better UX. For normal outputs
67+
* user will see a error if output files is not a VPC.
68+
*/
69+
QString fixOutputFileName( const QString &inputFileName, const QString &outputFileName, QgsProcessingContext &context );
70+
6071
/**
6172
* Returns path to the pdal_wrench executable binary.
6273
*/

‎src/analysis/processing/pdal/qgspdalalgorithms.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QStringList QgsPdalAlgorithms::supportedOutputRasterLayerExtensions() const
8383

8484
QStringList QgsPdalAlgorithms::supportedOutputPointCloudLayerExtensions() const
8585
{
86-
return QStringList() << QStringLiteral( "las" ) << QStringLiteral( "laz" ) << QStringLiteral( "copc.laz" );
86+
return QStringList() << QStringLiteral( "las" ) << QStringLiteral( "laz" ) << QStringLiteral( "copc.laz" ) << QStringLiteral( "vpc" );
8787
}
8888

8989
void QgsPdalAlgorithms::loadAlgorithms()

0 commit comments

Comments
 (0)
Please sign in to comment.