QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
Loading...
Searching...
No Matches
qgsgeometryengine.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsgeometryengine.h
3 -------------------------------------------------------------------
4Date : 22 Sept 2014
5Copyright : (C) 2014 by Marco Hugentobler
6email : 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 "qgsgeometry.h"
21#include "qgslinestring.h"
22#include "qgslogger.h"
23
24#include <QString>
25#include <QVector>
26
27using namespace Qt::StringLiterals;
28
30class QgsFeedback;
31
32#ifdef SIP_RUN
33// clang-format off
34% ModuleHeaderCode
35#include <qgsgeos.h>
36% End
37// clang-format on
38#endif
39
79 class CORE_EXPORT QgsGeometryEngine
80{
81#ifdef SIP_RUN
83 if ( dynamic_cast< QgsGeos * >( sipCpp ) != NULL )
84 sipType = sipType_QgsGeos;
85 else
86 sipType = NULL;
88#endif
89
90 public:
91
108
109 virtual ~QgsGeometryEngine() = default;
110
115 virtual void geometryChanged() = 0;
116
126 virtual void prepareGeometry() = 0;
127
137 const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr
138 ) const
139 = 0 SIP_FACTORY;
140
150 const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr
151 ) const
152 = 0 SIP_FACTORY;
153
163 virtual QgsAbstractGeometry *combine( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr ) const
164 = 0 SIP_FACTORY;
165
176 const QVector<QgsAbstractGeometry *> &geomList, QString *errorMsg, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr
177 ) const
178 = 0 SIP_FACTORY;
179
180 // clang-format off
189 virtual QgsAbstractGeometry *combine( const QVector< QgsGeometry > &geometries, QString *errorMsg = nullptr, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
190 // clang-format on
191
202 const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, const QgsGeometryParameters &parameters = QgsGeometryParameters(), QgsFeedback *feedback = nullptr
203 ) const
204 = 0 SIP_FACTORY;
205
213 virtual QgsAbstractGeometry *buffer( double distance, int segments, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
214
221 double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr
222 ) const
223 = 0 SIP_FACTORY;
224
231 virtual QgsAbstractGeometry *simplify( double tolerance, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
232
240 virtual QgsAbstractGeometry *interpolate( double distance, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
241
242 virtual QgsAbstractGeometry *envelope( QString *errorMsg = nullptr ) const = 0 SIP_FACTORY;
243
251 virtual QgsPoint *centroid( QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
252
259 virtual QgsPoint *pointOnSurface( QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
260
266 virtual QgsAbstractGeometry *convexHull( QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0 SIP_FACTORY;
267
273 virtual double distance( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
274
282 virtual bool distanceWithin( const QgsAbstractGeometry *geom, double maxdistance, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
283
289 virtual bool intersects( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
290
296 virtual bool touches( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
297
303 virtual bool crosses( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
304
310 virtual bool within( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
311
317 virtual bool overlaps( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
318
324 virtual bool contains( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
325
331 virtual bool disjoint( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
332
342 virtual QString relate( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
343
353 virtual bool relatePattern( const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
354
355 virtual double area( QString *errorMsg = nullptr ) const = 0;
356 virtual double length( QString *errorMsg = nullptr ) const = 0;
357
371 virtual bool isValid( QString *errorMsg = nullptr, bool allowSelfTouchingHoles = false, QgsGeometry *errorLoc = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
372
380 virtual bool isEqual( const QgsAbstractGeometry *geom, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
381
392 virtual bool isFuzzyEqual( const QgsAbstractGeometry *geom, double epsilon, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0;
393
394 virtual bool isEmpty( QString *errorMsg ) const = 0;
395
399 virtual bool isSimple( QString *errorMsg = nullptr ) const = 0;
400
413 const QgsLineString &splitLine, QVector<QgsGeometry > &newGeometries SIP_OUT, bool topological, QgsPointSequence &topologyTestPoints, QString *errorMsg = nullptr, bool skipIntersectionCheck = false
414 ) const
415 {
416 Q_UNUSED( splitLine )
417 Q_UNUSED( newGeometries )
418 Q_UNUSED( topological )
419 Q_UNUSED( topologyTestPoints )
420 Q_UNUSED( errorMsg )
421 Q_UNUSED( skipIntersectionCheck )
423 }
424
430 virtual QgsAbstractGeometry *offsetCurve( double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg = nullptr, QgsFeedback *feedback = nullptr ) const = 0
432
441 void setLogErrors( bool enabled ) { mLogErrors = enabled; }
442
443 protected:
445 bool mLogErrors = true;
446
454 void logError( const QString &engineName, const QString &message ) const
455 {
456 if ( mLogErrors )
457 {
458 QgsDebugError( u"%1 notice: %2"_s.arg( engineName, message ) );
459 qWarning( "%s exception: %s", engineName.toLocal8Bit().constData(), message.toLocal8Bit().constData() );
460 }
461 }
462
464 : mGeometry( geometry )
465 {}
466};
467
468#endif // QGSGEOMETRYENGINE_H
JoinStyle
Join styles for buffers.
Definition qgis.h:2241
EndCapStyle
End cap styles for buffers.
Definition qgis.h:2228
Abstract base class for all geometries.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
virtual double area(QString *errorMsg=nullptr) const =0
virtual ~QgsGeometryEngine()=default
virtual bool isFuzzyEqual(const QgsAbstractGeometry *geom, double epsilon, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if this is equal to geom ie.
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.
virtual void geometryChanged()=0
Should be called whenever the geometry associated with the engine has been modified and the engine mu...
virtual bool overlaps(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom overlaps this.
virtual QgsAbstractGeometry * intersection(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the intersection of this and geom.
virtual bool isEqual(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Check if geometries are topologically equivalent.
virtual double distance(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Calculates the distance between this and geom.
virtual QgsAbstractGeometry * symDifference(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the symmetric difference of this and geom.
virtual QgsAbstractGeometry * simplify(double tolerance, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Simplifies the geometery.
const QgsAbstractGeometry * mGeometry
virtual bool crosses(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom crosses this.
virtual QgsAbstractGeometry * combine(const QVector< QgsGeometry > &geometries, QString *errorMsg=nullptr, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the combination of this and geometries.
virtual QgsAbstractGeometry * difference(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the difference of this and geom.
virtual QgsPoint * centroid(QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Calculates the centroid of this.
void setLogErrors(bool enabled)
Sets whether warnings and errors encountered during the geometry operations should be logged.
virtual QgsAbstractGeometry * buffer(double distance, int segments, Qgis::EndCapStyle endCapStyle, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Buffers a geometry.
virtual QgsAbstractGeometry * convexHull(QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Calculate the convex hull of this geometry.
virtual QgsAbstractGeometry * buffer(double distance, int segments, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Buffers the geometry.
virtual QgsAbstractGeometry * envelope(QString *errorMsg=nullptr) const =0
EngineOperationResult
Success or failure of a geometry operation.
@ NothingHappened
Nothing happened, without any error.
@ InvalidBaseGeometry
The geometry on which the operation occurs is not valid.
@ InvalidInput
The input is not valid.
@ NodedGeometryError
Error occurred while creating a noded geometry.
@ EngineError
Error occurred in the geometry engine.
@ SplitCannotSplitPoint
Points cannot be split.
@ Success
Operation succeeded.
@ MethodNotImplemented
Method not implemented in geometry engine.
virtual bool relatePattern(const QgsAbstractGeometry *geom, const QString &pattern, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Tests whether two geometries are related by a specified Dimensional Extended 9 Intersection Model (DE...
virtual bool isEmpty(QString *errorMsg) const =0
virtual QgsAbstractGeometry * interpolate(double distance, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Interpolates a point by distance along the geometry.
virtual bool within(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom is within this.
QgsGeometryEngine(const QgsAbstractGeometry *geometry)
virtual bool isSimple(QString *errorMsg=nullptr) const =0
Determines whether the geometry is simple (according to OGC definition).
virtual bool intersects(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom intersects this.
virtual bool disjoint(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom is disjoint from this.
virtual QgsAbstractGeometry * combine(const QVector< QgsAbstractGeometry * > &geomList, QString *errorMsg, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the combination of this and geometries.
virtual bool isValid(QString *errorMsg=nullptr, bool allowSelfTouchingHoles=false, QgsGeometry *errorLoc=nullptr, QgsFeedback *feedback=nullptr) const =0
Returns true if the geometry is valid.
virtual bool contains(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom contains this.
virtual bool distanceWithin(const QgsAbstractGeometry *geom, double maxdistance, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom is within maxdistance distance from this geometry.
virtual void prepareGeometry()=0
Prepares the geometry, so that subsequent calls to spatial relation methods are much faster.
virtual QgsPoint * pointOnSurface(QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Calculate a point that is guaranteed to be on the surface of this.
virtual double length(QString *errorMsg=nullptr) const =0
virtual bool touches(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Checks if geom touches this.
virtual QgsAbstractGeometry * offsetCurve(double distance, int segments, Qgis::JoinStyle joinStyle, double miterLimit, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Offsets a curve.
void logError(const QString &engineName, const QString &message) const
Logs an error message encountered during an operation.
virtual QgsAbstractGeometry * combine(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, const QgsGeometryParameters &parameters=QgsGeometryParameters(), QgsFeedback *feedback=nullptr) const =0
Calculate the combination of this and geom.
virtual QString relate(const QgsAbstractGeometry *geom, QString *errorMsg=nullptr, QgsFeedback *feedback=nullptr) const =0
Returns the Dimensional Extended 9 Intersection Model (DE-9IM) representation of the relationship bet...
Encapsulates parameters under which a geometry operation is performed.
A geometry is the spatial representation of a feature.
Does vector analysis using the GEOS library and handles import, export, and exception handling.
Definition qgsgeos.h:175
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:53
#define SIP_CONVERT_TO_SUBCLASS_CODE(code)
Definition qgis_sip.h:198
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_END
Definition qgis_sip.h:215
QVector< QgsPoint > QgsPointSequence
#define QgsDebugError(str)
Definition qgslogger.h:59