/
qgsalgorithmdropmzvalues.cpp
107 lines (88 loc) · 3.48 KB
/
qgsalgorithmdropmzvalues.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
/***************************************************************************
qgsalgorithmdropmzvalues.cpp
---------------------
begin : April 2017
copyright : (C) 2017 by Nyall Dawson
email : nyall dot dawson 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 "qgsalgorithmdropmzvalues.h"
///@cond PRIVATE
QgsProcessingAlgorithm::Flags QgsDropMZValuesAlgorithm::flags() const
{
return QgsProcessingFeatureBasedAlgorithm::flags() | QgsProcessingAlgorithm::FlagCanRunInBackground;
}
QString QgsDropMZValuesAlgorithm::name() const
{
return QStringLiteral( "dropmzvalues" );
}
QString QgsDropMZValuesAlgorithm::displayName() const
{
return QObject::tr( "Drop M/Z values" );
}
QStringList QgsDropMZValuesAlgorithm::tags() const
{
return QObject::tr( "drop,set,convert,m,measure,z,25d,3d,values" ).split( ',' );
}
QString QgsDropMZValuesAlgorithm::group() const
{
return QObject::tr( "Vector geometry" );
}
QString QgsDropMZValuesAlgorithm::groupId() const
{
return QStringLiteral( "vectorgeometry" );
}
QString QgsDropMZValuesAlgorithm::outputName() const
{
return QObject::tr( "Z/M Dropped" );
}
QString QgsDropMZValuesAlgorithm::shortHelpString() const
{
return QObject::tr( "This algorithm can remove any measure (M) or Z values from input geometries." );
}
QgsDropMZValuesAlgorithm *QgsDropMZValuesAlgorithm::createInstance() const
{
return new QgsDropMZValuesAlgorithm();
}
void QgsDropMZValuesAlgorithm::initParameters( const QVariantMap & )
{
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_M_VALUES" ), QObject::tr( "Drop M Values" ), false ) );
addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_Z_VALUES" ), QObject::tr( "Drop Z Values" ), false ) );
}
QgsWkbTypes::Type QgsDropMZValuesAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
{
QgsWkbTypes::Type wkb = inputWkbType;
if ( mDropM )
wkb = QgsWkbTypes::dropM( wkb );
if ( mDropZ )
wkb = QgsWkbTypes::dropZ( wkb );
return wkb;
}
bool QgsDropMZValuesAlgorithm::prepareAlgorithm( const QVariantMap ¶meters, QgsProcessingContext &context, QgsProcessingFeedback * )
{
mDropM = parameterAsBool( parameters, QStringLiteral( "DROP_M_VALUES" ), context );
mDropZ = parameterAsBool( parameters, QStringLiteral( "DROP_Z_VALUES" ), context );
return true;
}
QgsFeature QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
{
QgsFeature f = feature;
if ( f.hasGeometry() )
{
std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().constGet()->clone() );
if ( mDropM )
newGeom->dropMValue();
if ( mDropZ )
newGeom->dropZValue();
f.setGeometry( QgsGeometry( newGeom.release() ) );
}
return f;
}
///@endcond