QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
qgsalgorithmmergelines.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmmergelines.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
22QString QgsMergeLinesAlgorithm::name() const
23{
24 return QStringLiteral( "mergelines" );
25}
26
27QString QgsMergeLinesAlgorithm::displayName() const
28{
29 return QObject::tr( "Merge lines" );
30}
31
32QStringList QgsMergeLinesAlgorithm::tags() const
33{
34 return QObject::tr( "line,merge,join,parts" ).split( ',' );
35}
36
37QString QgsMergeLinesAlgorithm::group() const
38{
39 return QObject::tr( "Vector geometry" );
40}
41
42QString QgsMergeLinesAlgorithm::groupId() const
43{
44 return QStringLiteral( "vectorgeometry" );
45}
46
47QString QgsMergeLinesAlgorithm::outputName() const
48{
49 return QObject::tr( "Merged" );
50}
51
52QgsProcessing::SourceType QgsMergeLinesAlgorithm::outputLayerType() const
53{
55}
56
57QgsWkbTypes::Type QgsMergeLinesAlgorithm::outputWkbType( QgsWkbTypes::Type ) const
58{
60}
61
62QString QgsMergeLinesAlgorithm::shortHelpString() const
63{
64 return QObject::tr( "This algorithm joins all connected parts of MultiLineString geometries into single LineString geometries.\n\n"
65 "If any parts of the input MultiLineString geometries are not connected, the resultant "
66 "geometry will be a MultiLineString containing any lines which could be merged and any non-connected line parts." );
67}
68
69QList<int> QgsMergeLinesAlgorithm::inputLayerTypes() const
70{
71 return QList<int>() << QgsProcessing::TypeVectorLine;
72}
73
74QgsMergeLinesAlgorithm *QgsMergeLinesAlgorithm::createInstance() const
75{
76 return new QgsMergeLinesAlgorithm();
77}
78
79QgsFeatureList QgsMergeLinesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
80{
81 if ( !feature.hasGeometry() )
82 return QgsFeatureList() << feature;
83
84 QgsFeature out = feature;
85 const QgsGeometry outputGeometry = feature.geometry().mergeLines();
86 if ( outputGeometry.isNull() )
87 feedback->reportError( QObject::tr( "Error merging lines for feature %1" ).arg( feature.id() ) );
88
89 out.setGeometry( outputGeometry );
90 return QgsFeatureList() << out;
91}
92
94
95
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition: qgsfeature.h:56
QgsGeometry geometry
Definition: qgsfeature.h:67
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:233
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:170
Q_GADGET QgsFeatureId id
Definition: qgsfeature.h:64
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
Q_GADGET bool isNull
Definition: qgsgeometry.h:166
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
Contains information about the context in which a processing algorithm is executed.
Base class for providing feedback from a processing algorithm.
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
SourceType
Data source types enum.
Definition: qgsprocessing.h:46
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:922