Skip to content

Commit 27210ce

Browse files
alexbruywonder-sk
authored andcommittedMar 22, 2023
add threshold and resolution parameters to boudary algorithm
1 parent c6d8e41 commit 27210ce

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed
 

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

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ void QgsPdalBoundaryAlgorithm::initAlgorithm( const QVariantMap & )
6161
{
6262
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
6363
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Boundary" ), QgsProcessing::TypeVectorPolygon ) );
64+
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "RESOLUTION" ), QObject::tr( "Resolution of cells used to calculate boundary" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
65+
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "THRESHOLD" ), QObject::tr( "Minimal number of points in a cell to consider cell occupied" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
6466
}
6567

6668
QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
@@ -74,12 +76,29 @@ QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &pa
7476
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
7577
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
7678

77-
7879
QStringList args = { QStringLiteral( "boundary" ),
7980
QStringLiteral( "--input=%1" ).arg( layer->source() ),
8081
QStringLiteral( "--output=%1" ).arg( outputFile )
8182
};
8283

84+
bool hasResolution = parameters.value( QStringLiteral( "RESOLUTION" ) ).isValid();
85+
bool hasThreshold = parameters.value( QStringLiteral( "THRESHOLD" ) ).isValid();
86+
87+
if ( hasThreshold && !hasResolution )
88+
{
89+
throw QgsProcessingException( QObject::tr( "Resolution parameter must be set when points threshold is set." ) );
90+
}
91+
92+
if ( hasResolution )
93+
{
94+
args << QStringLiteral( "--resolution=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "RESOLUTION" ), context ) );
95+
}
96+
97+
if ( hasThreshold )
98+
{
99+
args << QStringLiteral( "--threshold=%1" ).arg( parameterAsInt( parameters, QStringLiteral( "THRESHOLD" ), context ) );
100+
}
101+
83102
addThreadsParameter( args );
84103
return args;
85104
}

‎tests/src/analysis/testqgsprocessingpdalalgs.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,27 @@ void TestQgsProcessingPdalAlgs::boundary()
279279
<< QStringLiteral( "--output=%1" ).arg( outputGpkg )
280280
);
281281

282+
// threshold requires resolution parameter
283+
parameters.insert( QStringLiteral( "THRESHOLD" ), 10 );
284+
QVERIFY_EXCEPTION_THROWN( alg->createArgumentLists( parameters, *context, &feedback ), QgsProcessingException );
285+
286+
parameters.insert( QStringLiteral( "RESOLUTION" ), 3000 );
287+
args = alg->createArgumentLists( parameters, *context, &feedback );
288+
QCOMPARE( args, QStringList() << QStringLiteral( "boundary" )
289+
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
290+
<< QStringLiteral( "--output=%1" ).arg( outputGpkg )
291+
<< QStringLiteral( "--resolution=%1" ).arg( 3000 )
292+
<< QStringLiteral( "--threshold=%1" ).arg( 10 )
293+
);
294+
282295
// set max threads to 2, a --threads argument should be added
283296
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
284297
args = alg->createArgumentLists( parameters, *context, &feedback );
285298
QCOMPARE( args, QStringList() << QStringLiteral( "boundary" )
286299
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
287300
<< QStringLiteral( "--output=%1" ).arg( outputGpkg )
301+
<< QStringLiteral( "--resolution=%1" ).arg( 3000 )
302+
<< QStringLiteral( "--threshold=%1" ).arg( 10 )
288303
<< QStringLiteral( "--threads=2" )
289304
);
290305
}

0 commit comments

Comments
 (0)
Please sign in to comment.