/
qgsalgorithmpdalfilter.cpp
121 lines (99 loc) · 4.74 KB
/
qgsalgorithmpdalfilter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/***************************************************************************
qgsalgorithmpdalfilter.cpp
---------------------
begin : March 2023
copyright : (C) 2023 by Alexander Bruy
email : alexander dot bruy at gmail dot com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsalgorithmpdalfilter.h"
#include "qgsrunprocess.h"
#include "qgspointcloudlayer.h"
#include "qgspointcloudexpression.h"
///@cond PRIVATE
QString QgsPdalFilterAlgorithm::name() const
{
return QStringLiteral( "filter" );
}
QString QgsPdalFilterAlgorithm::displayName() const
{
return QObject::tr( "Filter" );
}
QString QgsPdalFilterAlgorithm::group() const
{
return QObject::tr( "Point cloud extraction" );
}
QString QgsPdalFilterAlgorithm::groupId() const
{
return QStringLiteral( "pointcloudextraction" );
}
QStringList QgsPdalFilterAlgorithm::tags() const
{
return QObject::tr( "pdal,lidar,filter,subset,extract,dimension,attribute,extent,bounds,rectangle" ).split( ',' );
}
QString QgsPdalFilterAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm extracts point from the input point cloud which match PDAL expression and/or are inside of a cropping rectangle." );
}
QgsPdalFilterAlgorithm *QgsPdalFilterAlgorithm::createInstance() const
{
return new QgsPdalFilterAlgorithm();
}
void QgsPdalFilterAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterExpression( QStringLiteral( "FILTER_EXPRESSION" ), QObject::tr( "Filter expression" ), QVariant(), QStringLiteral( "INPUT" ), false, Qgis::ExpressionType::PointCloud ) );
addParameter( new QgsProcessingParameterExtent( QStringLiteral( "FILTER_EXTENT" ), QObject::tr( "Cropping extent" ), QVariant(), true ) );
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Filtered" ) ) );
}
QStringList QgsPdalFilterAlgorithm::createArgumentLists( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
Q_UNUSED( feedback );
QgsPointCloudLayer *layer = parameterAsPointCloudLayer( parameters, QStringLiteral( "INPUT" ), context, QgsProcessing::LayerOptionsFlag::SkipIndexGeneration );
if ( !layer )
throw QgsProcessingException( invalidPointCloudError( parameters, QStringLiteral( "INPUT" ) ) );
const QString outputName = parameterAsOutputLayer( parameters, QStringLiteral( "OUTPUT" ), context );
QString outputFile = fixOutputFileName( layer->source(), outputName, context );
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
QStringList args = { QStringLiteral( "translate" ),
QStringLiteral( "--input=%1" ).arg( layer->source() ),
QStringLiteral( "--output=%1" ).arg( outputFile )
};
const QString filterExpression = parameterAsString( parameters, QStringLiteral( "FILTER_EXPRESSION" ), context ).trimmed();
if ( !filterExpression.isEmpty() )
{
QgsPointCloudExpression exp( filterExpression );
args << QStringLiteral( "--filter=%1" ).arg( exp.asPdalExpression() );
}
if ( parameters.value( QStringLiteral( "FILTER_EXTENT" ) ).isValid() )
{
if ( layer->crs().isValid() )
{
const QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "FILTER_EXTENT" ), context, layer->crs() );
args << QStringLiteral( "--bounds=([%1, %2], [%3, %4])" )
.arg( extent.xMinimum() )
.arg( extent.xMaximum() )
.arg( extent.yMinimum() )
.arg( extent.yMaximum() );
}
else
{
const QgsRectangle extent = parameterAsExtent( parameters, QStringLiteral( "FILTER_EXTENT" ), context );
args << QStringLiteral( "--bounds=([%1, %2], [%3, %4])" )
.arg( extent.xMinimum() )
.arg( extent.xMaximum() )
.arg( extent.yMinimum() )
.arg( extent.yMaximum() );
}
}
applyThreadsParameter( args, context );
return args;
}
///@endcond