QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 SIP_HOLDGIL;
47  int dimension() const override SIP_HOLDGIL;
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  int wkbSize( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
55  QByteArray asWkb( QgsAbstractGeometry::WkbFlags flags = QgsAbstractGeometry::WkbFlags() ) const override;
56  QString asWkt( int precision = 17 ) const override;
57  QDomElement asGml2( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
58  QDomElement asGml3( QDomDocument &doc, int precision = 17, const QString &ns = "gml", QgsAbstractGeometry::AxisOrder axisOrder = QgsAbstractGeometry::AxisOrder::XY ) const override;
59  json asJsonObject( int precision = 17 ) const override SIP_SKIP;
60  QString asKml( int precision = 17 ) const override;
61  void normalize() final SIP_HOLDGIL;
62 
63  //surface interface
64  double area() const override SIP_HOLDGIL;
65  double perimeter() const override SIP_HOLDGIL;
66  QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
67  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
68  QgsCurvePolygon *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
69  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
70  bool boundingBoxIntersects( const QgsRectangle &rectangle ) const override SIP_HOLDGIL;
71 
72  //curve polygon interface
73 
80  {
81  return mInteriorRings.size();
82  }
83 
90  {
91  return mExteriorRing.get();
92  }
93 
94 #ifndef SIP_RUN
95 
102  const QgsCurve *interiorRing( int i ) const SIP_HOLDGIL
103  {
104  if ( i < 0 || i >= mInteriorRings.size() )
105  {
106  return nullptr;
107  }
108  return mInteriorRings.at( i );
109  }
110 #else
111 
120  SIP_PYOBJECT interiorRing( int i ) SIP_HOLDGIL SIP_TYPEHINT( QgsCurve );
121  % MethodCode
122  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
123  {
124  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
125  sipIsErr = 1;
126  }
127  else
128  {
129  return sipConvertFromType( const_cast< QgsCurve * >( sipCpp->interiorRing( a0 ) ), sipType_QgsCurve, NULL );
130  }
131  % End
132 #endif
133 
140  virtual QgsPolygon *toPolygon( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const SIP_FACTORY;
141 
150  virtual void setExteriorRing( QgsCurve *ring SIP_TRANSFER );
151 
153  void setInteriorRings( const QVector<QgsCurve *> &rings SIP_TRANSFER );
155  virtual void addInteriorRing( QgsCurve *ring SIP_TRANSFER );
156 
157 #ifndef SIP_RUN
158 
165  bool removeInteriorRing( int ringIndex );
166 #else
167 
177  bool removeInteriorRing( int i );
178  % MethodCode
179  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
180  {
181  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
182  sipIsErr = 1;
183  }
184  else
185  {
186  return PyBool_FromLong( sipCpp->removeInteriorRing( a0 ) );
187  }
188  % End
189 #endif
190 
198  void removeInteriorRings( double minimumAllowedArea = -1 );
199 
207  void removeInvalidRings();
208 
217  void forceRHR();
218 
219  QPainterPath asQPainterPath() const override;
220  void draw( QPainter &p ) const override;
222  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
223 
224  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
225  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
226  bool deleteVertex( QgsVertexId position ) override;
227 
228  QgsCoordinateSequence coordinateSequence() const override;
229  int nCoordinates() const override;
230  int vertexNumberFromVertexId( QgsVertexId id ) const override;
231  bool isEmpty() const override SIP_HOLDGIL;
232  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;
233 
234  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
235  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
236  bool hasCurvedSegments() const override;
237 
243  QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
244 
250  double vertexAngle( QgsVertexId vertex ) const override;
251 
252  int vertexCount( int part = 0, int ring = 0 ) const override;
253  int ringCount( int part = 0 ) const override SIP_HOLDGIL;
254  int partCount() const override SIP_HOLDGIL;
255  QgsPoint vertexAt( QgsVertexId id ) const override;
256  double segmentLength( QgsVertexId startVertex ) const override;
257 
258  bool addZValue( double zValue = 0 ) override;
259  bool addMValue( double mValue = 0 ) override;
260  bool dropZValue() override;
261  bool dropMValue() override;
262  void swapXy() override;
263 
264  QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
265 
266  bool transform( QgsAbstractGeometryTransformer *transformer, QgsFeedback *feedback = nullptr ) override;
267 
268 #ifndef SIP_RUN
269  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
270  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
271 
279  inline static const QgsCurvePolygon *cast( const QgsAbstractGeometry *geom )
280  {
281  if ( !geom )
282  return nullptr;
283 
284  QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
285  if ( flatType == QgsWkbTypes::CurvePolygon
286  || flatType == QgsWkbTypes::Polygon
287  || flatType == QgsWkbTypes::Triangle )
288  return static_cast<const QgsCurvePolygon *>( geom );
289  return nullptr;
290  }
291 #endif
292 
294 
295 #ifdef SIP_RUN
296  SIP_PYOBJECT __repr__();
297  % MethodCode
298  QString wkt = sipCpp->asWkt();
299  if ( wkt.length() > 1000 )
300  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
301  QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( wkt );
302  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
303  % End
304 #endif
305 
306  protected:
307 
308  int childCount() const override;
309  QgsAbstractGeometry *childGeometry( int index ) const override;
310  int compareToSameClass( const QgsAbstractGeometry *other ) const final;
311 
312  protected:
313 
314  std::unique_ptr< QgsCurve > mExteriorRing;
315  QVector<QgsCurve *> mInteriorRings;
316 
317  QgsRectangle calculateBoundingBox() const override;
318 };
319 
320 // clazy:excludeall=qstring-allocations
321 
322 #endif // QGSCURVEPOLYGON_H
An abstract base class for classes which transform geometries by transforming input points to output ...
Abstract base class for all geometries.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
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.
virtual bool boundingBoxIntersects(const QgsRectangle &rectangle) const SIP_HOLDGIL
Returns true if the bounding box of this geometry intersects with a rectangle.
AxisOrder
Axis order for GML generation.
virtual QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership.
virtual double perimeter() const
Returns the planar, 2-dimensional perimeter of the geometry.
virtual QByteArray asWkb(WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns a WKB representation of the geometry.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
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.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
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.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
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.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
virtual json asJsonObject(int precision=17) const
Returns a json object representation of the geometry.
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.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
virtual QPainterPath asQPainterPath() const =0
Returns the geometry represented as a QPainterPath.
virtual void normalize()=0
Reorganizes the geometry into a normalized form (or "canonical" form).
virtual QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
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...
QgsWkbTypes::Type wkbType() const SIP_HOLDGIL
Returns the WKB type of the geometry.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
virtual bool operator==(const QgsAbstractGeometry &other) const =0
virtual QString asKml(int precision=17) const =0
Returns a KML representation of the geometry.
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...
virtual int wkbSize(QgsAbstractGeometry::WkbFlags flags=QgsAbstractGeometry::WkbFlags()) const =0
Returns the length of the QByteArray returned by asWkb()
virtual double area() const
Returns the planar, 2-dimensional area of the geometry.
virtual int compareToSameClass(const QgsAbstractGeometry *other) const =0
Compares to an other geometry of the same class, and returns a integer for sorting of the two geometr...
A const WKB pointer.
Definition: qgswkbptr.h:138
Class for doing transforms between two map coordinate systems.
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
@ ForwardTransform
Transform from source to destination CRS.
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:66
Curve polygon geometry type.
static const QgsCurvePolygon * cast(const QgsAbstractGeometry *geom)
Cast the geom to a QgsCurvePolygon.
QVector< QgsCurve * > mInteriorRings
const QgsCurve * interiorRing(int i) const SIP_HOLDGIL
Retrieves an interior ring from the curve polygon.
const QgsCurve * exteriorRing() const SIP_HOLDGIL
Returns the curve polygon's exterior ring.
int numInteriorRings() const SIP_HOLDGIL
Returns the number of interior rings contained with the curve polygon.
std::unique_ptr< QgsCurve > mExteriorRing
Abstract base class for curved geometry type.
Definition: qgscurve.h:36
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:45
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:49
Polygon geometry type.
Definition: qgspolygon.h:34
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Surface geometry type.
Definition: qgssurface.h:34
virtual QgsPolygon * surfaceToPolygon() const =0
Gets a polygon representation of this surface.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
static Type flatType(Type type) SIP_HOLDGIL
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:702
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
CORE_EXPORT std::unique_ptr< QgsPolygon > toPolygon(const QgsMeshFace &face, const QVector< QgsMeshVertex > &vertices)
Returns face as polygon geometry, caller is responsible for delete.
#define str(x)
Definition: qgis.cpp:37
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:218
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_HOLDGIL
Definition: qgis_sip.h:157
#define SIP_FACTORY
Definition: qgis_sip.h:76
QVector< QgsRingSequence > QgsCoordinateSequence
double closestSegment(const QgsPolylineXY &pl, const QgsPointXY &pt, int &vertexAfter, double epsilon)
Definition: qgstracer.cpp:68
int precision
Utility class for identifying a unique vertex within a geometry.