QGIS API Documentation  3.4.15-Madeira (e83d02e274)
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 QGSCURVEPOLYGONV2_H
19 #define QGSCURVEPOLYGONV2_H
20 
21 #include "qgis_core.h"
22 #include "qgis.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() 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  QString asJson( int precision = 17 ) const override;
59 
60  //surface interface
61  double area() const override;
62  double perimeter() const override;
63  QgsPolygon *surfaceToPolygon() const override SIP_FACTORY;
64  QgsAbstractGeometry *boundary() const override SIP_FACTORY;
65  QgsCurvePolygon *snappedToGrid( double hSpacing, double vSpacing, double dSpacing = 0, double mSpacing = 0 ) const override SIP_FACTORY;
66  bool removeDuplicateNodes( double epsilon = 4 * std::numeric_limits<double>::epsilon(), bool useZValues = false ) override;
67 
68  //curve polygon interface
69 
75  int numInteriorRings() const
76  {
77  return mInteriorRings.size();
78  }
79 
85  const QgsCurve *exteriorRing() const
86  {
87  return mExteriorRing.get();
88  }
89 
90 #ifndef SIP_RUN
91 
98  const QgsCurve *interiorRing( int i ) const
99  {
100  if ( i < 0 || i >= mInteriorRings.size() )
101  {
102  return nullptr;
103  }
104  return mInteriorRings.at( i );
105  }
106 #else
107 
116  SIP_PYOBJECT interiorRing( int i ) SIP_TYPEHINT( QgsCurve );
117  % MethodCode
118  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
119  {
120  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
121  sipIsErr = 1;
122  }
123  else
124  {
125  return sipConvertFromType( const_cast< QgsCurve * >( sipCpp->interiorRing( a0 ) ), sipType_QgsCurve, NULL );
126  }
127  % End
128 #endif
129 
135  virtual QgsPolygon *toPolygon( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const SIP_FACTORY;
136 
145  virtual void setExteriorRing( QgsCurve *ring SIP_TRANSFER );
146 
148  void setInteriorRings( const QVector<QgsCurve *> &rings SIP_TRANSFER );
150  virtual void addInteriorRing( QgsCurve *ring SIP_TRANSFER );
151 
152 #ifndef SIP_RUN
153 
160  bool removeInteriorRing( int ringIndex );
161 #else
162 
172  bool removeInteriorRing( int i );
173  % MethodCode
174  if ( a0 < 0 || a0 >= sipCpp->numInteriorRings() )
175  {
176  PyErr_SetString( PyExc_IndexError, QByteArray::number( a0 ) );
177  sipIsErr = 1;
178  }
179  else
180  {
181  return PyBool_FromLong( sipCpp->removeInteriorRing( a0 ) );
182  }
183  % End
184 #endif
185 
193  void removeInteriorRings( double minimumAllowedArea = -1 );
194 
202  void removeInvalidRings();
203 
212  void forceRHR();
213 
214  void draw( QPainter &p ) const override;
216  void transform( const QTransform &t, double zTranslate = 0.0, double zScale = 1.0, double mTranslate = 0.0, double mScale = 1.0 ) override;
217 
218  bool insertVertex( QgsVertexId position, const QgsPoint &vertex ) override;
219  bool moveVertex( QgsVertexId position, const QgsPoint &newPos ) override;
220  bool deleteVertex( QgsVertexId position ) override;
221 
222  QgsCoordinateSequence coordinateSequence() const override;
223  int nCoordinates() const override;
224  int vertexNumberFromVertexId( QgsVertexId id ) const override;
225  bool isEmpty() const override;
226  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;
227 
228  bool nextVertex( QgsVertexId &id, QgsPoint &vertex SIP_OUT ) const override;
229  void adjacentVertices( QgsVertexId vertex, QgsVertexId &previousVertex SIP_OUT, QgsVertexId &nextVertex SIP_OUT ) const override;
230  bool hasCurvedSegments() const override;
231 
236  QgsAbstractGeometry *segmentize( double tolerance = M_PI_2 / 90, SegmentationToleranceType toleranceType = MaximumAngle ) const override SIP_FACTORY;
237 
243  double vertexAngle( QgsVertexId vertex ) const override;
244 
245  int vertexCount( int part = 0, int ring = 0 ) const override;
246  int ringCount( int part = 0 ) const override;
247  int partCount() const override;
248  QgsPoint vertexAt( QgsVertexId id ) const override;
249  double segmentLength( QgsVertexId startVertex ) const override;
250 
251  bool addZValue( double zValue = 0 ) override;
252  bool addMValue( double mValue = 0 ) override;
253  bool dropZValue() override;
254  bool dropMValue() override;
255  void swapXy() override;
256 
257  QgsCurvePolygon *toCurveType() const override SIP_FACTORY;
258 
259 #ifndef SIP_RUN
260  void filterVertices( const std::function< bool( const QgsPoint & ) > &filter ) override;
261  void transformVertices( const std::function< QgsPoint( const QgsPoint & ) > &transform ) override;
262 
270  inline const QgsCurvePolygon *cast( const QgsAbstractGeometry *geom ) const
271  {
272  if ( !geom )
273  return nullptr;
274 
275  QgsWkbTypes::Type flatType = QgsWkbTypes::flatType( geom->wkbType() );
276  if ( flatType == QgsWkbTypes::CurvePolygon
277  || flatType == QgsWkbTypes::Polygon
278  || flatType == QgsWkbTypes::Triangle )
279  return static_cast<const QgsCurvePolygon *>( geom );
280  return nullptr;
281  }
282 #endif
283 
285 
286 #ifdef SIP_RUN
287  SIP_PYOBJECT __repr__();
288  % MethodCode
289  QString wkt = sipCpp->asWkt();
290  if ( wkt.length() > 1000 )
291  wkt = wkt.left( 1000 ) + QStringLiteral( "..." );
292  QString str = QStringLiteral( "<QgsCurvePolygon: %1>" ).arg( wkt );
293  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
294  % End
295 #endif
296 
297  protected:
298 
299  int childCount() const override;
300  QgsAbstractGeometry *childGeometry( int index ) const override;
301 
302  protected:
303 
304  std::unique_ptr< QgsCurve > mExteriorRing;
305  QVector<QgsCurve *> mInteriorRings;
306 
307  QgsRectangle calculateBoundingBox() const override;
308 };
309 
310 // clazy:excludeall=qstring-allocations
311 
312 #endif // QGSCURVEPOLYGONV2_H
const QgsCurve * exteriorRing() const
Returns the curve polygon&#39;s exterior ring.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
int precision
virtual bool isEmpty() const
Returns true if the geometry is empty.
A rectangle specified with double values.
Definition: qgsrectangle.h:40
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 int vertexNumberFromVertexId(QgsVertexId id) const =0
Returns the vertex number corresponding to a vertex id.
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 deleteVertex(QgsVertexId position)=0
Deletes a vertex within the geometry.
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 QgsAbstractGeometry * toCurveType() const =0
Returns the geometry converted to the more generic curve type.
virtual QByteArray asWkb() const =0
Returns a WKB representation of the geometry.
QgsAbstractGeometry & operator=(const QgsAbstractGeometry &geom)
virtual bool hasCurvedSegments() const
Returns true if the geometry contains curved segments.
virtual bool insertVertex(QgsVertexId position, const QgsPoint &vertex)=0
Inserts a vertex into the geometry.
QVector< QgsRingSequence > QgsCoordinateSequence
virtual bool operator==(const QgsAbstractGeometry &other) const =0
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
QgsWkbTypes::Type wkbType() const
Returns the WKB type of the geometry.
virtual double vertexAngle(QgsVertexId vertex) const =0
Returns approximate angle at a vertex.
Curve polygon geometry type.
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
virtual QgsAbstractGeometry * createEmptyWithSameType() const =0
Creates a new geometry with the same class and same WKB type as the original and transfers ownership...
virtual QString asJson(int precision=17) const =0
Returns a GeoJSON representation of the geometry.
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.
virtual QgsAbstractGeometry * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
virtual bool nextVertex(QgsVertexId &id, QgsPoint &vertex) const =0
Returns next vertex id and coordinates.
virtual QgsAbstractGeometry * clone() const =0
Clones the geometry by performing a deep copy.
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:206
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
virtual QgsAbstractGeometry * childGeometry(int index) const
Returns pointer to child geometry (for geometries with child geometries - i.e.
QVector< QgsCurve * > mInteriorRings
virtual QgsPolygon * surfaceToPolygon() const =0
Gets a polygon representation of this surface.
virtual bool operator!=(const QgsAbstractGeometry &other) const =0
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
virtual int nCoordinates() const
Returns the number of nodes contained in the geometry.
virtual double closestSegment(const QgsPoint &pt, QgsPoint &segmentPt, QgsVertexId &vertexAfter, int *leftOf=nullptr, double epsilon=4 *std::numeric_limits< double >::epsilon()) const =0
Searches for the closest segment of the geometry to a given point.
virtual double segmentLength(QgsVertexId startVertex) const =0
Returns the length of the segment of the geometry which begins at startVertex.
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...
virtual QgsAbstractGeometry * segmentize(double tolerance=M_PI/180., SegmentationToleranceType toleranceType=MaximumAngle) const
Returns a version of the geometry without curves.
Utility class for identifying a unique vertex within a geometry.
const QgsCurvePolygon * cast(const QgsAbstractGeometry *geom) const
Cast the geom to a QgsCurvePolygon.
#define SIP_TRANSFER
Definition: qgis_sip.h:36
virtual int ringCount(int part=0) const =0
Returns the number of rings of which this geometry is built.
Abstract base class for curved geometry type.
Definition: qgscurve.h:35
#define SIP_FACTORY
Definition: qgis_sip.h:69
Abstract base class for all geometries.
virtual int dimension() const =0
Returns the inherent dimension of the geometry.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:37
AxisOrder
Axis order for GML generation.
virtual QgsCoordinateSequence coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
virtual void adjacentVertices(QgsVertexId vertex, QgsVertexId &previousVertex, QgsVertexId &nextVertex) const =0
Returns the vertices adjacent to a specified vertex within a geometry.
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
virtual bool moveVertex(QgsVertexId position, const QgsPoint &newPos)=0
Moves a vertex within the geometry.
virtual double perimeter() const
Returns the perimeter of the geometry.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
#define SIP_OUT
Definition: qgis_sip.h:51
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
virtual int vertexCount(int part=0, int ring=0) const =0
Returns the number of vertices of which this geometry is built.
virtual double area() const
Returns the area of the geometry.
Class for doing transforms between two map coordinate systems.
#define SIP_THROW(name)
Definition: qgis_sip.h:177
Transform from source to destination CRS.
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...
Custom exception class for Coordinate Reference System related exceptions.
Definition: qgsexception.h:65
virtual int childCount() const
Returns number of child geometries (for geometries with child geometries) or child points (for geomet...
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
Polygon geometry type.
Definition: qgspolygon.h:31
virtual QgsPoint vertexAt(QgsVertexId id) const =0
Returns the point corresponding to a specified vertex id.
std::unique_ptr< QgsCurve > mExteriorRing
static Type flatType(Type type)
Returns the flat type for a WKB type.
Definition: qgswkbtypes.h:565
virtual void swapXy()=0
Swaps the x and y coordinates from the geometry.
double ANALYSIS_EXPORT leftOf(const QgsPoint &thepoint, const QgsPoint *p1, const QgsPoint *p2)
Returns whether &#39;thepoint&#39; is left or right of the line from &#39;p1&#39; to &#39;p2&#39;. Negativ values mean left a...
Definition: MathUtils.cpp:292
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual int partCount() const =0
Returns count of parts contained in 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 QString geometryType() const =0
Returns a unique string representing the geometry type.
virtual bool fromWkb(QgsConstWkbPtr &wkb)=0
Sets the geometry from a WKB string.