QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsgeometryengine.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsgeometryengine.h
3  -------------------------------------------------------------------
4 Date : 22 Sept 2014
5 Copyright : (C) 2014 by Marco Hugentobler
6 email : marco.hugentobler at sourcepole dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSGEOMETRYENGINE_H
17 #define QGSGEOMETRYENGINE_H
18 
19 #include "qgis_core.h"
20 #include "qgslinestring.h"
21 #include "qgsgeometry.h"
22 #include "qgslogger.h"
23 
24 #include <QVector>
25 
27 
34 class CORE_EXPORT QgsGeometryEngine
35 {
36  public:
37 
43  {
44  Success = 0,
45  NothingHappened = 1000,
51  /* split */
53  };
54 
55  virtual ~QgsGeometryEngine() = default;
56 
61  virtual void geometryChanged() = 0;
62 
72  virtual void prepareGeometry() = 0;
73 
79  virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
80 
86  virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
87 
93  virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
94 
100  virtual QgsAbstractGeometry *combine( const QVector<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const = 0 SIP_FACTORY;
101 
107  virtual QgsAbstractGeometry *combine( const QVector< QgsGeometry > &geometries, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
108 
114  virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
115  virtual QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
116  virtual QgsAbstractGeometry *buffer( double distance, int segments, int endCapStyle, int joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
117  virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
118  virtual QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
119  virtual QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
120 
127  virtual QgsPoint *centroid( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
128 
135  virtual QgsPoint *pointOnSurface( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
136 
140  virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
141 
147  virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
148 
154  virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
155 
161  virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
162 
168  virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
169 
175  virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
176 
182  virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
183 
189  virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
190 
196  virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
197 
206  virtual QString relate( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
207 
217  virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = nullptr ) const = 0;
218 
219  virtual double area( QString *errorMsg = nullptr ) const = 0;
220  virtual double length( QString *errorMsg = nullptr ) const = 0;
221 
233  virtual bool isValid( QString *errorMsg = nullptr, bool allowSelfTouchingHoles = false, QgsGeometry *errorLoc = nullptr ) const = 0;
234 
241  virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
242  virtual bool isEmpty( QString *errorMsg ) const = 0;
243 
248  virtual bool isSimple( QString *errorMsg = nullptr ) const = 0;
249 
262  QVector<QgsGeometry > &newGeometries SIP_OUT,
263  bool topological,
264  QgsPointSequence &topologyTestPoints, QString *errorMsg = nullptr, bool skipIntersectionCheck = false ) const
265  {
266  Q_UNUSED( splitLine )
267  Q_UNUSED( newGeometries )
268  Q_UNUSED( topological )
269  Q_UNUSED( topologyTestPoints )
270  Q_UNUSED( errorMsg )
271  Q_UNUSED( skipIntersectionCheck )
272  return MethodNotImplemented;
273  }
274 
275  virtual QgsAbstractGeometry *offsetCurve( double distance, int segments, int joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
276 
285  void setLogErrors( bool enabled ) { mLogErrors = enabled; }
286 
287  protected:
288  const QgsAbstractGeometry *mGeometry = nullptr;
289  bool mLogErrors = true;
290 
298  void logError( const QString &engineName, const QString &message ) const
299  {
300  if ( mLogErrors )
301  {
302  QgsDebugMsg( QStringLiteral( "%1 notice: %2" ).arg( engineName, message ) );
303  qWarning( "%s exception: %s", engineName.toLocal8Bit().constData(), message.toLocal8Bit().constData() );
304  }
305  }
306 
308  : mGeometry( geometry )
309  {}
310 };
311 
312 #endif // QGSGEOMETRYENGINE_H
313 
QgsGeometryEngine::isValid
virtual bool isValid(QString *errorMsg=nullptr, bool allowSelfTouchingHoles=false, QgsGeometry *errorLoc=nullptr) const =0
Returns true if the geometry is valid.
QgsGeometryEngine::InvalidInput
@ InvalidInput
The input is not valid.
Definition: qgsgeometryengine.h:50
QgsGeometryEngine::touches
virtual bool touches(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom touches this.
qgslinestring.h
QgsGeometryEngine::interpolate
virtual QgsAbstractGeometry * interpolate(double distance, QString *errorMsg=nullptr) const =0
QgsGeometryEngine::setLogErrors
void setLogErrors(bool enabled)
Sets whether warnings and errors encountered during the geometry operations should be logged.
Definition: qgsgeometryengine.h:285
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:38
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsGeometryEngine::relatePattern
virtual bool relatePattern(const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg=nullptr) const =0
Tests whether two geometries are related by a specified Dimensional Extended 9 Intersection Model (DE...
QgsGeometryEngine::EngineError
@ EngineError
Error occurred in the geometry engine.
Definition: qgsgeometryengine.h:47
QgsGeometryEngine::convexHull
virtual QgsAbstractGeometry * convexHull(QString *errorMsg=nullptr) const =0
Calculate the convex hull of this.
QgsGeometryEngine::MethodNotImplemented
@ MethodNotImplemented
Method not implemented in geometry engine.
Definition: qgsgeometryengine.h:46
QgsGeometryEngine::length
virtual double length(QString *errorMsg=nullptr) const =0
QgsGeometryEngine::intersection
virtual QgsAbstractGeometry * intersection(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Calculate the intersection of this and geom.
QgsGeometryEngine::relate
virtual QString relate(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Returns the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the relationship bet...
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
QgsGeometryEngine::buffer
virtual QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr) const =0
QgsGeometryEngine::crosses
virtual bool crosses(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom crosses this.
QgsGeometryEngine::disjoint
virtual bool disjoint(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom is disjoint from this.
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsGeometryEngine::pointOnSurface
virtual QgsPoint * pointOnSurface(QString *errorMsg=nullptr) const =0
Calculate a point that is guaranteed to be on the surface of this.
QgsGeometryEngine::isEmpty
virtual bool isEmpty(QString *errorMsg) const =0
QgsGeometryEngine::geometryChanged
virtual void geometryChanged()=0
Should be called whenever the geometry associated with the engine has been modified and the engine mu...
QgsGeometryEngine::NodedGeometryError
@ NodedGeometryError
Error occurred while creating a noded geometry.
Definition: qgsgeometryengine.h:48
QgsGeometryEngine::InvalidBaseGeometry
@ InvalidBaseGeometry
The geometry on which the operation occurs is not valid.
Definition: qgsgeometryengine.h:49
QgsGeometryEngine::combine
virtual QgsAbstractGeometry * combine(const QVector< QgsGeometry > &geometries, QString *errorMsg=nullptr) const =0
Calculate the combination of this and geometries.
QgsGeometryEngine::~QgsGeometryEngine
virtual ~QgsGeometryEngine()=default
QgsGeometryEngine::combine
virtual QgsAbstractGeometry * combine(const QVector< QgsAbstractGeometry * > &geomList, QString *errorMsg) const =0
Calculate the combination of this and geometries.
QgsGeometryEngine::QgsGeometryEngine
QgsGeometryEngine(const QgsAbstractGeometry *geometry)
Definition: qgsgeometryengine.h:307
QgsGeometryEngine::intersects
virtual bool intersects(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom intersects this.
QgsGeometryEngine::envelope
virtual QgsAbstractGeometry * envelope(QString *errorMsg=nullptr) const =0
QgsGeometryEngine::combine
virtual QgsAbstractGeometry * combine(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Calculate the combination of this and geom.
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsGeometryEngine::symDifference
virtual QgsAbstractGeometry * symDifference(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Calculate the symmetric difference of this and geom.
QgsGeometryEngine::isSimple
virtual bool isSimple(QString *errorMsg=nullptr) const =0
Determines whether the geometry is simple (according to OGC definition).
QgsGeometryEngine::distance
virtual double distance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Calculates the distance between this and geom.
QgsGeometryEngine::isEqual
virtual bool isEqual(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if this is equal to geom.
QgsGeometryEngine::simplify
virtual QgsAbstractGeometry * simplify(double tolerance, QString *errorMsg=nullptr) const =0
QgsGeometryEngine::offsetCurve
virtual QgsAbstractGeometry * offsetCurve(double distance, int segments, int joinStyle, double miterLimit, QString *errorMsg=nullptr) const =0
QgsGeometryEngine::area
virtual double area(QString *errorMsg=nullptr) const =0
QgsGeometryEngine::prepareGeometry
virtual void prepareGeometry()=0
Prepares the geometry, so that subsequent calls to spatial relation methods are much faster.
QgsGeometryEngine::SplitCannotSplitPoint
@ SplitCannotSplitPoint
Points cannot be split.
Definition: qgsgeometryengine.h:52
qgsgeometry.h
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:46
QgsGeometryEngine::within
virtual bool within(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom is within this.
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
QgsGeometryEngine::buffer
virtual QgsAbstractGeometry * buffer(double distance, int segments, int endCapStyle, int joinStyle, double miterLimit, QString *errorMsg=nullptr) const =0
QgsGeometryEngine::splitGeometry
virtual QgsGeometryEngine::EngineOperationResult splitGeometry(const QgsLineString &splitLine, QVector< QgsGeometry > &newGeometries, bool topological, QgsPointSequence &topologyTestPoints, QString *errorMsg=nullptr, bool skipIntersectionCheck=false) const
Splits this geometry according to a given line.
Definition: qgsgeometryengine.h:261
QgsGeometryEngine::EngineOperationResult
EngineOperationResult
Success or failure of a geometry operation.
Definition: qgsgeometryengine.h:43
qgslogger.h
QgsGeometryEngine::difference
virtual QgsAbstractGeometry * difference(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Calculate the difference of this and geom.
QgsGeometryEngine::overlaps
virtual bool overlaps(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom overlaps this.
QgsGeometryEngine::centroid
virtual QgsPoint * centroid(QString *errorMsg=nullptr) const =0
Calculates the centroid of this.
QgsGeometryEngine
Contains geometry relation and modification algorithms.
Definition: qgsgeometryengine.h:35
QgsGeometryEngine::logError
void logError(const QString &engineName, const QString &message) const
Logs an error message encountered during an operation.
Definition: qgsgeometryengine.h:298
QgsGeometryEngine::contains
virtual bool contains(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr) const =0
Checks if geom contains this.