QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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  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 
qgsalgorithmmergelines.h
QgsProcessingFeedback
Base class for providing feedback from a processing algorithm.
Definition: qgsprocessingfeedback.h:37
QgsProcessingFeedback::reportError
virtual void reportError(const QString &error, bool fatalError=false)
Reports that the algorithm encountered an error while executing.
Definition: qgsprocessingfeedback.cpp:59
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:50
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsGeometry::mergeLines
QgsGeometry mergeLines() const
Merges any connected lines in a LineString/MultiLineString geometry and converts them to single line ...
Definition: qgsgeometry.cpp:2657
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsWkbTypes::MultiLineString
@ MultiLineString
Definition: qgswkbtypes.h:77
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
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:127
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
QgsProcessing::SourceType
SourceType
Data source types enum.
Definition: qgsprocessing.h:45