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 27 /** 28 * \ingroup core 29 * \class QgsPolygon 30 * \brief Polygon geometry type. 31 * \since QGIS 2.10 32 */ 33 class CORE_EXPORT QgsPolygon: public QgsCurvePolygon 34 { 35 public: 36 37 38 /** 39 * Constructor for an empty polygon geometry. 40 */ 41 QgsPolygon() SIP_HOLDGIL; 42 43 /** 44 * Constructor for QgsPolygon, with the specified \a exterior ring and interior \a rings. 45 * 46 * Ownership of \a exterior and \a rings is transferred to the polygon. 47 * 48 * \since QGIS 3.14 49 */ 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 60 /** 61 * Returns the geometry converted to the more generic curve type QgsCurvePolygon 62 * \returns the converted geometry. Caller takes ownership 63 */ 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 72 /** 73 * Returns the distance from a point to the boundary of the polygon (either the 74 * exterior ring or any closer interior rings). The returned distance will be 75 * negative if the point lies outside the polygon. 76 * \since QGIS 3.0 77 */ 78 double pointDistanceToBoundary( double x, double y ) const; 79 80 #ifndef SIP_RUN 81 82 /** 83 * Cast the \a geom to a QgsPolygonV2. 84 * Should be used by qgsgeometry_cast<QgsPolygon *>( geometry ). 85 * 86 * \note Not available in Python. Objects will be automatically be converted to the appropriate target type. 87 * \since QGIS 3.0 88 */ cast(const QgsAbstractGeometry * geom)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 103 QgsPolygon *createEmptyWithSameType() const override SIP_FACTORY; 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 122