QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgssurface.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgssurface.h
3  --------------
4  begin : September 2014
5  copyright : (C) 2014 by Marco Hugentobler
6  email : marco at sourcepole dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #ifndef QGSSURFACE_H
19 #define QGSSURFACE_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgsabstractgeometry.h"
24 #include "qgsrectangle.h"
25 
26 class QgsPolygon;
27 
32 class CORE_EXPORT QgsSurface: public QgsAbstractGeometry
33 {
34  public:
35 
40  virtual QgsPolygon *surfaceToPolygon() const = 0 SIP_FACTORY;
41 
42  QgsRectangle boundingBox() const override
43  {
44  if ( mBoundingBox.isNull() )
45  {
46  mBoundingBox = calculateBoundingBox();
47  }
48  return mBoundingBox;
49  }
50 
51  bool isValid( QString &error SIP_OUT, int flags = 0 ) const override;
52 
53 
54 #ifndef SIP_RUN
55 
63  inline const QgsSurface *cast( const QgsAbstractGeometry *geom ) const
64  {
65  if ( !geom )
66  return nullptr;
67 
68  QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
69  if ( flatType == QgsWkbTypes::CurvePolygon
70  || flatType == QgsWkbTypes::Polygon
71  || flatType == QgsWkbTypes::Triangle )
72  return static_cast<const QgsSurface *>( geom );
73  return nullptr;
74  }
75 #endif
76  protected:
77 
78  void clearCache() const override;
79 
81  mutable bool mHasCachedValidity = false;
82  mutable QString mValidityFailureReason;
83 };
84 
85 #endif // QGSSURFACE_H
QgsSurface::cast
const QgsSurface * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsSurface.
Definition: qgssurface.h:63
QgsWkbTypes::Triangle
@ Triangle
Definition: qgswkbtypes.h:75
QgsAbstractGeometry::clearCache
virtual void clearCache() const
Clears any cached parameters associated with the geometry, e.g., bounding boxes.
Definition: qgsabstractgeometry.cpp:112
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:34
qgsrectangle.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsWkbTypes::flatType
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:702
QgsSurface
Definition: qgssurface.h:33
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsAbstractGeometry::isValid
virtual bool isValid(QString &error, int flags=0) const =0
Checks validity of the geometry, and returns true if the geometry is valid.
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsSurface::surfaceToPolygon
virtual QgsPolygon * surfaceToPolygon() const =0
Gets a polygon representation of this surface.
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:193
qgis_sip.h
QgsWkbTypes::CurvePolygon
@ CurvePolygon
Definition: qgswkbtypes.h:82
QgsSurface::mValidityFailureReason
QString mValidityFailureReason
Definition: qgssurface.h:82
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:74
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
qgsabstractgeometry.h
QgsSurface::boundingBox
QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Definition: qgssurface.h:42
QgsAbstractGeometry::calculateBoundingBox
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
Definition: qgsabstractgeometry.cpp:85
QgsSurface::mBoundingBox
QgsRectangle mBoundingBox
Definition: qgssurface.h:80