QGIS API Documentation  2.14.0-Essen
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 
22 {}
23 
25 {}
26 
28 {
29  if ( numPoints() == 0 )
30  return false;
31 
32  //don't consider M-coordinates when testing closedness
33  QgsPointV2 start = startPoint();
34  QgsPointV2 end = endPoint();
35  return ( qgsDoubleNear( start.x(), end.x(), 1E-8 ) &&
36  qgsDoubleNear( start.y(), end.y(), 1E-8 ) &&
37  qgsDoubleNear( start.z(), end.z(), 1E-8 ) );
38 }
39 
40 bool QgsCurveV2::isRing() const
41 {
42  return ( isClosed() && numPoints() >= 4 );
43 }
44 
46 {
47  if ( !mCoordinateSequence.isEmpty() )
48  return mCoordinateSequence;
49 
50  mCoordinateSequence.append( QgsRingSequenceV2() );
51  mCoordinateSequence.back().append( QgsPointSequenceV2() );
52  points( mCoordinateSequence.back().back() );
53 
54  return mCoordinateSequence;
55 }
56 
57 bool QgsCurveV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
58 {
59  if ( id.vertex < 0 )
60  {
61  id.vertex = 0;
62  if ( id.part < 0 )
63  {
64  id.part = 0;
65  }
66  if ( id.ring < 0 )
67  {
68  id.ring = 0;
69  }
70  }
71  else
72  {
73  if ( id.vertex + 1 >= numPoints() )
74  {
75  return false;
76  }
77  ++id.vertex;
78  }
79  return pointAt( id.vertex, vertex, id.type );
80 }
81 
83 {
84  return curveToLine();
85 }
86 
88 {
89  QgsPointV2 v;
91  pointAt( id.vertex, v, type );
92  return v;
93 }
94 
96 {
97  if ( mBoundingBox.isNull() )
98  {
99  mBoundingBox = calculateBoundingBox();
100  }
101  return mBoundingBox;
102 }
103 
A rectangle specified with double values.
Definition: qgsrectangle.h:35
double x() const
Returns the point&#39;s x-coordinate.
Definition: qgspointv2.h:68
virtual bool isRing() const
Returns true if the curve is a ring.
Definition: qgscurvev2.cpp:40
bool isNull() const
test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Abstract base class for all geometries.
QgsCurveV2 * segmentize() const override
Returns a geometry without curves.
Definition: qgscurvev2.cpp:82
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:285
double y() const
Returns the point&#39;s y-coordinate.
Definition: qgspointv2.h:74
virtual int numPoints() const =0
Returns the number of points in the curve.
void append(const T &value)
Utility class for identifying a unique vertex within a geometry.
double z() const
Returns the point&#39;s z-coordinate.
Definition: qgspointv2.h:80
virtual QgsRectangle calculateBoundingBox() const
Default calculator for the minimal bounding box for the geometry.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
bool isEmpty() const
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
Definition: qgscurvev2.cpp:57
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 QgsLineStringV2 * curveToLine() const =0
Returns a new line string geometry corresponding to a segmentized approximation of the curve...
virtual QgsPointV2 endPoint() const =0
Returns the end point of the curve.
virtual ~QgsCurveV2()
Definition: qgscurvev2.cpp:24
virtual bool isClosed() const
Returns true if the curve is closed.
Definition: qgscurvev2.cpp:27
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:87
virtual QgsCoordinateSequenceV2 coordinateSequence() const override
Retrieves the sequence of geometries, rings and nodes.
Definition: qgscurvev2.cpp:45
Abstract base class for curved geometry type.
Definition: qgscurvev2.h:32
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:95
QList< QgsPointV2 > QgsPointSequenceV2