QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgsvectorlayer.h"
20 
22 
23 QString QgsPromoteToMultipartAlgorithm::name() const
24 {
25  return QStringLiteral( "promotetomulti" );
26 }
27 
28 QString QgsPromoteToMultipartAlgorithm::displayName() const
29 {
30  return QObject::tr( "Promote to multipart" );
31 }
32 
33 QStringList QgsPromoteToMultipartAlgorithm::tags() const
34 {
35  return QObject::tr( "multi,single,multiple,convert,force,parts" ).split( ',' );
36 }
37 
38 QString QgsPromoteToMultipartAlgorithm::group() const
39 {
40  return QObject::tr( "Vector geometry" );
41 }
42 
43 QString QgsPromoteToMultipartAlgorithm::groupId() const
44 {
45  return QStringLiteral( "vectorgeometry" );
46 }
47 
48 QString QgsPromoteToMultipartAlgorithm::outputName() const
49 {
50  return QObject::tr( "Multiparts" );
51 }
52 
53 QString QgsPromoteToMultipartAlgorithm::shortHelpString() const
54 {
55  return QObject::tr( "This algorithm takes a vector layer with singlepart geometries and generates a new one in which all geometries are "
56  "multipart. Input features which are already multipart features will remain unchanged." ) +
57  QStringLiteral( "\n\n" ) +
58  QObject::tr( "This algorithm can be used to force geometries to multipart types in order to be compatible with data providers "
59  "with strict singlepart/multipart compatibility checks." ) +
60  QStringLiteral( "\n\n" ) +
61  QObject::tr( "See the 'Collect geometries' or 'Aggregate' algorithms for alternative options." );
62 }
63 
64 QgsPromoteToMultipartAlgorithm *QgsPromoteToMultipartAlgorithm::createInstance() const
65 {
66  return new QgsPromoteToMultipartAlgorithm();
67 }
68 
69 bool QgsPromoteToMultipartAlgorithm::supportInPlaceEdit( const QgsMapLayer *l ) const
70 {
71  const QgsVectorLayer *layer = qobject_cast< const QgsVectorLayer * >( l );
72  if ( !layer )
73  return false;
74 
76  return false;
77  return QgsWkbTypes::isMultiType( layer->wkbType() );
78 }
79 
80 QgsWkbTypes::Type QgsPromoteToMultipartAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
81 {
82  return QgsWkbTypes::multiType( inputWkbType );
83 }
84 
85 QgsProcessingFeatureSource::Flag QgsPromoteToMultipartAlgorithm::sourceFlags() const
86 {
88 }
89 
90 QgsFeatureList QgsPromoteToMultipartAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback * )
91 {
92  QgsFeature f = feature;
93  if ( f.hasGeometry() && !f.geometry().isMultipart() )
94  {
95  QgsGeometry g = f.geometry();
97  f.setGeometry( g );
98  }
99  return QgsFeatureList() << f;
100 }
101 
103 
104 
QgsVectorLayer::wkbType
Q_INVOKABLE QgsWkbTypes::Type wkbType() const FINAL
Returns the WKBType or WKBUnknown in case of error.
Definition: qgsvectorlayer.cpp:725
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
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
QgsProcessingFeatureBasedAlgorithm::supportInPlaceEdit
bool supportInPlaceEdit(const QgsMapLayer *layer) const override
Checks whether this algorithm supports in-place editing on the given layer Default implementation for...
Definition: qgsprocessingalgorithm.cpp:1139
QgsWkbTypes::multiType
static Type multiType(Type type) SIP_HOLDGIL
Returns the multi type for a WKB type.
Definition: qgswkbtypes.h:304
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
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
QgsVectorLayer
Represents a vector layer which manages a vector based data sets.
Definition: qgsvectorlayer.h:391
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:230
QgsMapLayer
Base class for all map layer types. This is the base class for all map layer types (vector,...
Definition: qgsmaplayer.h:72
QgsGeometry::convertToMultiType
bool convertToMultiType()
Converts single type geometry into multitype geometry e.g.
Definition: qgsgeometry.cpp:1571
qgsalgorithmpromotetomultipart.h
QgsFeature
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:55
QgsWkbTypes::isMultiType
static bool isMultiType(Type type) SIP_HOLDGIL
Returns true if the WKB type is a multi type.
Definition: qgswkbtypes.h:862