QGIS API Documentation 3.38.0-Grenoble (exported)
Loading...
Searching...
No Matches
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
52Qgis::ProcessingSourceType QgsMergeLinesAlgorithm::outputLayerType() const
53{
55}
56
57Qgis::WkbType QgsMergeLinesAlgorithm::outputWkbType( Qgis::WkbType ) 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>() << static_cast< int >( Qgis::ProcessingSourceType::VectorLine );
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
ProcessingSourceType
Processing data source types.
Definition qgis.h:2995
@ VectorLine
Vector line layers.
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
@ MultiLineString
MultiLineString.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
QgsFeatureId id
Definition qgsfeature.h:66
QgsGeometry geometry
Definition qgsfeature.h:69
bool hasGeometry() const
Returns true if the feature has an associated geometry.
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
A geometry is the spatial representation of a feature.
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.
QList< QgsFeature > QgsFeatureList