QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
68 class CORE_EXPORT QgsGeometryEngine
69 {
70  public:
71 
77  {
78  Success = 0,
79  NothingHappened = 1000,
85  /* split */
87  };
88 
89  virtual ~QgsGeometryEngine() = default;
90 
95  virtual void geometryChanged() = 0;
96 
106  virtual void prepareGeometry() = 0;
107 
113  virtual QgsAbstractGeometry *intersection( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
114 
120  virtual QgsAbstractGeometry *difference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
121 
127  virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
128 
134  virtual QgsAbstractGeometry *combine( const QVector<QgsAbstractGeometry *> &geomList, QString *errorMsg ) const = 0 SIP_FACTORY;
135 
141  virtual QgsAbstractGeometry *combine( const QVector< QgsGeometry > &geometries, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
142 
148  virtual QgsAbstractGeometry *symDifference( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
149  virtual QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
150 
154  virtual QgsAbstractGeometry *buffer( double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
155  virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
156  virtual QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
157  virtual QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
158 
165  virtual QgsPoint *centroid( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
166 
173  virtual QgsPoint *pointOnSurface( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
174 
178  virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
179 
185  virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
186 
192  virtual bool distanceWithin( const QgsAbstractGeometry *geom, double maxdistance, QString *errorMsg = nullptr ) const = 0;
193 
199  virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
200 
206  virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
207 
213  virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
214 
220  virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
221 
227  virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
228 
234  virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
235 
241  virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
242 
251  virtual QString relate( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
252 
262  virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = nullptr ) const = 0;
263 
264  virtual double area( QString *errorMsg = nullptr ) const = 0;
265  virtual double length( QString *errorMsg = nullptr ) const = 0;
266 
278  virtual bool isValid( QString *errorMsg = nullptr, bool allowSelfTouchingHoles = false, QgsGeometry *errorLoc = nullptr ) const = 0;
279 
286  virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr ) const = 0;
287  virtual bool isEmpty( QString *errorMsg ) const = 0;
288 
293  virtual bool isSimple( QString *errorMsg = nullptr ) const = 0;
294 
307  QVector<QgsGeometry > &newGeometries SIP_OUT,
308  bool topological,
309  QgsPointSequence &topologyTestPoints, QString *errorMsg = nullptr, bool skipIntersectionCheck = false ) const
310  {
311  Q_UNUSED( splitLine )
312  Q_UNUSED( newGeometries )
313  Q_UNUSED( topological )
314  Q_UNUSED( topologyTestPoints )
315  Q_UNUSED( errorMsg )
316  Q_UNUSED( skipIntersectionCheck )
317  return MethodNotImplemented;
318  }
319 
323  virtual QgsAbstractGeometry *offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
324 
333  void setLogErrors( bool enabled ) { mLogErrors = enabled; }
334 
335  protected:
336  const QgsAbstractGeometry *mGeometry = nullptr;
337  bool mLogErrors = true;
338 
346  void logError( const QString &engineName, const QString &message ) const
347  {
348  if ( mLogErrors )
349  {
350  QgsDebugMsg( QStringLiteral( "%1 notice: %2" ).arg( engineName, message ) );
351  qWarning( "%s exception: %s", engineName.toLocal8Bit().constData(), message.toLocal8Bit().constData() );
352  }
353  }
354 
356  : mGeometry( geometry )
357  {}
358 };
359 
360 #endif // QGSGEOMETRYENGINE_H
361 
QgsGeometryEngine::InvalidInput
@ InvalidInput
The input is not valid.
Definition: qgsgeometryengine.h:84
qgslinestring.h
QgsGeometryEngine::setLogErrors
void setLogErrors(bool enabled)
Sets whether warnings and errors encountered during the geometry operations should be logged.
Definition: qgsgeometryengine.h:333
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:48
QgsMeshUtils::centroid
CORE_EXPORT QgsMeshVertex centroid(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns the centroid of the face.
Definition: qgstriangularmesh.cpp:955
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
Qgis::EndCapStyle
EndCapStyle
End cap styles for buffers.
Definition: qgis.h:966
QgsGeometryEngine::EngineError
@ EngineError
Error occurred in the geometry engine.
Definition: qgsgeometryengine.h:81
QgsGeometryEngine::MethodNotImplemented
@ MethodNotImplemented
Method not implemented in geometry engine.
Definition: qgsgeometryengine.h:80
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
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsGeometryEngine::NodedGeometryError
@ NodedGeometryError
Error occurred while creating a noded geometry.
Definition: qgsgeometryengine.h:82
QgsGeometryEngine::InvalidBaseGeometry
@ InvalidBaseGeometry
The geometry on which the operation occurs is not valid.
Definition: qgsgeometryengine.h:83
QgsGeometryEngine::QgsGeometryEngine
QgsGeometryEngine(const QgsAbstractGeometry *geometry)
Definition: qgsgeometryengine.h:355
Qgis::JoinStyle
JoinStyle
Join styles for buffers.
Definition: qgis.h:979
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:79
QgsGeometryEngine::SplitCannotSplitPoint
@ SplitCannotSplitPoint
Points cannot be split.
Definition: qgsgeometryengine.h:86
qgsgeometry.h
QgsPointSequence
QVector< QgsPoint > QgsPointSequence
Definition: qgsabstractgeometry.h:52
QgsGeometry
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:124
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:306
QgsGeometryEngine::EngineOperationResult
EngineOperationResult
Success or failure of a geometry operation.
Definition: qgsgeometryengine.h:76
qgslogger.h
QgsGeometryEngine
A geometry engine is a low-level representation of a QgsAbstractGeometry object, optimised for use wi...
Definition: qgsgeometryengine.h:68
QgsGeometryEngine::logError
void logError(const QString &engineName, const QString &message) const
Logs an error message encountered during an operation.
Definition: qgsgeometryengine.h:346