QGIS API Documentation 3.43.0-Master (c6edab485a4)
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
25class QgsLineString;
26
32class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
33{
34 public:
35
36
41
49 QgsPolygon( QgsLineString *exterior SIP_TRANSFER, const QList< QgsLineString * > &rings SIP_TRANSFER = QList< QgsLineString * >() ) SIP_HOLDGIL;
50
51 QString geometryType() const override SIP_HOLDGIL;
52 QgsPolygon *clone() const override SIP_FACTORY;
53 void clear() override;
54 bool fromWkb( QgsConstWkbPtr &wkb ) override;
55 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
56 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
57 QString asWkt( int precision = 17 ) const override;
58 QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
59
64 QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
65
66 void addInteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
67 //overridden to handle LineString25D rings
68 void setExteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
69
70 QgsAbstractGeometry *boundary() const override SIP_FACTORY;
71
77 double pointDistanceToBoundary( double x, double y ) const;
78
79#ifndef SIP_RUN
80
89 inline static const QgsPolygon *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
90 {
91 if ( !geom )
92 return nullptr;
93
94 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
95
96 if ( flatType == Qgis::WkbType::Polygon
97 || flatType == Qgis::WkbType::Triangle )
98 return static_cast<const QgsPolygon *>( geom );
99 return nullptr;
100 }
101
110 inline static QgsPolygon *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
111 {
112 if ( !geom )
113 return nullptr;
114
115 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
116
117 if ( flatType == Qgis::WkbType::Polygon
118 || flatType == Qgis::WkbType::Triangle )
119 return static_cast<QgsPolygon *>( geom );
120 return nullptr;
121 }
122#endif
123
125
126#ifdef SIP_RUN
127 SIP_PYOBJECT __repr__();
128 % MethodCode
129 QString wkt = sipCpp->asWkt();
130 if ( wkt.length() > 1000 )
131 wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
132 QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( wkt );
133 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
134 % End
135#endif
136
137 protected:
138
139 friend class QgsCurvePolygon;
140
141};
142#endif // QGSPOLYGON_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
@ Polygon
Polygon.
@ Triangle
Triangle.
Abstract base class for all geometries.
QFlags< WkbFlag > WkbFlags
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
A const WKB pointer.
Definition qgswkbptr.h:138
Curve polygon geometry type.
QgsCurvePolygon * createEmptyWithSameType() const override
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
Abstract base class for curved geometry type.
Definition qgscurve.h:35
Line string geometry type, with support for z-dimension and m-values.
Polygon geometry type.
Definition qgspolygon.h:33
static const QgsPolygon * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsPolygon.
Definition qgspolygon.h:89
QgsPolygon(QgsLineString *exterior, const QList< QgsLineString * > &rings=QList< QgsLineString * >())
Constructor for QgsPolygon, with the specified exterior ring and interior rings.
static QgsPolygon * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsPolygon.
Definition qgspolygon.h:110
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define SIP_TRANSFER
Definition qgis_sip.h:36
#define SIP_HOLDGIL
Definition qgis_sip.h:171
#define SIP_FACTORY
Definition qgis_sip.h:76
int precision