QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 
18 #include "qgsalgorithmmergelines.h"
19 
21 
22 QString QgsMergeLinesAlgorithm::name() const
23 {
24  return QStringLiteral( "mergelines" );
25 }
26 
27 QString QgsMergeLinesAlgorithm::displayName() const
28 {
29  return QObject::tr( "Merge lines" );
30 }
31 
32 QStringList QgsMergeLinesAlgorithm::tags() const
33 {
34  return QObject::tr( "line,merge,join,parts" ).split( ',' );
35 }
36 
37 QString QgsMergeLinesAlgorithm::group() const
38 {
39  return QObject::tr( "Vector geometry" );
40 }
41 
42 QString QgsMergeLinesAlgorithm::groupId() const
43 {
44  return QStringLiteral( "vectorgeometry" );
45 }
46 
47 QString QgsMergeLinesAlgorithm::outputName() const
48 {
49  return QObject::tr( "Merged" );
50 }
51 
52 QgsProcessing::SourceType QgsMergeLinesAlgorithm::outputLayerType() const
53 {
55 }
56 
57 QgsWkbTypes::Type QgsMergeLinesAlgorithm::outputWkbType( QgsWkbTypes::Type ) const
58 {
60 }
61 
62 QString 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 
69 QList<int> QgsMergeLinesAlgorithm::inputLayerTypes() const
70 {
71  return QList<int>() << QgsProcessing::TypeVectorLine;
72 }
73 
74 QgsMergeLinesAlgorithm *QgsMergeLinesAlgorithm::createInstance() const
75 {
76  return new QgsMergeLinesAlgorithm();
77 }
78 
79 QgsFeatureList QgsMergeLinesAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
80 {
81  if ( !feature.hasGeometry() )
82  return QgsFeatureList() << feature;
83 
84  QgsFeature out = feature;
85  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:205
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:145
Q_GADGET QgsFeatureId id
Definition: qgsfeature.h:64
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
Q_GADGET bool isNull
Definition: qgsgeometry.h:126
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:736