QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
37 
42 
50  QgsPolygon( QgsLineString *exterior SIP_TRANSFER, const QList< QgsLineString * > &rings SIP_TRANSFER = QList< QgsLineString * >() ) SIP_HOLDGIL;
51 
52  QString geometryType() const override SIP_HOLDGIL;
53  QgsPolygon *clone() const override SIP_FACTORY;
54  void clear() override;
55  bool fromWkb( QgsConstWkbPtr &wkb ) override;
56  int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
57  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) 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 
78  double pointDistanceToBoundary( double x, double y ) const;
79 
80 #ifndef SIP_RUN
81 
89  inline static const QgsPolygon *cast( const QgsAbstractGeometry *geom )
90  {
91  if ( !geom )
92  return nullptr;
93 
94  const QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
95 
96  if ( flatType == QgsWkbTypes::Polygon
97  || flatType == QgsWkbTypes::Triangle )
98  return static_cast<const QgsPolygon *>( geom );
99  return nullptr;
100  }
101 #endif
102 
104 
105 #ifdef SIP_RUN
106  SIP_PYOBJECT __repr__();
107  % MethodCode
108  QString wkt = sipCpp->asWkt();
109  if ( wkt.length() > 1000 )
110  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
111  QString str = QStringLiteral( "<QgsPolygon: %1>" ).arg( wkt );
112  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
113  % End
114 #endif
115 
116  protected:
117 
118  friend class QgsCurvePolygon;
119 
120 };
121 #endif // QGSPOLYGON_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsPolygon::cast
static const QgsPolygon * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsPolygonV2.
Definition: qgspolygon.h:89
QgsWkbTypes::Triangle
@ Triangle
Definition: qgswkbtypes.h:75
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:145
QgsCurvePolygon::setExteriorRing
virtual void setExteriorRing(QgsCurve *ring)
Sets the exterior ring of the polygon.
Definition: qgscurvepolygon.cpp:698
QgsWkbTypes::flatType
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:732
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:140
QgsCurvePolygon::wkbSize
int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Returns the length of the QByteArray returned by asWkb()
Definition: qgscurvepolygon.cpp:292
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsLineString
Line string geometry type, with support for z-dimension and m-values.
Definition: qgslinestring.h:44
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_HOLDGIL
#define SIP_HOLDGIL
Definition: qgis_sip.h:166
QgsAbstractGeometry::wkbType
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
Definition: qgsabstractgeometry.h:206
QgsCurvePolygon::fromWkb
bool fromWkb(QgsConstWkbPtr &wkb) override
Sets the geometry from a WKB string.
Definition: qgscurvepolygon.cpp:155
QgsCurvePolygon::addInteriorRing
virtual void addInteriorRing(QgsCurve *ring)
Adds an interior ring to the geometry (takes ownership)
Definition: qgscurvepolygon.cpp:745
QgsConstWkbPtr
A const WKB pointer.
Definition: qgswkbptr.h:137
qgis_sip.h
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsCurvePolygon::geometryType
QString geometryType() const override SIP_HOLDGIL
Returns a unique string representing the geometry type.
Definition: qgscurvepolygon.cpp:53
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:46
qgscurvepolygon.h
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:79
QgsCurvePolygon::toCurveType
QgsCurvePolygon * toCurveType() const override
Returns the geometry converted to the more generic curve type.
Definition: qgscurvepolygon.cpp:1357
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:557
str
#define str(x)
Definition: qgis.cpp:37
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:74
QgsCurvePolygon::surfaceToPolygon
QgsPolygon * surfaceToPolygon() const override
Gets a polygon representation of this surface.
Definition: qgscurvepolygon.cpp:539
QgsCurvePolygon::asWkb
QByteArray asWkb(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const override
Definition: qgscurvepolygon.cpp:306