QGIS API Documentation 3.99.0-Master (26c88405ac0)
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
23
24QString QgsMultipartToSinglepartAlgorithm::name() const
25{
26 return QStringLiteral( "multiparttosingleparts" );
27}
28
29QString QgsMultipartToSinglepartAlgorithm::displayName() const
30{
31 return QObject::tr( "Multipart to singleparts" );
32}
33
34QString QgsMultipartToSinglepartAlgorithm::outputName() const
35{
36 return QObject::tr( "Single parts" );
37}
38
39Qgis::WkbType QgsMultipartToSinglepartAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
40{
41 return QgsWkbTypes::singleType( inputWkbType );
42}
43
44QStringList QgsMultipartToSinglepartAlgorithm::tags() const
45{
46 return QObject::tr( "multi,single,multiple,split,dump" ).split( ',' );
47}
48
49QString QgsMultipartToSinglepartAlgorithm::group() const
50{
51 return QObject::tr( "Vector geometry" );
52}
53
54QString QgsMultipartToSinglepartAlgorithm::groupId() const
55{
56 return QStringLiteral( "vectorgeometry" );
57}
58
59QString QgsMultipartToSinglepartAlgorithm::shortHelpString() const
60{
61 return QObject::tr( "This algorithm takes a vector layer with multipart geometries and generates a new one in which all geometries contain "
62 "a single part. Features with multipart geometries are divided in as many different features as parts the geometry "
63 "contain, and the same attributes are used for each of them." );
64}
65QString QgsMultipartToSinglepartAlgorithm::shortDescription() const
66{
67 return QObject::tr( "Takes a vector layer with multipart geometries and generates a new one in which all geometries contain "
68 "a single part." );
69}
70
71Qgis::ProcessingAlgorithmDocumentationFlags QgsMultipartToSinglepartAlgorithm::documentationFlags() const
72{
74}
75
76QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::createInstance() const
77{
78 return new QgsMultipartToSinglepartAlgorithm();
79}
80
81
82Qgis::ProcessingFeatureSourceFlags QgsMultipartToSinglepartAlgorithm::sourceFlags() const
83{
84 // skip geometry checks - this algorithm can be used to repair geometries
86}
87
88QgsFeatureSink::SinkFlags QgsMultipartToSinglepartAlgorithm::sinkFlags() const
89{
91}
92
93QgsFeatureList QgsMultipartToSinglepartAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
94{
95 if ( !feature.hasGeometry() )
96 return QgsFeatureList() << feature;
97
98 const QgsGeometry inputGeometry = feature.geometry();
99 QgsFeatureList outputs;
100 if ( inputGeometry.isMultipart() )
101 {
102 const QVector<QgsGeometry> parts = inputGeometry.asGeometryCollection();
103 for ( const QgsGeometry &g : parts )
104 {
105 QgsFeature out;
106 out.setAttributes( feature.attributes() );
107 out.setGeometry( g );
108 outputs.append( out );
109 }
110 }
111 else
112 {
113 outputs.append( feature );
114 }
115 return outputs;
116}
117
118
@ RegeneratesPrimaryKey
Algorithm always drops any existing primary keys or FID values and regenerates them in outputs.
Definition qgis.h:3619
QFlags< ProcessingAlgorithmDocumentationFlag > ProcessingAlgorithmDocumentationFlags
Flags describing algorithm behavior for documentation purposes.
Definition qgis.h:3630
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3711
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3722
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:58
QgsAttributes attributes
Definition qgsfeature.h:67
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
QgsGeometry geometry
Definition qgsfeature.h:69
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:53
QList< QgsFeature > QgsFeatureList