QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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(
61 "This algorithm returns the closure of the combinatorial boundary of the input geometries (ie the "
62 "topological boundary of the geometry). For instance, a polygon geometry will have a "
63 "boundary consisting of the linestrings for each ring in the polygon. Only valid for "
64 "polygon or line layers."
65 );
66}
67
68QString QgsBoundaryAlgorithm::shortDescription() const
69{
70 return QObject::tr( "Returns the topological boundary of the input geometries." );
71}
72
73QList<int> QgsBoundaryAlgorithm::inputLayerTypes() const
74{
75 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
76}
77
78bool QgsBoundaryAlgorithm::supportInPlaceEdit( const QgsMapLayer * ) const
79{
80 return false;
81}
82
83QgsBoundaryAlgorithm *QgsBoundaryAlgorithm::createInstance() const
84{
85 return new QgsBoundaryAlgorithm();
86}
87
88Qgis::ProcessingFeatureSourceFlags QgsBoundaryAlgorithm::sourceFlags() const
89{
91}
92
93Qgis::WkbType QgsBoundaryAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
94{
96 switch ( QgsWkbTypes::geometryType( inputWkbType ) )
97 {
99 outputWkb = Qgis::WkbType::MultiPoint;
100 break;
101
104 break;
105
109 outputWkb = Qgis::WkbType::NoGeometry;
110 break;
111 }
112
113 if ( QgsWkbTypes::hasZ( inputWkbType ) )
114 outputWkb = QgsWkbTypes::addZ( outputWkb );
115 if ( QgsWkbTypes::hasM( inputWkbType ) )
116 outputWkb = QgsWkbTypes::addM( outputWkb );
117
118 return outputWkb;
119}
120
121QgsFeatureList QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
122{
123 QgsFeature outFeature = feature;
124
125 if ( feature.hasGeometry() )
126 {
127 const QgsGeometry inputGeometry = feature.geometry();
128 const QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() );
129 if ( outputGeometry.isNull() )
130 {
131 feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)" ).arg( feature.id() ) );
132 outFeature.clearGeometry();
133 }
134 else
135 {
136 outFeature.setGeometry( outputGeometry );
137 }
138 }
139 return QgsFeatureList() << outFeature;
140}
141
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3650
@ VectorLine
Vector line layers.
Definition qgis.h:3649
@ Point
Points.
Definition qgis.h:380
@ Line
Lines.
Definition qgis.h:381
@ Polygon
Polygons.
Definition qgis.h:382
@ Unknown
Unknown types.
Definition qgis.h:383
@ Null
No geometry.
Definition qgis.h:384
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3828
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
@ MultiPoint
MultiPoint.
Definition qgis.h:300
@ NoGeometry
No geometry.
Definition qgis.h:312
@ MultiLineString
MultiLineString.
Definition qgis.h:301
@ Unknown
Unknown.
Definition qgis.h:295
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3839
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