QGIS API Documentation  3.2.0-Bonn (bc43194)
qgsalgorithmpromotetomultipart.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsalgorithmpromotetomultipart.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 QgsPromoteToMultipartAlgorithm::name() const
23 {
24  return QStringLiteral( "promotetomulti" );
25 }
26 
27 QString QgsPromoteToMultipartAlgorithm::displayName() const
28 {
29  return QObject::tr( "Promote to multipart" );
30 }
31 
32 QStringList QgsPromoteToMultipartAlgorithm::tags() const
33 {
34  return QObject::tr( "multi,single,multiple,convert,force,parts" ).split( ',' );
35 }
36 
37 QString QgsPromoteToMultipartAlgorithm::group() const
38 {
39  return QObject::tr( "Vector geometry" );
40 }
41 
42 QString QgsPromoteToMultipartAlgorithm::groupId() const
43 {
44  return QStringLiteral( "vectorgeometry" );
45 }
46 
47 QString QgsPromoteToMultipartAlgorithm::outputName() const
48 {
49  return QObject::tr( "Multiparts" );
50 }
51 
52 QString QgsPromoteToMultipartAlgorithm::shortHelpString() const
53 {
54  return QObject::tr( "This algorithm takes a vector layer with singlepart geometries and generates a new one in which all geometries are "
55  "multipart. Input features which are already multipart features will remain unchanged." ) +
56  QStringLiteral( "\n\n" ) +
57  QObject::tr( "This algorithm can be used to force geometries to multipart types in order to be compatibility with data providers "
58  "with strict singlepart/multipart compatibility checks." ) +
59  QStringLiteral( "\n\n" ) +
60  QObject::tr( "See the 'Collect geometries' or 'Aggregate' algorithms for alternative options." );
61 }
62 
63 QgsPromoteToMultipartAlgorithm *QgsPromoteToMultipartAlgorithm::createInstance() const
64 {
65  return new QgsPromoteToMultipartAlgorithm();
66 }
67 
68 QgsWkbTypes::Type QgsPromoteToMultipartAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
69 {
70  return QgsWkbTypes::multiType( inputWkbType );
71 }
72 
73 QgsProcessingFeatureSource::Flag QgsPromoteToMultipartAlgorithm::sourceFlags() const
74 {
76 }
77 
78 QgsFeatureList QgsPromoteToMultipartAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
79 {
80  QgsFeature f = feature;
81  if ( f.hasGeometry() && !f.geometry().isMultipart() )
82  {
83  QgsGeometry g = f.geometry();
85  f.setGeometry( g );
86  }
87  return QgsFeatureList() << f;
88 }
89 
91 
92 
static Type multiType(Type type)
Returns the multi type for a WKB type.
Definition: qgswkbtypes.h:296
Base class for providing feedback from a processing algorithm.
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:549
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:104
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:62
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:190
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:67
QgsGeometry geometry() const
Returns the geometry associated with this feature.
Definition: qgsfeature.cpp:101
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
void setGeometry(const QgsGeometry &geometry)
Set the feature&#39;s geometry.
Definition: qgsfeature.cpp:137
Contains information about the context in which a processing algorithm is executed.