QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
21 
22 QString QgsDropMZValuesAlgorithm::name() const
23 {
24  return QStringLiteral( "dropmzvalues" );
25 }
26 
27 QString QgsDropMZValuesAlgorithm::displayName() const
28 {
29  return QObject::tr( "Drop M/Z values" );
30 }
31 
32 QStringList QgsDropMZValuesAlgorithm::tags() const
33 {
34  return QObject::tr( "drop,set,convert,m,measure,z,25d,3d,values" ).split( ',' );
35 }
36 
37 QString QgsDropMZValuesAlgorithm::group() const
38 {
39  return QObject::tr( "Vector geometry" );
40 }
41 
42 QString QgsDropMZValuesAlgorithm::groupId() const
43 {
44  return QStringLiteral( "vectorgeometry" );
45 }
46 
47 QString QgsDropMZValuesAlgorithm::outputName() const
48 {
49  return QObject::tr( "Z/M Dropped" );
50 }
51 
52 QString QgsDropMZValuesAlgorithm::shortHelpString() const
53 {
54  return QObject::tr( "This algorithm can remove any measure (M) or Z values from input geometries." );
55 }
56 
57 QgsDropMZValuesAlgorithm *QgsDropMZValuesAlgorithm::createInstance() const
58 {
59  return new QgsDropMZValuesAlgorithm();
60 }
61 
62 bool QgsDropMZValuesAlgorithm::supportInPlaceEdit( const QgsMapLayer *layer ) const
63 {
64  Q_UNUSED( layer )
65  return false;
66 }
67 
68 void QgsDropMZValuesAlgorithm::initParameters( const QVariantMap & )
69 {
70  addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_M_VALUES" ), QObject::tr( "Drop M Values" ), false ) );
71  addParameter( new QgsProcessingParameterBoolean( QStringLiteral( "DROP_Z_VALUES" ), QObject::tr( "Drop Z Values" ), false ) );
72 }
73 
74 QgsWkbTypes::Type QgsDropMZValuesAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
75 {
76  QgsWkbTypes::Type wkb = inputWkbType;
77  if ( mDropM )
78  wkb = QgsWkbTypes::dropM( wkb );
79  if ( mDropZ )
80  wkb = QgsWkbTypes::dropZ( wkb );
81  return wkb;
82 }
83 
84 QgsProcessingFeatureSource::Flag QgsDropMZValuesAlgorithm::sourceFlags() const
85 {
87 }
88 
89 bool QgsDropMZValuesAlgorithm::prepareAlgorithm( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback * )
90 {
91  mDropM = parameterAsBoolean( parameters, QStringLiteral( "DROP_M_VALUES" ), context );
92  mDropZ = parameterAsBoolean( parameters, QStringLiteral( "DROP_Z_VALUES" ), context );
93  return true;
94 }
95 
96 QgsFeatureList QgsDropMZValuesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
97 {
98  QgsFeature f = feature;
99  if ( f.hasGeometry() )
100  {
101  std::unique_ptr< QgsAbstractGeometry > newGeom( f.geometry().constGet()->clone() );
102  if ( mDropM )
103  newGeom->dropMValue();
104  if ( mDropZ )
105  newGeom->dropZValue();
106  f.setGeometry( QgsGeometry( newGeom.release() ) );
107  }
108 
109  return QgsFeatureList() << f;
110 }
111 
113 
QgsWkbTypes::dropM
static Type dropM(Type type) SIP_HOLDGIL
Drops the m dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:1213
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:38
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:67
QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition: qgsprocessingutils.h:477
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:139
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition: qgsprocessingcontext.h:44
QgsAbstractGeometry::clone
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:583
QgsWkbTypes::dropZ
static Type dropZ(Type type) SIP_HOLDGIL
Drops the z dimension (if present) for a WKB type and returns the new type.
Definition: qgswkbtypes.h:1195
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const SIP_HOLDGIL
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:128
QgsProcessingParameterBoolean
A boolean parameter for processing algorithms.
Definition: qgsprocessingparameters.h:1507
qgsalgorithmdropmzvalues.h
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition: qgsprocessingutils.h:476
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:199
QgsMapLayer
Base class for all map layer types.
Definition: qgsmaplayer.h:83
QgsFeature
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:56