QGIS API Documentation
3.26.3-Buenos Aires (65e4edfdad)
src
analysis
processing
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
18
#include "
qgsalgorithmmultiparttosinglepart.h
"
19
#include "
qgsvectorlayer.h
"
20
22
23
QString QgsMultipartToSinglepartAlgorithm::name()
const
24
{
25
return
QStringLiteral(
"multiparttosingleparts"
);
26
}
27
28
QString QgsMultipartToSinglepartAlgorithm::displayName()
const
29
{
30
return
QObject::tr(
"Multipart to singleparts"
);
31
}
32
33
QString QgsMultipartToSinglepartAlgorithm::outputName()
const
34
{
35
return
QObject::tr(
"Single parts"
);
36
}
37
38
QgsWkbTypes::Type
QgsMultipartToSinglepartAlgorithm::outputWkbType(
QgsWkbTypes::Type
inputWkbType )
const
39
{
40
return
QgsWkbTypes::singleType
( inputWkbType );
41
}
42
43
QStringList QgsMultipartToSinglepartAlgorithm::tags()
const
44
{
45
return
QObject::tr(
"multi,single,multiple,split,dump"
).split(
','
);
46
}
47
48
QString QgsMultipartToSinglepartAlgorithm::group()
const
49
{
50
return
QObject::tr(
"Vector geometry"
);
51
}
52
53
QString QgsMultipartToSinglepartAlgorithm::groupId()
const
54
{
55
return
QStringLiteral(
"vectorgeometry"
);
56
}
57
58
QString QgsMultipartToSinglepartAlgorithm::shortHelpString()
const
59
{
60
return
QObject::tr(
"This algorithm takes a vector layer with multipart geometries and generates a new one in which all geometries contain "
61
"a single part. Features with multipart geometries are divided in as many different features as parts the geometry "
62
"contain, and the same attributes are used for each of them."
);
63
}
64
65
QgsMultipartToSinglepartAlgorithm *QgsMultipartToSinglepartAlgorithm::createInstance()
const
66
{
67
return
new
QgsMultipartToSinglepartAlgorithm();
68
}
69
70
71
QgsProcessingFeatureSource::Flag
QgsMultipartToSinglepartAlgorithm::sourceFlags()
const
72
{
73
// skip geometry checks - this algorithm can be used to repair geometries
74
return
QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks
;
75
}
76
77
QgsFeatureSink::SinkFlags QgsMultipartToSinglepartAlgorithm::sinkFlags()
const
78
{
79
return
QgsFeatureSink::RegeneratePrimaryKey
;
80
}
81
82
QgsFeatureList
QgsMultipartToSinglepartAlgorithm::processFeature(
const
QgsFeature
&feature,
QgsProcessingContext
&,
QgsProcessingFeedback
* )
83
{
84
if
( !feature.
hasGeometry
() )
85
return
QgsFeatureList
() << feature;
86
87
const
QgsGeometry
inputGeometry = feature.
geometry
();
88
QgsFeatureList
outputs;
89
if
( inputGeometry.
isMultipart
() )
90
{
91
const
QVector<QgsGeometry> parts = inputGeometry.
asGeometryCollection
();
92
for
(
const
QgsGeometry
&g : parts )
93
{
94
QgsFeature
out;
95
out.
setAttributes
( feature.
attributes
() );
96
out.
setGeometry
( g );
97
outputs.append( out );
98
}
99
}
100
else
101
{
102
outputs.append( feature );
103
}
104
return
outputs;
105
}
106
107
109
110
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition:
qgsprocessingfeedback.h:37
qgsalgorithmmultiparttosinglepart.h
QgsFeature::geometry
QgsGeometry geometry
Definition:
qgsfeature.h:71
QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition:
qgsprocessingutils.h:584
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition:
qgswkbtypes.h:69
QgsGeometry::asGeometryCollection
QVector< QgsGeometry > asGeometryCollection() const
Returns contents of the geometry as a list of geometries.
Definition:
qgsgeometry.cpp:2753
QgsGeometry::isMultipart
bool isMultipart() const SIP_HOLDGIL
Returns true if WKB of the geometry is of WKBMulti* type.
Definition:
qgsgeometry.cpp:389
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition:
qgsfeature.cpp:170
QgsProcessingContext
Contains information about the context in which a processing algorithm is executed.
Definition:
qgsprocessingcontext.h:46
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition:
qgsfeature.h:882
QgsFeatureSink::RegeneratePrimaryKey
@ RegeneratePrimaryKey
This flag indicates, that a primary key field cannot be guaranteed to be unique and the sink should i...
Definition:
qgsfeaturesink.h:55
QgsFeature::attributes
QgsAttributes attributes
Definition:
qgsfeature.h:69
qgsvectorlayer.h
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition:
qgsprocessingutils.h:582
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:230
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition:
qgsfeature.h:55
QgsFeature::setAttributes
void setAttributes(const QgsAttributes &attrs)
Sets the feature's attributes.
Definition:
qgsfeature.cpp:160
QgsWkbTypes::singleType
static Type singleType(Type type) SIP_HOLDGIL
Returns the single type for a WKB type.
Definition:
qgswkbtypes.h:157
Generated on Sun Sep 11 2022 00:03:17 for QGIS API Documentation by
1.8.17