QGIS API Documentation  2.12.0-Lyon
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  coord.clear();
49  points( pts );
50  QList< QList<QgsPointV2> > ptsList;
51  ptsList.append( pts );
52  coord.append( ptsList );
53 }
54 
55 bool QgsCurveV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
56 {
57  if ( id.vertex < 0 )
58  {
59  id.vertex = 0;
60  if ( id.part < 0 )
61  {
62  id.part = 0;
63  }
64  if ( id.ring < 0 )
65  {
66  id.ring = 0;
67  }
68  }
69  else
70  {
71  if ( id.vertex + 1 >= numPoints() )
72  {
73  return false;
74  }
75  ++id.vertex;
76  }
77  return pointAt( id.vertex, vertex, id.type );
78 }
79 
81 {
82  return curveToLine();
83 }
84 
86 {
87  QgsPointV2 v;
89  pointAt( id.vertex, v, type );
90  return v;
91 }
double x() const
Definition: qgspointv2.h:42
virtual void points(QList< QgsPointV2 > &pt) const =0
Returns a list of points within the curve.
virtual bool isRing() const
Returns true if the curve is a ring.
Definition: qgscurvev2.cpp:40
Abstract base class for all geometries.
virtual void coordinateSequence(QList< QList< QList< QgsPointV2 > > > &coord) const override
Retrieves the sequence of geometries, rings and nodes.
Definition: qgscurvev2.cpp:45
bool qgsDoubleNear(double a, double b, double epsilon=4 *DBL_EPSILON)
Definition: qgis.h:268
double y() const
Definition: qgspointv2.h:43
virtual int numPoints() const =0
Returns the number of points in the curve.
void append(const T &value)
virtual bool pointAt(int i, QgsPointV2 &vertex, QgsVertexId::VertexType &type) const =0
Returns the point and vertex id of a point within the curve.
Utility class for identifying a unique vertex within a geometry.
double z() const
Definition: qgspointv2.h:44
Point geometry type.
Definition: qgspointv2.h:29
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const override
Returns next vertex id and coordinates.
Definition: qgscurvev2.cpp:55
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
QgsAbstractGeometryV2 * segmentize() const override
Returns a version of the geometry without curves.
Definition: qgscurvev2.cpp:80
virtual QgsPointV2 vertexAt(const QgsVertexId &id) const override
Returns the point corresponding to a specified vertex id.
Definition: qgscurvev2.cpp:85
virtual QgsPointV2 startPoint() const =0
Returns the starting point of the curve.