QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
18 #include "qgsalgorithmboundary.h"
19 #include "qgsvectorlayer.h"
20 
22 
23 QString QgsBoundaryAlgorithm::name() const
24 {
25  return QStringLiteral( "boundary" );
26 }
27 
28 QString QgsBoundaryAlgorithm::displayName() const
29 {
30  return QObject::tr( "Boundary" );
31 }
32 
33 QStringList QgsBoundaryAlgorithm::tags() const
34 {
35  return QObject::tr( "boundary,ring,border,exterior" ).split( ',' );
36 }
37 
38 QString QgsBoundaryAlgorithm::group() const
39 {
40  return QObject::tr( "Vector geometry" );
41 }
42 
43 QString QgsBoundaryAlgorithm::groupId() const
44 {
45  return QStringLiteral( "vectorgeometry" );
46 }
47 
48 QString QgsBoundaryAlgorithm::outputName() const
49 {
50  return QObject::tr( "Boundary" );
51 }
52 
53 QString QgsBoundaryAlgorithm::shortHelpString() const
54 {
55  return QObject::tr( "Returns the closure of the combinatorial boundary of the input geometries (ie the "
56  "topological boundary of the geometry). For instance, a polygon geometry will have a "
57  "boundary consisting of the linestrings for each ring in the polygon. Only valid for "
58  "polygon or line layers." );
59 }
60 
61 QList<int> QgsBoundaryAlgorithm::inputLayerTypes() const
62 {
64 }
65 
66 bool QgsBoundaryAlgorithm::supportInPlaceEdit( const QgsMapLayer * ) const
67 {
68  return false;
69 }
70 
71 QgsBoundaryAlgorithm *QgsBoundaryAlgorithm::createInstance() const
72 {
73  return new QgsBoundaryAlgorithm();
74 }
75 
76 QgsProcessingFeatureSource::Flag QgsBoundaryAlgorithm::sourceFlags() const
77 {
79 }
80 
81 QgsWkbTypes::Type QgsBoundaryAlgorithm::outputWkbType( QgsWkbTypes::Type inputWkbType ) const
82 {
84  switch ( QgsWkbTypes::geometryType( inputWkbType ) )
85  {
87  outputWkb = QgsWkbTypes::MultiPoint;
88  break;
89 
91  outputWkb = QgsWkbTypes::MultiLineString;
92  break;
93 
97  outputWkb = QgsWkbTypes::NoGeometry;
98  break;
99  }
100 
101  if ( QgsWkbTypes::hasZ( inputWkbType ) )
102  outputWkb = QgsWkbTypes::addZ( outputWkb );
103  if ( QgsWkbTypes::hasM( inputWkbType ) )
104  outputWkb = QgsWkbTypes::addM( outputWkb );
105 
106  return outputWkb;
107 }
108 
109 QgsFeatureList QgsBoundaryAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &, QgsProcessingFeedback *feedback )
110 {
111  QgsFeature outFeature = feature;
112 
113  if ( feature.hasGeometry() )
114  {
115  QgsGeometry inputGeometry = feature.geometry();
116  QgsGeometry outputGeometry = QgsGeometry( inputGeometry.constGet()->boundary() );
117  if ( outputGeometry.isNull() )
118  {
119  feedback->reportError( QObject::tr( "No boundary for feature %1 (possibly a closed linestring?)'" ).arg( feature.id() ) );
120  outFeature.clearGeometry();
121  }
122  else
123  {
124  outFeature.setGeometry( outputGeometry );
125  }
126  }
127  return QgsFeatureList() << outFeature;
128 }
129 
QgsWkbTypes::NullGeometry
@ NullGeometry
Definition: qgswkbtypes.h:145
QgsProcessingFeedback
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:39
QgsProcessing::TypeVectorPolygon
@ TypeVectorPolygon
Vector polygon layers.
Definition: qgsprocessing.h:50
QgsFeature::geometry
QgsGeometry geometry
Definition: qgsfeature.h:71
QgsProcessing::TypeVectorLine
@ TypeVectorLine
Vector line layers.
Definition: qgsprocessing.h:49
QgsProcessingFeatureSource::FlagSkipGeometryValidityChecks
@ FlagSkipGeometryValidityChecks
Invalid geometry checks should always be skipped. This flag can be useful for algorithms which always...
Definition: qgsprocessingutils.h:475
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsWkbTypes::hasZ
static bool hasZ(Type type)
Tests whether a WKB type contains the z-dimension.
Definition: qgswkbtypes.h:1042
QgsWkbTypes::addM
static Type addM(Type type)
Adds the m dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:1163
QgsWkbTypes::PolygonGeometry
@ PolygonGeometry
Definition: qgswkbtypes.h:143
QgsFeature::clearGeometry
void clearGeometry()
Removes any geometry associated with the feature.
Definition: qgsfeature.cpp:151
QgsFeature::id
QgsFeatureId id
Definition: qgsfeature.h:68
QgsWkbTypes::MultiLineString
@ MultiLineString
Definition: qgswkbtypes.h:76
QgsWkbTypes::Unknown
@ Unknown
Definition: qgswkbtypes.h:70
QgsFeature::setGeometry
void setGeometry(const QgsGeometry &geometry)
Set the feature's geometry.
Definition: qgsfeature.cpp:137
QgsProcessingContext
Definition: qgsprocessingcontext.h:43
QgsFeatureList
QList< QgsFeature > QgsFeatureList
Definition: qgsfeature.h:572
QgsWkbTypes::geometryType
static GeometryType geometryType(Type type)
Returns the geometry type for a WKB type, e.g., both MultiPolygon and CurvePolygon would have a Polyg...
Definition: qgswkbtypes.h:937
QgsGeometry::isNull
bool isNull
Definition: qgsgeometry.h:125
QgsGeometry::constGet
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Definition: qgsgeometry.cpp:128
QgsWkbTypes::addZ
static Type addZ(Type type)
Adds the z dimension to a WKB type and returns the new type.
Definition: qgswkbtypes.h:1138
qgsvectorlayer.h
QgsWkbTypes::hasM
static bool hasM(Type type)
Tests whether a WKB type contains m values.
Definition: qgswkbtypes.h:1092
QgsWkbTypes::LineGeometry
@ LineGeometry
Definition: qgswkbtypes.h:142
QgsWkbTypes::PointGeometry
@ PointGeometry
Definition: qgswkbtypes.h:141
QgsProcessingFeatureSource::Flag
Flag
Flags controlling how QgsProcessingFeatureSource fetches features.
Definition: qgsprocessingutils.h:473
QgsWkbTypes::NoGeometry
@ NoGeometry
Definition: qgswkbtypes.h:84
QgsGeometry
Definition: qgsgeometry.h:122
QgsFeature::hasGeometry
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Definition: qgsfeature.cpp:197
QgsMapLayer
Definition: qgsmaplayer.h:81
QgsWkbTypes::MultiPoint
@ MultiPoint
Definition: qgswkbtypes.h:75
qgsalgorithmboundary.h
QgsWkbTypes::UnknownGeometry
@ UnknownGeometry
Definition: qgswkbtypes.h:144
QgsAbstractGeometry::boundary
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
QgsFeature
Definition: qgsfeature.h:55