QGIS API Documentation 3.41.0-Master (cea29feecf2)
Loading...
Searching...
No Matches
qgsgeometrycheckerutils.h
Go to the documentation of this file.
1/***************************************************************************
2 * qgsgeometrycheckerutils.h *
3 * ------------------- *
4 * copyright : (C) 2014 by Sandro Mani / Sourcepole AG *
5 * email : [email protected] *
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 ***************************************************************************/
16
17#ifndef QGS_GEOMETRYCHECKERUTILS_H
18#define QGS_GEOMETRYCHECKERUTILS_H
19
20#include "qgis_analysis.h"
21#include "qgsfeature.h"
22#include "qgsabstractgeometry.h"
23#include "qgspoint.h"
25#include <qmath.h>
26
28class QgsFeaturePool;
29class QgsFeedback;
30
39class ANALYSIS_EXPORT QgsGeometryCheckerUtils
40{
41 public:
50 class ANALYSIS_EXPORT LayerFeature
51 {
52 public:
59 LayerFeature( const QgsFeaturePool *pool, const QgsFeature &feature, const QgsGeometryCheckContext *context, bool useMapCrs );
60
65 QgsFeature feature() const;
66
71
75 QPointer<QgsVectorLayer> layer() const SIP_SKIP;
76
80 QString layerId() const;
81
87 QgsGeometry geometry() const;
88
92 QString id() const;
93 bool operator==( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
94 bool operator!=( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
95
99 bool useMapCrs() const;
100
101 private:
102 const QgsFeaturePool *mFeaturePool;
103 QgsFeature mFeature;
104 QgsGeometry mGeometry;
105 bool mMapCrs;
106 };
107
115 class ANALYSIS_EXPORT LayerFeatures
116 {
117 public:
118#ifndef SIP_RUN
119
123 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QgsFeatureIds> &featureIds, const QList<Qgis::GeometryType> &geometryTypes, QgsFeedback *feedback, const QgsGeometryCheckContext *context, bool useMapCrs = false );
124
128 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools, const QList<QString> &layerIds, const QgsRectangle &extent, const QList<Qgis::GeometryType> &geometryTypes, const QgsGeometryCheckContext *context );
129
138 {
139 public:
143 iterator( const QStringList::const_iterator &layerIt, const LayerFeatures *parent );
144
145 iterator( const iterator &rh );
146 ~iterator();
147
152 const iterator &operator++();
153
158 iterator operator++( int n );
159
164 bool operator!=( const iterator &other ) const;
165
166 private:
167 bool nextLayerFeature( bool begin );
168 bool nextLayer( bool begin );
169 bool nextFeature( bool begin );
170 QList<QString>::const_iterator mLayerIt;
171 QgsFeatureIds::const_iterator mFeatureIt;
172 const LayerFeatures *mParent = nullptr;
173 std::unique_ptr<QgsGeometryCheckerUtils::LayerFeature> mCurrentFeature;
174
175 iterator &operator=( const iterator & ) = delete;
176 };
177
181 iterator begin() const;
182
186 iterator end() const;
187
188#endif
189
190 private:
191#ifdef SIP_RUN
193#endif
194 QMap<QString, QgsFeaturePool *> mFeaturePools;
195 QMap<QString, QgsFeatureIds> mFeatureIds;
196 QList<QString> mLayerIds;
197 QgsRectangle mExtent;
198 QList<Qgis::GeometryType> mGeometryTypes;
199 QgsFeedback *mFeedback = nullptr;
200 const QgsGeometryCheckContext *mContext = nullptr;
201 bool mUseMapCrs = true;
202 };
203
204#ifndef SIP_RUN
205
206 static QgsAbstractGeometry *getGeomPart( QgsAbstractGeometry *geom, int partIdx );
207 static const QgsAbstractGeometry *getGeomPart( const QgsAbstractGeometry *geom, int partIdx );
208
209 static QList<const QgsLineString *> polygonRings( const QgsPolygon *polygon );
210
211 static void filter1DTypes( QgsAbstractGeometry *geom );
212
217 static inline int polyLineSize( const QgsAbstractGeometry *geom, int iPart, int iRing, bool *isClosed = nullptr )
218 {
219 if ( !geom->isEmpty() )
220 {
221 const int nVerts = geom->vertexCount( iPart, iRing );
222 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
223 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
224 const bool closed = back == front;
225 if ( isClosed )
226 *isClosed = closed;
227 return closed ? nVerts - 1 : nVerts;
228 }
229 else
230 {
231 if ( isClosed )
232 *isClosed = true;
233 return 0;
234 }
235 }
236
237 static bool pointOnLine( const QgsPoint &p, const QgsLineString *line, double tol, bool excludeExtremities = false );
238
239 static QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol );
240
241 static double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol );
242
243 static inline bool canDeleteVertex( const QgsAbstractGeometry *geom, int iPart, int iRing )
244 {
245 const int nVerts = geom->vertexCount( iPart, iRing );
246 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
247 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
248 const bool closed = back == front;
249 return closed ? nVerts > 4 : nVerts > 2;
250 }
251
252#endif
253
254}; // QgsGeometryCheckerUtils
255
256#endif // QGS_GEOMETRYCHECKERUTILS_H
Abstract base class for all geometries.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
virtual bool isEmpty() const
Returns true if the geometry is empty.
This class represents a coordinate reference system (CRS).
A feature pool is based on a vector layer and caches features.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:58
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Base configuration for geometry checks.
A layer feature combination to uniquely identify and access a feature in a set of layers.
An iterator over all features in a QgsGeometryCheckerUtils::LayerFeatures.
Contains a set of layers and feature ids in those layers to pass to a geometry check.
Contains utilities required for geometry checks.
static bool canDeleteVertex(const QgsAbstractGeometry *geom, int iPart, int iRing)
static int polyLineSize(const QgsAbstractGeometry *geom, int iPart, int iRing, bool *isClosed=nullptr)
Returns the number of points in a polyline, accounting for duplicate start and end point if the polyl...
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
A geometry is the spatial representation of a feature.
Line string geometry type, with support for z-dimension and m-values.
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:49
Polygon geometry type.
Definition qgspolygon.h:33
A rectangle specified with double values.
#define SIP_SKIP
Definition qgis_sip.h:126
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
QgsMargins operator*(const QgsMargins &margins, double factor)
Returns a QgsMargins object that is formed by multiplying each component of the given margins by fact...
Definition qgsmargins.h:249
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30