QGIS API Documentation 3.41.0-Master (3440c17df1d)
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:
42
51 class ANALYSIS_EXPORT LayerFeature
52 {
53 public:
54
61 LayerFeature( const QgsFeaturePool *pool, const QgsFeature &feature, const QgsGeometryCheckContext *context, bool useMapCrs );
62
67 QgsFeature feature() const;
68
73
77 QPointer<QgsVectorLayer> layer() const SIP_SKIP;
78
82 QString layerId() const;
83
89 QgsGeometry geometry() const;
90
94 QString id() const;
95 bool operator==( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
96 bool operator!=( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
97
101 bool useMapCrs() const;
102
103 private:
104 const QgsFeaturePool *mFeaturePool;
105 QgsFeature mFeature;
106 QgsGeometry mGeometry;
107 bool mMapCrs;
108 };
109
117 class ANALYSIS_EXPORT LayerFeatures
118 {
119 public:
120#ifndef SIP_RUN
121
125 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools,
126 const QMap<QString, QgsFeatureIds> &featureIds,
127 const QList<Qgis::GeometryType> &geometryTypes,
128 QgsFeedback *feedback,
129 const QgsGeometryCheckContext *context,
130 bool useMapCrs = false );
131
135 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools,
136 const QList<QString> &layerIds, const QgsRectangle &extent,
137 const QList<Qgis::GeometryType> &geometryTypes,
138 const QgsGeometryCheckContext *context );
139
148 {
149 public:
150
154 iterator( const QStringList::const_iterator &layerIt, const LayerFeatures *parent );
155
156 iterator( const iterator &rh );
157 ~iterator();
158
163 const iterator &operator++();
164
169 iterator operator++( int n );
170
175 bool operator!=( const iterator &other ) const;
176
177 private:
178 bool nextLayerFeature( bool begin );
179 bool nextLayer( bool begin );
180 bool nextFeature( bool begin );
181 QList<QString>::const_iterator mLayerIt;
182 QgsFeatureIds::const_iterator mFeatureIt;
183 const LayerFeatures *mParent = nullptr;
184 std::unique_ptr<QgsGeometryCheckerUtils::LayerFeature> mCurrentFeature;
185
186 iterator &operator= ( const iterator & ) = delete;
187 };
188
192 iterator begin() const;
193
197 iterator end() const;
198
199#endif
200
201 private:
202#ifdef SIP_RUN
204#endif
205 QMap<QString, QgsFeaturePool *> mFeaturePools;
206 QMap<QString, QgsFeatureIds> mFeatureIds;
207 QList<QString> mLayerIds;
208 QgsRectangle mExtent;
209 QList<Qgis::GeometryType> mGeometryTypes;
210 QgsFeedback *mFeedback = nullptr;
211 const QgsGeometryCheckContext *mContext = nullptr;
212 bool mUseMapCrs = true;
213 };
214
215#ifndef SIP_RUN
216
217 static QgsAbstractGeometry *getGeomPart( QgsAbstractGeometry *geom, int partIdx );
218 static const QgsAbstractGeometry *getGeomPart( const QgsAbstractGeometry *geom, int partIdx );
219
220 static QList <const QgsLineString *> polygonRings( const QgsPolygon *polygon );
221
222 static void filter1DTypes( QgsAbstractGeometry *geom );
223
228 static inline int polyLineSize( const QgsAbstractGeometry *geom, int iPart, int iRing, bool *isClosed = nullptr )
229 {
230 if ( !geom->isEmpty() )
231 {
232 const int nVerts = geom->vertexCount( iPart, iRing );
233 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
234 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
235 const bool closed = back == front;
236 if ( isClosed )
237 *isClosed = closed;
238 return closed ? nVerts - 1 : nVerts;
239 }
240 else
241 {
242 if ( isClosed )
243 *isClosed = true;
244 return 0;
245 }
246 }
247
248 static bool pointOnLine( const QgsPoint &p, const QgsLineString *line, double tol, bool excludeExtremities = false );
249
250 static QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol );
251
252 static double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol );
253
254 static inline bool canDeleteVertex( const QgsAbstractGeometry *geom, int iPart, int iRing )
255 {
256 const int nVerts = geom->vertexCount( iPart, iRing );
257 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
258 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
259 const bool closed = back == front;
260 return closed ? nVerts > 4 : nVerts > 2;
261 }
262
263#endif
264
265}; // QgsGeometryCheckerUtils
266
267#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