QGIS API Documentation 3.99.0-Master (357b655ed83)
Loading...
Searching...
No Matches
qgsalgorithmmultiparttosinglepart.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmmultiparttosinglepart.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 "qgsvectorlayer.h"
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsMultipartToSinglepartAlgorithm::name() const
29{
30 return u"multiparttosingleparts"_s;
31}
32
33QString QgsMultipartToSinglepartAlgorithm::displayName() const
34{
35 return QObject::tr( "Multipart to singleparts" );
36}
37
38QString QgsMultipartToSinglepartAlgorithm::outputName() const
39{
40 return QObject::tr( "Single parts" );
41}
42
43Qgis::WkbType QgsMultipartToSinglepartAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
44{
45 return QgsWkbTypes::singleType( inputWkbType );
46}
47
48QStringList QgsMultipartToSinglepartAlgorithm::tags() const
49{
50 return QObject::tr( "multi,single,multiple,split,dump" ).split( ',' );
51}
52
53QString QgsMultipartToSinglepartAlgorithm::group() const
54{
55 return QObject::tr( "Vector geometry" );
56}
57
58QString QgsMultipartToSinglepartAlgorithm::groupId() const
59{
60 return u"vectorgeometry"_s;
61}
62
63QString QgsMultipartToSinglepartAlgorithm::shortHelpString() const
64{
65 return QObject::tr( "This algorithm takes a vector layer with multipart geometries and generates a new one in which all geometries contain "
66 "a single part. Features with multipart geometries are divided in as many different features as parts the geometry "
67 "contain, and the same attributes are used for each of them." );
68}
69QString QgsMultipartToSinglepartAlgorithm::shortDescription() const
70{
71 return QObject::tr( "Takes a vector layer with multipart geometries and generates a new one in which all geometries contain "
72 "a single part." );
73}
74
75Qgis::ProcessingAlgorithmDocumentationFlags QgsMultipartToSinglepartAlgorithm::documentationFlags() const
76{
78}
79
80QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::createInstance() const
81{
82 return new QgsMultipartToSinglepartAlgorithm();
83}
84
85
86Qgis::ProcessingFeatureSourceFlags QgsMultipartToSinglepartAlgorithm::sourceFlags() const
87{
88 // skip geometry checks - this algorithm can be used to repair geometries
90}
91
92QgsFeatureSink::SinkFlags QgsMultipartToSinglepartAlgorithm::sinkFlags() const
93{
95}
96
97QgsFeatureList QgsMultipartToSinglepartAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
98{
99 if ( !feature.hasGeometry() )
100 return QgsFeatureList() << feature;
101
102 const QgsGeometry inputGeometry = feature.geometry();
103 QgsFeatureList outputs;
104 if ( inputGeometry.isMultipart() )
105 {
106 const QVector<QgsGeometry> parts = inputGeometry.asGeometryCollection();
107 for ( const QgsGeometry &g : parts )
108 {
109 QgsFeature out;
110 out.setAttributes( feature.attributes() );
111 out.setGeometry( g );
112 outputs.append( out );
113 }
114 }
115 else
116 {
117 outputs.append( feature );
118 }
119 return outputs;
120}
121
122
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
Definition qgis.h:3690
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3701
@ 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
QFlags< SinkFlag > SinkFlags
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsAttributes attributes
Definition qgsfeature.h:69
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
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.
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
bool isMultipart() const
Returns true if WKB of the geometry is of WKBMulti* type.
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
static Qgis::WkbType singleType(Qgis::WkbType type)
Returns the single type for a WKB type.
Definition qgswkbtypes.h:52
QList< QgsFeature > QgsFeatureList