QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
qgscurvev2.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscurvev2.cpp
3  --------------
4  begin : November 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 #include "qgscurvev2.h"
19 #include "qgslinestringv2.h"
20 #include "qgspointv2.h"
21 #include "qgsmultipointv2.h"
22 
24 {}
25 
27 {}
28 
30 {
31  if ( numPoints() == 0 )
32  return false;
33 
34  //don't consider M-coordinates when testing closedness
35  QgsPointV2 start = startPoint();
36  QgsPointV2 end = endPoint();
37  return ( qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
38  qgsDoubleNear( start.y(), end.y(), 1E-8 ) &&
39  qgsDoubleNear( start.z(), end.z(), 1E-8 ) );
40 }
41 
42 bool QgsCurveV2::isRing() const
43 {
44  return ( isClosed() && numPoints() >= 4 );
45 }
46 
48 {
49  if ( !mCoordinateSequence.isEmpty() )
50  return mCoordinateSequence;
51 
52  mCoordinateSequence.append( QgsRingSequenceV2() );
53  mCoordinateSequence.back().append( QgsPointSequenceV2() );
54  points( mCoordinateSequence.back().back() );
55 
56  return mCoordinateSequence;
57 }
58 
59 bool QgsCurveV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
60 {
61  if ( id.vertex < 0 )
62  {
63  id.vertex = 0;
64  if ( id.part < 0 )
65  {
66  id.part = 0;
67  }
68  if ( id.ring < 0 )
69  {
70  id.ring = 0;
71  }
72  }
73  else
74  {
75  if ( id.vertex + 1 >= numPoints() )
76  {
77  return false;
78  }
79  ++id.vertex;
80  }
81  return pointAt( id.vertex, vertex, id.type );
82 }
83 
85 {
86  if ( isEmpty() )
87  return nullptr;
88 
89  if ( isClosed() )
90  return nullptr;
91 
92  QgsMultiPointV2* multiPoint = new QgsMultiPointV2();
93  multiPoint->addGeometry( new QgsPointV2( startPoint() ) );
94  multiPoint->addGeometry( new QgsPointV2( endPoint() ) );
95  return multiPoint;
96 }
97 
98 QgsCurveV2* QgsCurveV2::segmentize( double tolerance, SegmentationToleranceType toleranceType ) const
99 {
100  return curveToLine( tolerance, toleranceType );
101 }
102 
104 {
105  QgsPointV2 v;
107  pointAt( id.vertex, v, type );
108  return v;
109 }
110 
112 {
113  if ( mBoundingBox.isNull() )
114  {
115  mBoundingBox = calculateBoundingBox();
116  }
117  return mBoundingBox;
118 }
119 
virtual bool addGeometry(QgsAbstractGeometryV2 *g) override
Adds a geometry and takes ownership.
A rectangle specified with double values.
Definition: qgsrectangle.h:35
bool isEmpty() const
Returns true if the geometry is empty.
SegmentationToleranceType
Segmentation tolerance as maximum angle or maximum difference between approximation and circle...
Abstract base class for all geometries.
Multi point geometry collection.
double z() const
Returns the point&#39;s z-coordinate.
Definition: qgspointv2.h:80
double y() const
Returns the point&#39;s y-coordinate.
Definition: qgspointv2.h:74
virtual bool isRing() const
Returns true if the curve is a ring.
Definition: qgscurvev2.cpp:42
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Compare two doubles (but allow some difference)
Definition: qgis.h:353
virtual int numPoints() const =0
Returns the number of points in the curve.
void append(const T &value)
virtual bool isClosed() const
Returns true if the curve is closed.
Definition: qgscurvev2.cpp:29
Utility class for identifying a unique vertex within a geometry.
QgsCurveV2 * segmentize(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const override
Returns a geometry without curves.
Definition: qgscurvev2.cpp:98
virtual QgsAbstractGeometryV2 * boundary() const override
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
Definition: qgscurvev2.cpp:84
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
bool isEmpty() const
double x() const
Returns the point&#39;s x-coordinate.
Definition: qgspointv2.h:68
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
Definition: qgscurvev2.cpp:59
QList< QgsPointSequenceV2 > QgsRingSequenceV2
virtual bool pointAt(int node, QgsPointV2 &point, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
virtual ~QgsCurveV2()
Definition: qgscurvev2.cpp:26
virtual QgsLineStringV2 * curveToLine(double tolerance=M_PI_2/90, SegmentationToleranceType toleranceType=MaximumAngle) const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
virtual QgsPointV2 startPoint() const =0
Returns the starting point of the curve.
virtual QgsPointV2 vertexAt(QgsVertexId id) const override
Returns the point corresponding to a specified vertex id.
Definition: qgscurvev2.cpp:103
virtual QgsCoordinateSequenceV2 coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition: qgscurvev2.cpp:47
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
T & back()
virtual void points(QgsPointSequenceV2 &pt) const =0
Returns a list of points within the curve.
virtual QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Definition: qgscurvev2.cpp:111
QList< QgsPointV2 > QgsPointSequenceV2