QGIS API Documentation  2.10.1-Pisa
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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  return ( numPoints() > 0 && ( startPoint() == endPoint() ) );
30 }
31 
32 bool QgsCurveV2::isRing() const
33 {
34  return ( isClosed() && numPoints() >= 4 );
35 }
36 
38 {
39  coord.clear();
41  points( pts );
42  QList< QList<QgsPointV2> > ptsList;
43  ptsList.append( pts );
44  coord.append( ptsList );
45 }
46 
47 bool QgsCurveV2::nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const
48 {
49  if ( id.vertex < 0 )
50  {
51  id.vertex = 0;
52  if ( id.part < 0 )
53  {
54  id.part = 0;
55  }
56  if ( id.ring < 0 )
57  {
58  id.ring = 0;
59  }
60  }
61  else
62  {
63  if ( id.vertex + 1 >= numPoints() )
64  {
65  return false;
66  }
67  ++id.vertex;
68  }
69  return pointAt( id.vertex, vertex, id.type );
70 }
71 
72 double QgsCurveV2::area() const
73 {
74  if ( !isClosed() )
75  {
76  return 0.0;
77  }
78 
79  double area = 0.0;
80  sumUpArea( area );
81  return qAbs( area );
82 }
83 
85 {
86  return curveToLine();
87 }
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:32
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:37
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.
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:47
virtual void sumUpArea(double &sum) const =0
Calculates the area of 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 double area() const override
Returns the area of the geometry.
Definition: qgscurvev2.cpp:72
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:84
virtual QgsPointV2 startPoint() const =0
Returns the starting point of the curve.