Skip to content

Commit

Permalink
[processing] add new options to build vpc algorithm
Browse files Browse the repository at this point in the history
This includes options to calculate statistics from the input data,
calculate exact boundaries and build an overview point cloud
  • Loading branch information
alexbruy authored and wonder-sk committed Apr 13, 2023
1 parent f89591b commit c4774d6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 5 deletions.
20 changes: 19 additions & 1 deletion src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp
Expand Up @@ -60,6 +60,9 @@ QgsPdalBuildVpcAlgorithm *QgsPdalBuildVpcAlgorithm::createInstance() const
void QgsPdalBuildVpcAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ), QgsProcessing::TypePointCloud ) );
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)" ) ) );
}

Expand All @@ -77,11 +80,26 @@ QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &pa
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );

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

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

if ( parameterAsBool( parameters, QStringLiteral( "BOUNDARY" ), context ) )
{
args << "--boundary";
}

if ( parameterAsBool( parameters, QStringLiteral( "STATISTICS" ), context ) )
{
args << "--stats";
}

if ( parameterAsBool( parameters, QStringLiteral( "OVERVIEW" ), context ) )
{
args << "--overview";
}

addThreadsParameter( args );

for ( const QgsMapLayer *layer : std::as_const( layers ) )
Expand Down
44 changes: 40 additions & 4 deletions tests/src/analysis/testqgsprocessingpdalalgs.cpp
Expand Up @@ -154,7 +154,7 @@ void TestQgsProcessingPdalAlgs::reproject()
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--transform-crs=%1" ).arg( QLatin1String( "EPSG:4326") )
<< QStringLiteral( "--transform-crs=%1" ).arg( QLatin1String( "EPSG:4326" ) )
);

// set max threads to 2, a --threads argument should be added
Expand All @@ -163,7 +163,7 @@ void TestQgsProcessingPdalAlgs::reproject()
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--transform-crs=%1" ).arg( QLatin1String( "EPSG:4326") )
<< QStringLiteral( "--transform-crs=%1" ).arg( QLatin1String( "EPSG:4326" ) )
<< QStringLiteral( "--threads=2" )
);
}
Expand All @@ -188,7 +188,7 @@ void TestQgsProcessingPdalAlgs::fixProjection()
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--assign-crs=%1" ).arg( QLatin1String( "EPSG:4326") )
<< QStringLiteral( "--assign-crs=%1" ).arg( QLatin1String( "EPSG:4326" ) )
);

// set max threads to 2, a --threads argument should be added
Expand All @@ -197,7 +197,7 @@ void TestQgsProcessingPdalAlgs::fixProjection()
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--assign-crs=%1" ).arg( QLatin1String( "EPSG:4326") )
<< QStringLiteral( "--assign-crs=%1" ).arg( QLatin1String( "EPSG:4326" ) )
<< QStringLiteral( "--threads=2" )
);
}
Expand Down Expand Up @@ -749,11 +749,47 @@ void TestQgsProcessingPdalAlgs::buildVpc()
<< pointCloud2
);

// calculate exact boundaries
parameters.insert( QStringLiteral( "BOUNDARY" ), true );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
<< QStringLiteral( "--output=%1" ).arg( outputFile )
<< QStringLiteral( "--boundary" )
<< pointCloud1
<< pointCloud2
);

// calculate statistics
parameters.insert( QStringLiteral( "STATISTICS" ), true );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
<< QStringLiteral( "--output=%1" ).arg( outputFile )
<< QStringLiteral( "--boundary" )
<< QStringLiteral( "--stats" )
<< pointCloud1
<< pointCloud2
);

// build overview
parameters.insert( QStringLiteral( "OVERVIEW" ), true );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
<< QStringLiteral( "--output=%1" ).arg( outputFile )
<< QStringLiteral( "--boundary" )
<< QStringLiteral( "--stats" )
<< QStringLiteral( "--overview" )
<< pointCloud1
<< pointCloud2
);

// set max threads to 2, a --threads argument should be added
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
<< QStringLiteral( "--output=%1" ).arg( outputFile )
<< QStringLiteral( "--boundary" )
<< QStringLiteral( "--stats" )
<< QStringLiteral( "--overview" )
<< QStringLiteral( "--threads=2" )
<< pointCloud1
<< pointCloud2
Expand Down

0 comments on commit c4774d6

Please sign in to comment.