QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgscurvepolygon.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgscurvepolygon.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 QGSCURVEPOLYGON_H
19 #define QGSCURVEPOLYGON_H
20 
21 #include "qgis_core.h"
22 #include "qgis_sip.h"
23 #include "qgssurface.h"
24 #include <memory>
25 
26 class QgsPolygon;
27 
34 class CORE_EXPORT QgsCurvePolygon: public QgsSurface
35 {
36  public:
38  QgsCurvePolygon( const QgsCurvePolygon &p );
40 
41  bool operator==( const QgsAbstractGeometry &other ) const override;
42  bool operator!=( const QgsAbstractGeometry &other ) const override;
43 
44  ~QgsCurvePolygon() override;
45 
46  QString geometryType() const override;
47  int dimension() const override;
48  QgsCurvePolygon *clone() const override SIP_FACTORY;
49  void clear() override;
50 
51  bool fromWkb( QgsConstWkbPtr &wkb ) override;
52  bool fromWkt( const QString &wkt ) override;
53 
54  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
55  QString asWkt( int precision = 17 ) const override;
56  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
57  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
58  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
59  QString asKml( int precision = 17 ) const override;
60 
61  //surface interface
62  double area() const override;
63  double perimeter() const override;
64  QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
65  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
66  QgsCurvePolygon *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
67  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
68 
69  //curve polygon interface
70 
76  int numInteriorRings() const
77  {
78  return mInteriorRings.size();
79  }
80 
86  const QgsCurve *exteriorRing() const
87  {
88  return mExteriorRing.get();
89  }
90 
91 #ifndef SIP_RUN
92 
99  const QgsCurve *interiorRing( int i ) const
100  {
101  if ( i < 0 || i >= mInteriorRings.size() )
102  {
103  return nullptr;
104  }
105  return mInteriorRings.at( i );
106  }
107 #else
108 
117  SIP_PYOBJECT interiorRing( int i ) SIP_TYPEHINT( QgsCurve );
118  % MethodCode
119  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
120  {
121  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
122  sipIsErr = 1;
123  }
124  else
125  {
126  return sipConvertFromType( const_cast< QgsCurve * >( sipCpp->interiorRing( a0 ) ), sipType_QgsCurve, NULL );
127  }
128  % End
129 #endif
130 
136  virtual QgsPolygon *toPolygon( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const SIP_FACTORY;
137 
146  virtual void setExteriorRing( QgsCurve *ring SIP_TRANSFER );
147 
149  void setInteriorRings( const QVector<QgsCurve *> &rings SIP_TRANSFER );
151  virtual void addInteriorRing( QgsCurve *ring SIP_TRANSFER );
152 
153 #ifndef SIP_RUN
154 
161  bool removeInteriorRing( int ringIndex );
162 #else
163 
173  bool removeInteriorRing( int i );
174  % MethodCode
175  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
176  {
177  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
178  sipIsErr = 1;
179  }
180  else
181  {
182  return PyBool_FromLong( sipCpp->removeInteriorRing( a0 ) );
183  }
184  % End
185 #endif
186 
194  void removeInteriorRings( double minimumAllowedArea = -1 );
195 
203  void removeInvalidRings();
204 
213  void forceRHR();
214 
215  void draw( QPainter &p ) const override;
217  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
218 
219  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
220  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
221  bool deleteVertex( QgsVertexId position ) override;
222 
223  QgsCoordinateSequence coordinateSequence() const override;
224  int nCoordinates() const override;
225  int vertexNumberFromVertexId( QgsVertexId id ) const override;
226  bool isEmpty() const override;
227  double closestSegment( const QgsPoint &pt, QgsPoint &segmentPt SIP_OUT, QgsVertexId &vertexAfter SIP_OUT, int *leftOf SIP_OUT = nullptr, double epsilon = 4 * std::numeric_limits<double>::epsilon() ) const override;
228 
229  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
230  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
231  bool hasCurvedSegments() const override;
232 
237  QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
238 
244  double vertexAngle( QgsVertexId vertex ) const override;
245 
246  int vertexCount( int part = 0, int ring = 0 ) const override;
247  int ringCount( int part = 0 ) const override;
248  int partCount() const override;
249  QgsPoint vertexAt( QgsVertexId id ) const override;
250  double segmentLength( QgsVertexId startVertex ) const override;
251 
252  bool addZValue( double zValue = 0 ) override;
253  bool addMValue( double mValue = 0 ) override;
254  bool dropZValue() override;
255  bool dropMValue() override;
256  void swapXy() override;
257 
258  QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
259 
260 #ifndef SIP_RUN
261  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
262  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
263 
271  inline const QgsCurvePolygon *cast( const QgsAbstractGeometry *geom ) const
272  {
273  if ( !geom )
274  return nullptr;
275 
276  QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
277  if ( flatType == QgsWkbTypes::CurvePolygon
278  || flatType == QgsWkbTypes::Polygon
279  || flatType == QgsWkbTypes::Triangle )
280  return static_cast<const QgsCurvePolygon *>( geom );
281  return nullptr;
282  }
283 #endif
284 
286 
287 #ifdef SIP_RUN
288  SIP_PYOBJECT __repr__();
289  % MethodCode
290  QString wkt = sipCpp->asWkt();
291  if ( wkt.length() > 1000 )
292  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
293  QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( wkt );
294  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
295  % End
296 #endif
297 
298  protected:
299 
300  int childCount() const override;
301  QgsAbstractGeometry *childGeometry( int index ) const override;
302 
303  protected:
304 
305  std::unique_ptr< QgsCurve > mExteriorRing;
306  QVector<QgsCurve *> mInteriorRings;
307 
308  QgsRectangle calculateBoundingBox() const override;
309 };
310 
311 // clazy:excludeall=qstring-allocations
312 
313 #endif // QGSCURVEPOLYGON_H
QgsCurve
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
QgsCoordinateSequence
QVector< QgsRingSequence > QgsCoordinateSequence
Definition: qgsabstractgeometry.h:49
QgsAbstractGeometry::removeDuplicateNodes
virtual bool removeDuplicateNodes(double epsilon=4 *std::numeric_limits< double >::epsilon(), bool useZValues=false)=0
Removes duplicate nodes from the geometry, wherever removing the nodes does not result in a degenerat...
QgsAbstractGeometry::fromWkt
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
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
QgsAbstractGeometry::asWkb
virtual QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of the geometry.
QgsPoint
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
QgsAbstractGeometry::snappedToGrid
virtual QgsAbstractGeometry * snappedToGrid(double hSpacing, double vSpacing, double dSpacing=0, double mSpacing=0) const =0
Makes a new geometry with all the points or vertices snapped to the closest point of the grid.
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsAbstractGeometry::filterVertices
virtual void filterVertices(const std::function< bool(const QgsPoint &) > &filter)
Filters the vertices from the geometry in place, removing any which do not return true for the filter...
Definition: qgsabstractgeometry.cpp:250
QgsCurvePolygon
Curve polygon geometry type.
Definition: qgscurvepolygon.h:34
QgsCoordinateTransform::TransformDirection
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
Definition: qgscoordinatetransform.h:58
QgsAbstractGeometry::asWkt
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
QgsCurvePolygon::exteriorRing
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
Definition: qgscurvepolygon.h:86
QgsSurface
Definition: qgssurface.h:32
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsAbstractGeometry::asKml
virtual QString asKml(int precision=17) const =0
Returns a KML representation of the geometry.
QgsAbstractGeometry::childGeometry
virtual QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
Definition: qgsabstractgeometry.h:995
closestSegment
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition: qgstracer.cpp:68
QgsRectangle
Definition: qgsrectangle.h:41
QgsCurvePolygon::interiorRing
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Definition: qgscurvepolygon.h:99
SIP_TYPEHINT
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:213
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
MathUtils::leftOf
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'. Negative values mean left ...
Definition: MathUtils.cpp:292
QgsAbstractGeometry::area
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
Definition: qgsabstractgeometry.cpp:142
QgsSurface::surfaceToPolygon
virtual QgsPolygon * surfaceToPolygon() const =0
Gets a polygon representation of this surface.
precision
int precision
Definition: qgswfsgetfeature.cpp:103
QgsAbstractGeometry::dimension
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
QgsCsException
Definition: qgsexception.h:65
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:184
QgsCurvePolygon::mExteriorRing
std::unique_ptr< QgsCurve > mExteriorRing
Definition: qgscurvepolygon.h:305
QgsAbstractGeometry::AxisOrder
AxisOrder
Axis order for GML generation.
Definition: qgsabstractgeometry.h:128
QgsAbstractGeometry::asJsonObject
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
Definition: qgsabstractgeometry.cpp:162
QgsMeshUtils::toPolygon
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
Definition: qgstriangularmesh.cpp:509
QgsConstWkbPtr
Definition: qgswkbptr.h:127
QgsAbstractGeometry::clone
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
qgis_sip.h
QgsWkbTypes::CurvePolygon
@ CurvePolygon
Definition: qgswkbtypes.h:81
SIP_TRANSFER
#define SIP_TRANSFER
Definition: qgis_sip.h:36
QgsAbstractGeometry::clear
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
QgsAbstractGeometry::fromWkb
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.
QgsAbstractGeometry
Abstract base class for all geometries.
Definition: qgsabstractgeometry.h:71
QgsCoordinateTransform::ForwardTransform
@ ForwardTransform
Transform from source to destination CRS.
Definition: qgscoordinatetransform.h:60
QgsAbstractGeometry::geometryType
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
QgsAbstractGeometry::createEmptyWithSameType
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
QgsCurvePolygon::numInteriorRings
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
Definition: qgscurvepolygon.h:76
QgsAbstractGeometry::asGml3
virtual QDomElement asGml3(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML3 representation of the geometry.
QgsAbstractGeometry::operator=
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
Definition: qgsabstractgeometry.cpp:33
QgsAbstractGeometry::operator!=
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
QgsAbstractGeometry::draw
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
QgsWkbTypes::Polygon
@ Polygon
Definition: qgswkbtypes.h:73
QgsAbstractGeometry::childCount
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
Definition: qgsabstractgeometry.h:988
QgsVertexId
Utility class for identifying a unique vertex within a geometry.
Definition: qgsabstractgeometry.h:1033
QgsAbstractGeometry::perimeter
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
Definition: qgsabstractgeometry.cpp:137
QgsCurvePolygon::cast
const QgsCurvePolygon * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCurvePolygon.
Definition: qgscurvepolygon.h:271
QgsAbstractGeometry::transformVertices
virtual void transformVertices(const std::function< QgsPoint(const QgsPoint &) > &transform)
Transforms the vertices from the geometry in place, applying the transform function to every vertex.
Definition: qgsabstractgeometry.cpp:255
QgsAbstractGeometry::boundary
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
QgsCurvePolygon::mInteriorRings
QVector< QgsCurve * > mInteriorRings
Definition: qgscurvepolygon.h:306
QgsAbstractGeometry::operator==
virtual bool operator==(const QgsAbstractGeometry &other) const =0
QgsCoordinateTransform
Definition: qgscoordinatetransform.h:52
QgsAbstractGeometry::transform
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false) SIP_THROW(QgsCsException)=0
Transforms the geometry using a coordinate transform.
QgsWkbTypes::flatType
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:701
QgsAbstractGeometry::asGml2
virtual QDomElement asGml2(QDomDocument &doc, int precision=17, const QString &ns="gml", AxisOrder axisOrder=QgsAbstractGeometry::AxisOrder::XY) const =0
Returns a GML2 representation of the geometry.
qgssurface.h
QgsAbstractGeometry::calculateBoundingBox
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
Definition: qgsabstractgeometry.cpp:85