QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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#include <QString>
26
27using namespace Qt::StringLiterals;
28
29class QgsLineString;
30
36class CORE_EXPORT QgsPolygon: public QgsCurvePolygon
37{
38 public:
39
40
45
53 QgsPolygon( QgsLineString *exterior SIP_TRANSFER, const QList< QgsLineString * > &rings SIP_TRANSFER = QList< QgsLineString * >() ) SIP_HOLDGIL;
54
55 QString geometryType() const override SIP_HOLDGIL;
56 QgsPolygon *clone() const override SIP_FACTORY;
57 void clear() override;
58 bool fromWkb( QgsConstWkbPtr &wkb ) override;
59 int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
60 QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
61 QString asWkt( int precision = 17 ) const override;
62 QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
63
68 QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
69
70 void addInteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
71 //overridden to handle LineString25D rings
72 void setExteriorRing( QgsCurve *ring SIP_TRANSFER ) override;
73
75
81 double pointDistanceToBoundary( double x, double y ) const;
82
83#ifndef SIP_RUN
84
93 inline static const QgsPolygon *cast( const QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
94 {
95 if ( !geom )
96 return nullptr;
97
98 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
99
100 if ( flatType == Qgis::WkbType::Polygon
101 || flatType == Qgis::WkbType::Triangle )
102 return static_cast<const QgsPolygon *>( geom );
103 return nullptr;
104 }
105
114 inline static QgsPolygon *cast( QgsAbstractGeometry *geom ) // cppcheck-suppress duplInheritedMember
115 {
116 if ( !geom )
117 return nullptr;
118
119 const Qgis::WkbType flatType = QgsWkbTypes::flatType( geom->wkbType() );
120
121 if ( flatType == Qgis::WkbType::Polygon
122 || flatType == Qgis::WkbType::Triangle )
123 return static_cast<QgsPolygon *>( geom );
124 return nullptr;
125 }
126#endif
127
129
130#ifdef SIP_RUN
131 SIP_PYOBJECT __repr__();
132 % MethodCode
133 QString wkt = sipCpp->asWkt();
134 if ( wkt.length() > 1000 )
135 wkt = wkt.left( 1000 ) + u"..."_s;
136 QString str = u"<QgsPolygon: %1>"_s.arg( wkt );
137 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
138 % End
139#endif
140
141 protected:
142
143 friend class QgsCurvePolygon;
144
145};
146#endif // QGSPOLYGON_H
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:280
@ Polygon
Polygon.
Definition qgis.h:284
@ Triangle
Triangle.
Definition qgis.h:285
QFlags< WkbFlag > WkbFlags
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
QgsAbstractGeometry()=default
A const WKB pointer.
Definition qgswkbptr.h:139
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:36
Line string geometry type, with support for z-dimension and m-values.
Polygon geometry type.
Definition qgspolygon.h:37
QgsCurvePolygon * toCurveType() const override
Returns the geometry converted to the more generic curve type QgsCurvePolygon.
static const QgsPolygon * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsPolygon.
Definition qgspolygon.h:93
QgsPolygon(QgsLineString *exterior, const QList< QgsLineString * > &rings=QList< QgsLineString * >())
Constructor for QgsPolygon, with the specified exterior ring and interior rings.
void setExteriorRing(QgsCurve *ring) override
Sets the exterior ring of the polygon.
void addInteriorRing(QgsCurve *ring) override
Adds an interior ring to the geometry (takes ownership).
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb().
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns a WKB representation of the geometry.
QgsPolygon * clone() const override
Clones the geometry by performing a deep copy.
void clear() override
Clears the geometry, ie reset it to a null geometry.
QString geometryType() const override
Returns a unique string representing the geometry type.
double pointDistanceToBoundary(double x, double y) const
Returns the distance from a point to the boundary of the polygon (either the exterior ring or any clo...
QgsAbstractGeometry * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
friend class QgsCurvePolygon
Definition qgspolygon.h:143
QgsPolygon()
Constructor for an empty polygon geometry.
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
QgsPolygon * surfaceToPolygon() const override
Gets a polygon representation of this surface.
QString asWkt(int precision=17) const override
Returns a WKT representation of the geometry.
static QgsPolygon * cast(QgsAbstractGeometry *geom)
Cast the geom to a QgsPolygon.
Definition qgspolygon.h:114
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:179
#define SIP_FACTORY
Definition qgis_sip.h:84