QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmdropmzvalues.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmdropmzvalues.cpp
3 ---------------------
4 begin : April 2017
5 copyright : (C) 2017 by Nyall Dawson
6 email : nyall dot dawson 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
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
25
26QString QgsDropMZValuesAlgorithm::name() const
27{
28 return u"dropmzvalues"_s;
29}
30
31QString QgsDropMZValuesAlgorithm::displayName() const
32{
33 return QObject::tr( "Drop M/Z values" );
34}
35
36QStringList QgsDropMZValuesAlgorithm::tags() const
37{
38 return QObject::tr( "drop,set,convert,m,measure,z,25d,3d,values" ).split( ',' );
39}
40
41QString QgsDropMZValuesAlgorithm::group() const
42{
43 return QObject::tr( "Vector geometry" );
44}
45
46QString QgsDropMZValuesAlgorithm::groupId() const
47{
48 return u"vectorgeometry"_s;
49}
50
51QString QgsDropMZValuesAlgorithm::outputName() const
52{
53 return QObject::tr( "Z/M Dropped" );
54}
55
56QString QgsDropMZValuesAlgorithm::shortHelpString() const
57{
58 return QObject::tr( "This algorithm can remove any measure (M) or Z values from input geometries." );
59}
60
61QString QgsDropMZValuesAlgorithm::shortDescription() const
62{
63 return QObject::tr( "Removes any measure (M) or Z values from input geometries." );
64}
65
66QgsDropMZValuesAlgorithm *QgsDropMZValuesAlgorithm::createInstance() const
67{
68 return new QgsDropMZValuesAlgorithm();
69}
70
71bool QgsDropMZValuesAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
72{
73 Q_UNUSED( layer )
74 return false;
75}
76
77void QgsDropMZValuesAlgorithm::initParameters( const QVariantMap & )
78{
79 addParameter( new QgsProcessingParameterBoolean( u"DROP_M_VALUES"_s, QObject::tr( "Drop M Values" ), false ) );
80 addParameter( new QgsProcessingParameterBoolean( u"DROP_Z_VALUES"_s, QObject::tr( "Drop Z Values" ), false ) );
81}
82
83Qgis::WkbType QgsDropMZValuesAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
84{
85 Qgis::WkbType wkb = inputWkbType;
86 if ( mDropM )
87 wkb = QgsWkbTypes::dropM( wkb );
88 if ( mDropZ )
89 wkb = QgsWkbTypes::dropZ( wkb );
90 return wkb;
91}
92
93Qgis::ProcessingFeatureSourceFlags QgsDropMZValuesAlgorithm::sourceFlags() const
94{
96}
97
98bool QgsDropMZValuesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
99{
100 mDropM = parameterAsBoolean( parameters, u"DROP_M_VALUES"_s, context );
101 mDropZ = parameterAsBoolean( parameters, u"DROP_Z_VALUES"_s, context );
102 return true;
103}
104
105QgsFeatureList QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
106{
107 QgsFeature f = feature;
108 if ( f.hasGeometry() )
109 {
110 std::unique_ptr<QgsAbstractGeometry> newGeom( f.geometry().constGet()->clone() );
111 if ( mDropM )
112 newGeom->dropMValue();
113 if ( mDropZ )
114 newGeom->dropZValue();
115 f.setGeometry( QgsGeometry( newGeom.release() ) );
116 }
117
118 return QgsFeatureList() << f;
119}
120
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3782
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3793
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsGeometry geometry
Definition qgsfeature.h:71
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Base class for all map layer types.
Definition qgsmaplayer.h:83
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
A boolean parameter for processing algorithms.
static Qgis::WkbType dropM(Qgis::WkbType type)
Drops the m dimension (if present) for a WKB type and returns the new type.
static Qgis::WkbType dropZ(Qgis::WkbType type)
Drops the z dimension (if present) for a WKB type and returns the new type.
QList< QgsFeature > QgsFeatureList