QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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
23
24QString QgsBoundaryAlgorithm::name() const
25{
26 return QStringLiteral( "boundary" );
27}
28
29QString QgsBoundaryAlgorithm::displayName() const
30{
31 return QObject::tr( "Boundary" );
32}
33
34QStringList QgsBoundaryAlgorithm::tags() const
35{
36 return QObject::tr( "boundary,ring,border,exterior" ).split( ',' );
37}
38
39QString QgsBoundaryAlgorithm::group() const
40{
41 return QObject::tr( "Vector geometry" );
42}
43
44QString QgsBoundaryAlgorithm::groupId() const
45{
46 return QStringLiteral( "vectorgeometry" );
47}
48
49QString QgsBoundaryAlgorithm::outputName() const
50{
51 return QObject::tr( "Boundary" );
52}
53
54QString QgsBoundaryAlgorithm::shortHelpString() const
55{
56 return QObject::tr( "This algorithm returns the closure of the combinatorial boundary of the input geometries (ie the "
57 "topological boundary of the geometry). For instance, a polygon geometry will have a "
58 "boundary consisting of the linestrings for each ring in the polygon. Only valid for "
59 "polygon or line layers." );
60}
61
62QString QgsBoundaryAlgorithm::shortDescription() const
63{
64 return QObject::tr( "Returns the topological boundary of the input geometries." );
65}
66
67QList<int> QgsBoundaryAlgorithm::inputLayerTypes() const
68{
69 return QList<int>() << static_cast<int>( Qgis::ProcessingSourceType::VectorLine ) << static_cast<int>( Qgis::ProcessingSourceType::VectorPolygon );
70}
71
72bool QgsBoundaryAlgorithm::supportInPlaceEdit( const QgsMapLayer * ) const
73{
74 return false;
75}
76
77QgsBoundaryAlgorithm *QgsBoundaryAlgorithm::createInstance() const
78{
79 return new QgsBoundaryAlgorithm();
80}
81
82Qgis::ProcessingFeatureSourceFlags QgsBoundaryAlgorithm::sourceFlags() const
83{
85}
86
87Qgis::WkbType QgsBoundaryAlgorithm::outputWkbType( Qgis::WkbType inputWkbType ) const
88{
90 switch ( QgsWkbTypes::geometryType( inputWkbType ) )
91 {
93 outputWkb = Qgis::WkbType::MultiPoint;
94 break;
95
98 break;
99
103 outputWkb = Qgis::WkbType::NoGeometry;
104 break;
105 }
106
107 if ( QgsWkbTypes::hasZ( inputWkbType ) )
108 outputWkb = QgsWkbTypes::addZ( outputWkb );
109 if ( QgsWkbTypes::hasM( inputWkbType ) )
110 outputWkb = QgsWkbTypes::addM( outputWkb );
111
112 return outputWkb;
113}
114
115QgsFeatureList QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
116{
117 QgsFeature outFeature = feature;
118
119 if ( feature.hasGeometry() )
120 {
121 const QgsGeometry inputGeometry = feature.geometry();
122 const QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() );
123 if ( outputGeometry.isNull() )
124 {
125 feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)" ).arg( feature.id() ) );
126 outFeature.clearGeometry();
127 }
128 else
129 {
130 outFeature.setGeometry( outputGeometry );
131 }
132 }
133 return QgsFeatureList() << outFeature;
134}
135
@ VectorPolygon
Vector polygon layers.
Definition qgis.h:3536
@ VectorLine
Vector line layers.
Definition qgis.h:3535
@ Point
Points.
Definition qgis.h:359
@ Line
Lines.
Definition qgis.h:360
@ Polygon
Polygons.
Definition qgis.h:361
@ Unknown
Unknown types.
Definition qgis.h:362
@ Null
No geometry.
Definition qgis.h:363
@ SkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition qgis.h:3711
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:277
@ MultiPoint
MultiPoint.
Definition qgis.h:283
@ NoGeometry
No geometry.
Definition qgis.h:294
@ MultiLineString
MultiLineString.
Definition qgis.h:284
@ Unknown
Unknown.
Definition qgis.h:278
QFlags< ProcessingFeatureSourceFlag > ProcessingFeatureSourceFlags
Flags which control how QgsProcessingFeatureSource fetches features.
Definition qgis.h:3722
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:58
QgsFeatureId id
Definition qgsfeature.h:66
QgsGeometry geometry
Definition qgsfeature.h:69
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:80
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