Skip to content

Commit a068f9d

Browse files
alexbruywonder-sk
authored andcommittedMar 22, 2023
add boundary algorithm
1 parent 8de4aee commit a068f9d

File tree

5 files changed

+176
-0
lines changed

5 files changed

+176
-0
lines changed
 

‎src/analysis/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ if (WITH_PDAL)
423423

424424
processing/pdal/qgspdalalgorithmbase.cpp
425425

426+
processing/pdal/qgsalgorithmpdalboundary.cpp
426427
processing/pdal/qgsalgorithmpdalconvertformat.cpp
427428
processing/pdal/qgsalgorithmpdalfixprojection.cpp
428429
processing/pdal/qgsalgorithmpdalinformation.cpp
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/***************************************************************************
2+
qgsalgorithmpdalboundary.cpp
3+
---------------------
4+
begin : February 2023
5+
copyright : (C) 2023 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsalgorithmpdalboundary.h"
19+
20+
#include "qgsrunprocess.h"
21+
#include "qgspointcloudlayer.h"
22+
23+
///@cond PRIVATE
24+
25+
QString QgsPdalBoundaryAlgorithm::name() const
26+
{
27+
return QStringLiteral( "boundary" );
28+
}
29+
30+
QString QgsPdalBoundaryAlgorithm::displayName() const
31+
{
32+
return QObject::tr( "Boundary" );
33+
}
34+
35+
QString QgsPdalBoundaryAlgorithm::group() const
36+
{
37+
return QObject::tr( "Point cloud extraction" );
38+
}
39+
40+
QString QgsPdalBoundaryAlgorithm::groupId() const
41+
{
42+
return QStringLiteral( "pointcloudextraction" );
43+
}
44+
45+
QStringList QgsPdalBoundaryAlgorithm::tags() const
46+
{
47+
return QObject::tr( "extent,envelope,bounds,bounding,boundary,vector" ).split( ',' );
48+
}
49+
50+
QString QgsPdalBoundaryAlgorithm::shortHelpString() const
51+
{
52+
return QObject::tr( "This algorithm exports a polygon file containing point cloud layer boundary. It may contain holes and it may be a multi-part polygon." );
53+
}
54+
55+
QgsPdalBoundaryAlgorithm *QgsPdalBoundaryAlgorithm::createInstance() const
56+
{
57+
return new QgsPdalBoundaryAlgorithm();
58+
}
59+
60+
void QgsPdalBoundaryAlgorithm::initAlgorithm( const QVariantMap & )
61+
{
62+
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
63+
addParameter( new QgsProcessingParameterVectorDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Boundary" ), QgsProcessing::TypeVectorPolygon ) );
64+
}
65+
66+
QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
67+
{
68+
Q_UNUSED( feedback );
69+
70+
QgsPointCloudLayer *layer = parameterAsPointCloudLayer( parameters, QStringLiteral( "INPUT" ), context );
71+
if ( !layer )
72+
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );
73+
74+
const QString outputFile = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
75+
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
76+
77+
78+
QStringList args = { QStringLiteral( "boundary" ),
79+
QStringLiteral( "--input=%1" ).arg( layer->source() ),
80+
QStringLiteral( "--output=%1" ).arg( outputFile )
81+
};
82+
83+
addThreadsParameter( args );
84+
return args;
85+
}
86+
87+
///@endcond
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
qgsalgorithmpdalboundary.h
3+
---------------------
4+
begin : February 2023
5+
copyright : (C) 2023 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSALGORITHMPDALBOUNDARY_H
19+
#define QGSALGORITHMPDALBOUNDARY_H
20+
21+
#define SIP_NO_FILE
22+
23+
#include "qgis_sip.h"
24+
#include "qgspdalalgorithmbase.h"
25+
26+
///@cond PRIVATE
27+
28+
/**
29+
* Native point cloud boundary algorithm.
30+
*/
31+
class QgsPdalBoundaryAlgorithm : public QgsPdalAlgorithmBase
32+
{
33+
34+
public:
35+
36+
QgsPdalBoundaryAlgorithm() = default;
37+
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
38+
QString name() const override;
39+
QString displayName() const override;
40+
QString group() const override;
41+
QString groupId() const override;
42+
QStringList tags() const override;
43+
QString shortHelpString() const override;
44+
QgsPdalBoundaryAlgorithm *createInstance() const override SIP_FACTORY;
45+
46+
QStringList createArgumentLists( const QVariantMap &parameters,
47+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
48+
49+
friend class TestQgsProcessingPdalAlgs;
50+
};
51+
52+
///@endcond PRIVATE
53+
54+
#endif // QGSALGORITHMPDALBOUNDARY_H

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "qgsruntimeprofiler.h"
2020
#include "qgsapplication.h"
2121

22+
#include "qgsalgorithmpdalboundary.h"
2223
#include "qgsalgorithmpdalconvertformat.h"
2324
#include "qgsalgorithmpdalfixprojection.h"
2425
#include "qgsalgorithmpdalinformation.h"
@@ -80,6 +81,7 @@ void QgsPdalAlgorithms::loadAlgorithms()
8081
{
8182
const QgsScopedRuntimeProfile profile( QObject::tr( "QGIS PDAL provider" ) );
8283

84+
addAlgorithm( new QgsPdalBoundaryAlgorithm() );
8385
addAlgorithm( new QgsPdalConvertFormatAlgorithm() );
8486
addAlgorithm( new QgsPdalFixProjectionAlgorithm() );
8587
addAlgorithm( new QgsPdalInformationAlgorithm() );

‎tests/src/analysis/testqgsprocessingpdalalgs.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class TestQgsProcessingPdalAlgs: public QObject
3434
void init(); // will be called before each testfunction is executed.
3535
void cleanup() {} // will be called after every testfunction.
3636

37+
void boundary();
3738
void convertFormat();
3839
void fixProjection();
3940
void info();
@@ -248,5 +249,36 @@ void TestQgsProcessingPdalAlgs::thin()
248249
);
249250
}
250251

252+
void TestQgsProcessingPdalAlgs::boundary()
253+
{
254+
QgsPdalAlgorithmBase *alg = const_cast<QgsPdalAlgorithmBase *>( static_cast< const QgsPdalAlgorithmBase * >( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "pdal:boundary" ) ) ) );
255+
256+
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
257+
context->setProject( QgsProject::instance() );
258+
259+
QgsProcessingFeedback feedback;
260+
261+
const QString outputGpkg = QDir::tempPath() + "/boundary.gpkg";
262+
263+
QVariantMap parameters;
264+
parameters.insert( QStringLiteral( "INPUT" ), mPointCloudLayerPath );
265+
parameters.insert( QStringLiteral( "OUTPUT" ), outputGpkg );
266+
267+
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
268+
QCOMPARE( args, QStringList() << QStringLiteral( "boundary" )
269+
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
270+
<< QStringLiteral( "--output=%1" ).arg( outputGpkg )
271+
);
272+
273+
// set max threads to 2, a --threads argument should be added
274+
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
275+
args = alg->createArgumentLists( parameters, *context, &feedback );
276+
QCOMPARE( args, QStringList() << QStringLiteral( "boundary" )
277+
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
278+
<< QStringLiteral( "--output=%1" ).arg( outputGpkg )
279+
<< QStringLiteral( "--threads=2" )
280+
);
281+
}
282+
251283
QGSTEST_MAIN( TestQgsProcessingPdalAlgs )
252284
#include "testqgsprocessingpdalalgs.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.