QGIS API Documentation 3.99.0-Master (2fe06baccd8)
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 "qgsabstractgeometry.h"
22#include "qgsfeature.h"
24#include "qgspoint.h"
25
26#include <qmath.h>
27
29class QgsFeaturePool;
30class QgsFeedback;
31
40class ANALYSIS_EXPORT QgsGeometryCheckerUtils
41{
42 public:
51 class ANALYSIS_EXPORT LayerFeature
52 {
53 public:
60 LayerFeature( const QgsFeaturePool *pool, const QgsFeature &feature, const QgsGeometryCheckContext *context, bool useMapCrs );
61
66 QgsFeature feature() const;
67
72
76 QPointer<QgsVectorLayer> layer() const SIP_SKIP;
77
81 QString layerId() const;
82
88 QgsGeometry geometry() const;
89
93 QString id() const;
94 bool operator==( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
95 bool operator!=( const QgsGeometryCheckerUtils::LayerFeature &other ) const;
96
100 bool useMapCrs() const;
101
102 private:
103 const QgsFeaturePool *mFeaturePool;
104 QgsFeature mFeature;
105 QgsGeometry mGeometry;
106 bool mMapCrs;
107 };
108
116 class ANALYSIS_EXPORT LayerFeatures
117 {
118 public:
119#ifndef SIP_RUN
120
124 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools, const QMap<QString, QgsFeatureIds> &featureIds, const QList<Qgis::GeometryType> &geometryTypes, QgsFeedback *feedback, const QgsGeometryCheckContext *context, bool useMapCrs = false );
125
129 LayerFeatures( const QMap<QString, QgsFeaturePool *> &featurePools, const QList<QString> &layerIds, const QgsRectangle &extent, const QList<Qgis::GeometryType> &geometryTypes, const QgsGeometryCheckContext *context );
130
139 {
140 public:
144 iterator( const QStringList::const_iterator &layerIt, const LayerFeatures *parent );
145
146 iterator( const iterator &rh );
147 ~iterator();
148
153 const iterator &operator++();
154
159 iterator operator++( int n );
160
165 bool operator!=( const iterator &other ) const;
166
167 private:
168 bool nextLayerFeature( bool begin );
169 bool nextLayer( bool begin );
170 bool nextFeature( bool begin );
171 QList<QString>::const_iterator mLayerIt;
172 QgsFeatureIds::const_iterator mFeatureIt;
173 const LayerFeatures *mParent = nullptr;
174 std::unique_ptr<QgsGeometryCheckerUtils::LayerFeature> mCurrentFeature;
175
176 iterator &operator=( const iterator & ) = delete;
177 };
178
182 iterator begin() const;
183
187 iterator end() const;
188
189#endif
190
191 private:
192#ifdef SIP_RUN
194#endif
195 QMap<QString, QgsFeaturePool *> mFeaturePools;
196 QMap<QString, QgsFeatureIds> mFeatureIds;
197 QList<QString> mLayerIds;
198 QgsRectangle mExtent;
199 QList<Qgis::GeometryType> mGeometryTypes;
200 QgsFeedback *mFeedback = nullptr;
201 const QgsGeometryCheckContext *mContext = nullptr;
202 bool mUseMapCrs = true;
203 };
204
205#ifndef SIP_RUN
206
207 static QgsAbstractGeometry *getGeomPart( QgsAbstractGeometry *geom, int partIdx );
208 static const QgsAbstractGeometry *getGeomPart( const QgsAbstractGeometry *geom, int partIdx );
209
210 static QList<const QgsLineString *> polygonRings( const QgsPolygon *polygon );
211
212 static void filter1DTypes( QgsAbstractGeometry *geom );
213
218 static inline int polyLineSize( const QgsAbstractGeometry *geom, int iPart, int iRing, bool *isClosed = nullptr )
219 {
220 if ( !geom->isEmpty() )
221 {
222 const int nVerts = geom->vertexCount( iPart, iRing );
223 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
224 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
225 const bool closed = back == front;
226 if ( isClosed )
227 *isClosed = closed;
228 return closed ? nVerts - 1 : nVerts;
229 }
230 else
231 {
232 if ( isClosed )
233 *isClosed = true;
234 return 0;
235 }
236 }
237
238 static bool pointOnLine( const QgsPoint &p, const QgsLineString *line, double tol, bool excludeExtremities = false );
239
240 static QList<QgsPoint> lineIntersections( const QgsLineString *line1, const QgsLineString *line2, double tol );
241
242 static double sharedEdgeLength( const QgsAbstractGeometry *geom1, const QgsAbstractGeometry *geom2, double tol );
243
244 static inline bool canDeleteVertex( const QgsAbstractGeometry *geom, int iPart, int iRing )
245 {
246 const int nVerts = geom->vertexCount( iPart, iRing );
247 const QgsPoint front = geom->vertexAt( QgsVertexId( iPart, iRing, 0 ) );
248 const QgsPoint back = geom->vertexAt( QgsVertexId( iPart, iRing, nVerts - 1 ) );
249 const bool closed = back == front;
250 return closed ? nVerts > 4 : nVerts > 2;
251 }
252
253#endif
254
255}; // QgsGeometryCheckerUtils
256
257#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.
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.
LayerFeature(const QgsFeaturePool *pool, const QgsFeature &feature, const QgsGeometryCheckContext *context, bool useMapCrs)
Create a new layer/feature combination.
QgsGeometry geometry() const
Returns the geometry of this feature.
QString id() const
Returns a combination of the layerId and the feature id.
QgsFeature feature() const
Returns the feature.
QPointer< QgsVectorLayer > layer() const
The layer.
bool useMapCrs() const
Returns if the geometry is reprojected to the map CRS or not.
QgsCoordinateReferenceSystem layerCrs() const
The layer CRS.
An iterator over all features in a QgsGeometryCheckerUtils::LayerFeatures.
const iterator & operator++()
Increments the item the iterator currently points to by one and returns the new iterator.
iterator(const QStringList::const_iterator &layerIt, const LayerFeatures *parent)
Creates a new iterator.
iterator end() const
One after the last feature to stop iterating.
LayerFeatures(const QMap< QString, QgsFeaturePool * > &featurePools, const QMap< QString, QgsFeatureIds > &featureIds, const QList< Qgis::GeometryType > &geometryTypes, QgsFeedback *feedback, const QgsGeometryCheckContext *context, bool useMapCrs=false)
Creates a new set of layer and features.
iterator begin() const
The first feature to start iterating.
Contains utilities required for geometry checks.
static void filter1DTypes(QgsAbstractGeometry *geom)
static QList< const QgsLineString * > polygonRings(const QgsPolygon *polygon)
static bool canDeleteVertex(const QgsAbstractGeometry *geom, int iPart, int iRing)
static QgsAbstractGeometry * getGeomPart(QgsAbstractGeometry *geom, int partIdx)
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:134
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:250
Utility class for identifying a unique vertex within a geometry.
Definition qgsvertexid.h:30