QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 
QgsFeatureId id
Definition: qgsfeature.h:64
Base class for providing feedback from a processing algorithm.
bool isNull() const
Returns true if the geometry is null (ie, contains no underlying geometry accessible via geometry() )...
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:571
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:106
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Definition: qgsfeature.h:55
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
Vector line layers.
Definition: qgsprocessing.h:49
void setGeometry(const QgsGeometry &geometry)
Set the feature&#39;s geometry.
Definition: qgsfeature.cpp:137
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
SourceType
Data source types enum.
Definition: qgsprocessing.h:44
QgsGeometry geometry
Definition: qgsfeature.h:67
Contains information about the context in which a processing algorithm is executed.
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.