QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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  bool transformZ = false ) override;
170  void transform( const QTransform& t ) override;
171  virtual QgsCoordinateSequenceV2 coordinateSequence() const override;
172  virtual int nCoordinates() const override { return 1; }
173  virtual QgsAbstractGeometryV2* boundary() const override;
174 
175  //low-level editing
176  virtual bool insertVertex( QgsVertexId position, const QgsPointV2& vertex ) override { Q_UNUSED( position ); Q_UNUSED( vertex ); return false; }
177  virtual bool moveVertex( QgsVertexId position, const QgsPointV2& newPos ) override;
178  virtual bool deleteVertex( QgsVertexId position ) override { Q_UNUSED( position ); return false; }
179 
180  double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const override;
181  bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const override;
182 
186  double vertexAngle( QgsVertexId vertex ) const override { Q_UNUSED( vertex ); return 0.0; }
187 
188  virtual int vertexCount( int /*part*/ = 0, int /*ring*/ = 0 ) const override { return 1; }
189  virtual int ringCount( int /*part*/ = 0 ) const override { return 1; }
190  virtual int partCount() const override { return 1; }
191  virtual QgsPointV2 vertexAt( QgsVertexId /*id*/ ) const override { return *this; }
192 
193  virtual bool addZValue( double zValue = 0 ) override;
194  virtual bool addMValue( double mValue = 0 ) override;
195  virtual bool dropZValue() override;
196  virtual bool dropMValue() override;
197  bool convertTo( QgsWKBTypes::Type type ) override;
198 
199  private:
200  double mX;
201  double mY;
202  double mZ;
203  double mM;
204 };
205 
206 #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:189
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.
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.
double z() const
Returns the point's z-coordinate.
Definition: qgspointv2.h:80
double y() const
Returns the point's y-coordinate.
Definition: qgspointv2.h:74
virtual void clearCache() const
Clears any cached parameters associated with the geometry, eg bounding boxes.
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.
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:176
virtual bool deleteVertex(QgsVertexId position) override
Deletes a vertex within the geometry.
Definition: qgspointv2.h:178
Utility class for identifying a unique vertex within a geometry.
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.
double x() const
Returns the point's x-coordinate.
Definition: qgspointv2.h:68
virtual bool addZValue(double zValue=0)=0
Adds a z-dimension to the geometry, initialized to a preset value.
virtual int nCoordinates() const override
Returns the number of nodes contained in the geometry.
Definition: qgspointv2.h:172
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:117
virtual QgsAbstractGeometryV2 * boundary() const =0
Returns the closure of the combinatorial boundary of the geometry (ie the topological boundary of the...
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:186
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.
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:191
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:188
virtual int partCount() const override
Returns count of parts contained in the geometry.
Definition: qgspointv2.h:190
double m() const
Returns the point's m value.
Definition: qgspointv2.h:86
virtual void transform(const QgsCoordinateTransform &ct, QgsCoordinateTransform::TransformDirection d=QgsCoordinateTransform::ForwardTransform, bool transformZ=false)=0
Transforms the geometry using a coordinate transform.