QGIS API Documentation  2.14.0-Essen
qgspointv2.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgspointv2.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 QGSPOINTV2_H
19 #define QGSPOINTV2_H
20 
21 #include "qgsabstractgeometryv2.h"
22 
23 /***************************************************************************
24  * This class is considered CRITICAL and any change MUST be accompanied with
25  * full unit tests in testqgsgeometry.cpp.
26  * See details in QEP #17
27  ****************************************************************************/
28 
34 class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
35 {
36  public:
37 
42  QgsPointV2( double x = 0.0, double y = 0.0 );
43 
46  explicit QgsPointV2( const QgsPoint& p );
47 
50  explicit QgsPointV2( QPointF p );
51 
59  QgsPointV2( QgsWKBTypes::Type type, double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
60 
61  bool operator==( const QgsPointV2& pt ) const;
62  bool operator!=( const QgsPointV2& pt ) const;
63 
68  double x() const { return mX; }
69 
74  double y() const { return mY; }
75 
80  double z() const { return mZ; }
81 
86  double m() const { return mM; }
87 
94  double &rx() { clearCache(); return mX; }
95 
102  double &ry() { clearCache(); return mY; }
103 
110  double &rz() { clearCache(); return mZ; }
111 
118  double &rm() { clearCache(); return mM; }
119 
124  void setX( double x ) { clearCache(); mX = x; }
125 
130  void setY( double y ) { clearCache(); mY = y; }
131 
138  void setZ( double z ) { clearCache(); mZ = z; }
139 
146  void setM( double m ) { clearCache(); mM = m; }
147 
151  QPointF toQPointF() const;
152 
153  //implementation of inherited methods
154  virtual QgsRectangle boundingBox() const override { return QgsRectangle( mX, mY, mX, mY ); }
155  virtual QString geometryType() const override { return "Point"; }
156  virtual int dimension() const override { return 0; }
157  virtual QgsPointV2* clone() const override;
158  void clear() override;
159  virtual bool fromWkb( QgsConstWkbPtr wkb ) override;
160  virtual bool fromWkt( const QString& wkt ) override;
161  int wkbSize() const override;
162  unsigned char* asWkb( int& binarySize ) const override;
163  QString asWkt( int precision = 17 ) const override;
164  QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const override;
165  QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const override;
166  QString asJSON( int precision = 17 ) const override;
167  void draw( QPainter& p ) const override;
169  void transform( const QTransform& t ) override;
170  virtual QgsCoordinateSequenceV2 coordinateSequence() const override;
171 
172  //low-level editing
173  virtual bool insertVertex( QgsVertexId position, const QgsPointV2& vertex ) override { Q_UNUSED( position ); Q_UNUSED( vertex ); return false; }
174  virtual bool moveVertex( QgsVertexId position, const QgsPointV2& newPos ) override;
175  virtual bool deleteVertex( QgsVertexId position ) override { Q_UNUSED( position ); return false; }
176 
177  double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const override;
178  bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const override;
179 
183  double vertexAngle( QgsVertexId vertex ) const override { Q_UNUSED( vertex ); return 0.0; }
184 
185  virtual int vertexCount( int /*part*/ = 0, int /*ring*/ = 0 ) const override { return 1; }
186  virtual int ringCount( int /*part*/ = 0 ) const override { return 1; }
187  virtual int partCount() const override { return 1; }
188  virtual QgsPointV2 vertexAt( QgsVertexId /*id*/ ) const override { return *this; }
189 
190  virtual bool addZValue( double zValue = 0 ) override;
191  virtual bool addMValue( double mValue = 0 ) override;
192  virtual bool dropZValue() override;
193  virtual bool dropMValue() override;
194  bool convertTo( QgsWKBTypes::Type type ) override;
195 
196  private:
197  double mX;
198  double mY;
199  double mZ;
200  double mM;
201 };
202 
203 #endif // QGSPOINTV2_H
double & rx()
Returns a reference to the x-coordinate of this point.
Definition: qgspointv2.h:94
A rectangle specified with double values.
Definition: qgsrectangle.h:35
virtual int ringCount(int=0) const override
Definition: qgspointv2.h:186
virtual bool dropMValue()=0
Drops any measure values which exist in the geometry.
void setZ(double z)
Sets the point's z-coordinate.
Definition: qgspointv2.h:138
virtual QgsCoordinateSequenceV2 coordinateSequence() const =0
Retrieves the sequence of geometries, rings and nodes.
double x() const
Returns the point's x-coordinate.
Definition: qgspointv2.h:68
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
bool operator!=(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
TransformDirection
Enum used to indicate the direction (forward or inverse) of the transform.
virtual QString asJSON(int precision=17) const =0
Returns a GeoJSON representation of the geometry.
virtual int dimension() const override
Returns the inherent dimension of the geometry.
Definition: qgspointv2.h:156
Abstract base class for all geometries.
void setX(double x)
Sets the point's x-coordinate.
Definition: qgspointv2.h:124
virtual bool dropZValue()=0
Drops any z-dimensions which exist in the geometry.
virtual int wkbSize() const =0
Returns the size of the WKB representation of the geometry.
void setY(double y)
Sets the point's y-coordinate.
Definition: qgspointv2.h:130
virtual bool addMValue(double mValue=0)=0
Adds a measure to the geometry, initialized to a preset value.
double y() const
Returns the point's y-coordinate.
Definition: qgspointv2.h:74
virtual void clear()=0
Clears the geometry, ie reset it to a null geometry.
virtual QString geometryType() const override
Returns a unique string representing the geometry type.
Definition: qgspointv2.h:155
virtual bool insertVertex(QgsVertexId position, const QgsPointV2 &vertex) override
Inserts a vertex into the geometry.
Definition: qgspointv2.h:173
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition: qgspointv2.h:175
Utility class for identifying a unique vertex within a geometry.
double z() const
Returns the point's z-coordinate.
Definition: qgspointv2.h:80
void setM(double m)
Sets the point's m-value.
Definition: qgspointv2.h:146
virtual bool fromWkb(QgsConstWkbPtr wkb)=0
Sets the geometry from a WKB string.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspointv2.h:34
virtual unsigned char * asWkb(int &binarySize) const =0
Returns a WKB representation of the geometry.
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform)=0
Transforms the geometry using a coordinate transform.
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual QDomElement asGML3(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML3 representation of the geometry.
virtual bool nextVertex(QgsVertexId &id, QgsPointV2 &vertex) const =0
Returns next vertex id and coordinates.
virtual bool fromWkt(const QString &wkt)=0
Sets the geometry from a WKT string.
A class to represent a point.
Definition: qgspoint.h:65
double & rz()
Returns a reference to the z-coordinate of this point.
Definition: qgspointv2.h:110
virtual QgsRectangle boundingBox() const override
Returns the minimal bounding box for the geometry.
Definition: qgspointv2.h:154
virtual bool convertTo(QgsWKBTypes::Type type)
Converts the geometry to a specified type.
double vertexAngle(QgsVertexId vertex) const override
Angle undefined.
Definition: qgspointv2.h:183
double & rm()
Returns a reference to the m value of this point.
Definition: qgspointv2.h:118
Class for doing transforms between two map coordinate systems.
virtual QString asWkt(int precision=17) const =0
Returns a WKT representation of the geometry.
double m() const
Returns the point's m value.
Definition: qgspointv2.h:86
virtual void clearCache() const
Clears any cached parameters associated with the geometry, eg bounding boxes.
virtual void draw(QPainter &p) const =0
Draws the geometry using the specified QPainter.
double ANALYSIS_EXPORT leftOf(Point3D *thepoint, Point3D *p1, Point3D *p2)
Returns whether 'thepoint' is left or right of the line from 'p1' to 'p2'.
virtual QgsPointV2 vertexAt(QgsVertexId) const override
Returns the point corresponding to a specified vertex id.
Definition: qgspointv2.h:188
virtual QDomElement asGML2(QDomDocument &doc, int precision=17, const QString &ns="gml") const =0
Returns a GML2 representation of the geometry.
double & ry()
Returns a reference to the y-coordinate of this point.
Definition: qgspointv2.h:102
virtual QgsAbstractGeometryV2 * clone() const =0
Clones the geometry by performing a deep copy.
virtual bool moveVertex(QgsVertexId position, const QgsPointV2 &newPos)=0
Moves a vertex within the geometry.
virtual double closestSegment(const QgsPointV2 &pt, QgsPointV2 &segmentPt, QgsVertexId &vertexAfter, bool *leftOf, double epsilon) const =0
Searches for the closest segment of the geometry to a given point.
virtual int vertexCount(int=0, int=0) const override
Definition: qgspointv2.h:185
virtual int partCount() const override
Returns count of parts contained in the geometry.
Definition: qgspointv2.h:187