QGIS API Documentation 3.99.0-Master (09f76ad7019)
Loading...
Searching...
No Matches
qgsalgorithmboundary.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsalgorithmboundary.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
20#include "qgsvectorlayer.h"
21
22#include <QString>
23
24using namespace Qt::StringLiterals;
25
27
28QString QgsBoundaryAlgorithm::name() const
29{
30 return u"boundary"_s;
31}
32
33QString QgsBoundaryAlgorithm::displayName() const
34{
35 return QObject::tr( "Boundary" );
36}
37
38QStringList QgsBoundaryAlgorithm::tags() const
39{
40 return QObject::tr( "boundary,ring,border,exterior" ).split( ',' );
41}
42
43QString QgsBoundaryAlgorithm::group() const
44{
45 return QObject::tr( "Vector geometry" );
46}
47
48QString QgsBoundaryAlgorithm::groupId() const
49{
50 return u"vectorgeometry"_s;
51}
52
53QString QgsBoundaryAlgorithm::outputName() const
54{
55 return QObject::tr( "Boundary" );
56}
57
58QString QgsBoundaryAlgorithm::shortHelpString() const
59{
60 return QObject::tr( "This algorithm returns the closure of the combinatorial boundary of the input geometries (ie the "
61 "topological boundary of the geometry). For instance, a polygon geometry will have a "
62 "boundary consisting of the linestrings for each ring in the polygon. Only valid for "
63 "polygon or line layers." );
64}
65
66QString QgsBoundaryAlgorithm::shortDescription() const
67{
68 return QObject::tr( "Returns the topological boundary of the input geometries." );
69}
70
71QList<int> QgsBoundaryAlgorithm::inputLayerTypes() const
72{
73 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
74}
75
76bool QgsBoundaryAlgorithm::supportInPlaceEdit( const QgsMapLayer * ) const
77{
78 return false;
79}
80
81QgsBoundaryAlgorithm *QgsBoundaryAlgorithm::createInstance() const
82{
83 return new QgsBoundaryAlgorithm();
84}
85
86Qgis::ProcessingFeatureSourceFlags QgsBoundaryAlgorithm::sourceFlags() const
87{
89}
90
91Qgis::WkbType QgsBoundaryAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
92{
94 switch ( QgsWkbTypes::geometryType( inputWkbType ) )
95 {
97 outputWkb = Qgis::WkbType::MultiPoint;
98 break;
99
102 break;
103
107 outputWkb = Qgis::WkbType::NoGeometry;
108 break;
109 }
110
111 if ( QgsWkbTypes::hasZ( inputWkbType ) )
112 outputWkb = QgsWkbTypes::addZ( outputWkb );
113 if ( QgsWkbTypes::hasM( inputWkbType ) )
114 outputWkb = QgsWkbTypes::addM( outputWkb );
115
116 return outputWkb;
117}
118
119QgsFeatureList QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
120{
121 QgsFeature outFeature = feature;
122
123 if ( feature.hasGeometry() )
124 {
125 const QgsGeometry inputGeometry = feature.geometry();
126 const QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() );
127 if ( outputGeometry.isNull() )
128 {
129 feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)" ).arg( feature.id() ) );
130 outFeature.clearGeometry();
131 }
132 else
133 {
134 outFeature.setGeometry( outputGeometry );
135 }
136 }
137 return QgsFeatureList() << outFeature;
138}
139
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3607
@ VectorLine
Vector line layers.
Definition qgis.h:3606
@ Point
Points.
Definition qgis.h:366
@ Line
Lines.
Definition qgis.h:367
@ Polygon
Polygons.
Definition qgis.h:368
@ Unknown
Unknown types.
Definition qgis.h:369
@ Null
No geometry.
Definition qgis.h:370
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3782
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ MultiPoint
MultiPoint.
Definition qgis.h:286
@ NoGeometry
No geometry.
Definition qgis.h:298
@ MultiLineString
MultiLineString.
Definition qgis.h:287
@ Unknown
Unknown.
Definition qgis.h:281
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3793
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFeatureId id
Definition qgsfeature.h:68
QgsGeometry geometry
Definition qgsfeature.h:71
void clearGeometry()
Removes any geometry associated with the feature.
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.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Base class for all map layer types.
Definition qgsmaplayer.h:83
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.
static Qgis::GeometryType geometryType(Qgis::WkbType type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
static Qgis::WkbType addM(Qgis::WkbType type)
Adds the m dimension to a WKB type and returns the new type.
static Qgis::WkbType addZ(Qgis::WkbType type)
Adds the z dimension to a WKB type and returns the new type.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
QList< QgsFeature > QgsFeatureList