QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgspolygon.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspolygon.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 QGSPOLYGON_H
19 #define QGSPOLYGON_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgscurvepolygon.h"
24 
25 class QgsLineString;
26 
33 class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
34 {
35  public:
36  QgsPolygon();
37 
45  QgsPolygon( QgsLineString *exterior SIP_TRANSFER, const QList< QgsLineString * > &rings SIP_TRANSFER = QList< QgsLineString * >() );
46 
47  QString geometryType() const override;
48  QgsPolygon *clone() const override SIP_FACTORY;
49  void clear() override;
50  bool fromWkb( QgsConstWkbPtr &wkb ) override;
51  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
52  QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
53 
57  QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
58 
59  void addInteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
60  //overridden to handle LineString25D rings
61  void setExteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
62 
63  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
64 
71  double pointDistanceToBoundary( double x, double y ) const;
72 
73 #ifndef SIP_RUN
74 
82  inline const QgsPolygon *cast( const QgsAbstractGeometry *geom ) const
83  {
84  if ( !geom )
85  return nullptr;
86 
87  QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
88 
89  if ( flatType == QgsWkbTypes::Polygon
90  || flatType == QgsWkbTypes::Triangle )
91  return static_cast<const QgsPolygon *>( geom );
92  return nullptr;
93  }
94 #endif
95 
97 
98 #ifdef SIP_RUN
99  SIP_PYOBJECT __repr__();
100  % MethodCode
101  QString wkt = sipCpp->asWkt();
102  if ( wkt.length() > 1000 )
103  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
104  QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( wkt );
105  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
106  % End
107 #endif
108 
109  protected:
110 
111  friend class QgsCurvePolygon;
112 
113 };
114 #endif // QGSPOLYGON_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:189
QgsWkbTypes::Triangle
@ Triangle
Definition: qgswkbtypes.h:74
QgsPolygon
Polygon geometry type.
Definition: qgspolygon.h:33
QgsCurvePolygon::clear
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition: qgscurvepolygon.cpp:144
QgsCurvePolygon::setExteriorRing
virtual void setExteriorRing(QgsCurve *ring)
Sets the exterior ring of the polygon.
Definition: qgscurvepolygon.cpp:629
QgsCurvePolygon
Curve polygon geometry type.
Definition: qgscurvepolygon.h:34
QgsCurvePolygon::clone
QgsCurvePolygon * clone() const override
Clones the geometry by performing a deep copy.
Definition: qgscurvepolygon.cpp:139
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:43
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsCurvePolygon::fromWkb
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
Definition: qgscurvepolygon.cpp:154
QgsCurvePolygon::addInteriorRing
virtual void addInteriorRing(QgsCurve *ring)
Adds an interior ring to the geometry (takes ownership)
Definition: qgscurvepolygon.cpp:676
QgsConstWkbPtr
Definition: qgswkbptr.h:127
QgsPolygon::cast
const QgsPolygon * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsPolygonV2.
Definition: qgspolygon.h:82
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsCurvePolygon::createEmptyWithSameType
QgsCurvePolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Definition: qgscurvepolygon.cpp:45
qgscurvepolygon.h
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsCurvePolygon::toCurveType
QgsCurvePolygon * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition: qgscurvepolygon.cpp:1237
QgsCurvePolygon::boundary
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Definition: qgscurvepolygon.cpp:521
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:73
QgsCurvePolygon::geometryType
QString geometryType() const override
Returns a unique string representing the geometry type.
Definition: qgscurvepolygon.cpp:52
QgsCurvePolygon::surfaceToPolygon
QgsPolygon * surfaceToPolygon() const override
Gets a polygon representation of this surface.
Definition: qgscurvepolygon.cpp:503
QgsWkbTypes::flatType
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:701
QgsCurvePolygon::asWkb
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Definition: qgscurvepolygon.cpp:288