Skip to content

Commit 9cfbba1

Browse files
committed
Add rx(), ry(), ... methods to QgsPointV2, add missing docs to class
Allows for directly modifying point's coordinates in place
1 parent 2623abc commit 9cfbba1

File tree

2 files changed

+239
-83
lines changed

2 files changed

+239
-83
lines changed

python/core/geometry/qgspointv2.sip

Lines changed: 149 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,156 @@
1+
/** \ingroup core
2+
* \class QgsPointV2
3+
* \brief Point geometry type, with support for z-dimension and m-values.
4+
* \note added in QGIS 2.10
5+
*/
6+
17
class QgsPointV2: public QgsAbstractGeometryV2
28
{
39
%TypeHeaderCode
410
#include <qgspointv2.h>
511
%End
612

7-
public:
8-
QgsPointV2( double x = 0.0, double y = 0.0 );
9-
QgsPointV2( const QgsPoint& p );
10-
QgsPointV2( QgsWKBTypes::Type type, double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
11-
12-
bool operator==( const QgsPointV2& pt ) const;
13-
bool operator!=( const QgsPointV2& pt ) const;
14-
15-
virtual QgsPointV2* clone() const;
16-
void clear();
17-
18-
double x() const;
19-
double y() const;
20-
double z() const;
21-
double m() const;
22-
23-
void setX( double x );
24-
void setY( double y );
25-
void setZ( double z );
26-
void setM( double m );
27-
28-
virtual QString geometryType() const;
29-
30-
//implementation of inherited methods
31-
virtual int dimension() const;
32-
33-
34-
virtual bool fromWkb( const unsigned char* wkb );
35-
virtual bool fromWkt( const QString& wkt );
36-
37-
int wkbSize() const;
38-
unsigned char* asWkb( int& binarySize ) const;
39-
QString asWkt( int precision = 17 ) const;
40-
QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
41-
QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
42-
QString asJSON( int precision = 17 ) const;
43-
44-
virtual QgsRectangle calculateBoundingBox() const;
45-
46-
void draw( QPainter& p ) const;
47-
void transform( const QgsCoordinateTransform& ct );
48-
void transform( const QTransform& t );
49-
50-
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const;
51-
52-
//low-level editing
53-
virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex );
54-
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos );
55-
virtual bool deleteVertex( const QgsVertexId& position );
56-
57-
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
58-
bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;
59-
60-
/** Angle undefined. Always returns 0.0
61-
@param vertex the vertex id
62-
@return 0.0*/
63-
double vertexAngle( const QgsVertexId& vertex ) const;
64-
65-
virtual int vertexCount(int part = 0, int ring = 0) const;
66-
virtual int ringCount(int part = 0) const;
67-
virtual int partCount() const;
68-
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;
69-
70-
virtual bool addZValue( double zValue = 0 );
71-
virtual bool addMValue( double mValue = 0 );
13+
public:
14+
15+
/** Construct a 2 dimensional point with an initial x and y coordinate.
16+
* @param x x-coordinate of point
17+
* @param y y-coordinate of point
18+
*/
19+
QgsPointV2( double x = 0.0, double y = 0.0 );
20+
21+
/** Construct a QgsPointV2 from a QgsPoint object
22+
*/
23+
QgsPointV2( const QgsPoint& p );
24+
25+
/** Construct a point with a specified type (eg PointZ, PointM) and initial x, y, z, and m values.
26+
* @param type point type
27+
* @param x x-coordinate of point
28+
* @param y y-coordinate of point
29+
* @param z z-coordinate of point, for PointZ or PointZM types
30+
* @param m m-value of point, for PointM or PointZM types
31+
*/
32+
QgsPointV2( QgsWKBTypes::Type type, double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
33+
34+
bool operator==( const QgsPointV2& pt ) const;
35+
bool operator!=( const QgsPointV2& pt ) const;
36+
37+
/** Returns the point's x-coordinate.
38+
* @see setX()
39+
* @see rx()
40+
*/
41+
double x() const;
42+
43+
/** Returns the point's y-coordinate.
44+
* @see setY()
45+
* @see ry()
46+
*/
47+
double y() const;
48+
49+
/** Returns the point's z-coordinate.
50+
* @see setZ()
51+
* @see rz()
52+
*/
53+
double z() const;
54+
55+
/** Returns the point's m value.
56+
* @see setM()
57+
* @see rm()
58+
*/
59+
double m() const;
60+
61+
/** Returns a reference to the x-coordinate of this point.
62+
* Using a reference makes it possible to directly manipulate x in place.
63+
* @see x()
64+
* @see setX()
65+
* @note not available in Python bindings
66+
*/
67+
//double &rx();
68+
69+
/** Returns a reference to the y-coordinate of this point.
70+
* Using a reference makes it possible to directly manipulate y in place.
71+
* @see y()
72+
* @see setY()
73+
* @note not available in Python bindings
74+
*/
75+
//double &ry();
76+
77+
/** Returns a reference to the z-coordinate of this point.
78+
* Using a reference makes it possible to directly manipulate z in place.
79+
* @see z()
80+
* @see setZ()
81+
* @note not available in Python bindings
82+
*/
83+
//double &rz();
84+
85+
/** Returns a reference to the m value of this point.
86+
* Using a reference makes it possible to directly manipulate m in place.
87+
* @see m()
88+
* @see setM()
89+
* @note not available in Python bindings
90+
*/
91+
//double &rm()
92+
93+
/** Sets the point's x-coordinate.
94+
* @see x()
95+
* @see rx()
96+
*/
97+
void setX( double x );
98+
99+
/** Sets the point's y-coordinate.
100+
* @see y()
101+
* @see ry()
102+
*/
103+
void setY( double y );
104+
105+
/** Sets the point's z-coordinate.
106+
* @see z()
107+
* @see rz()
108+
*/
109+
void setZ( double z );
110+
111+
/** Sets the point's m-value.
112+
* @see m()
113+
* @see rm()
114+
*/
115+
void setM( double m );
116+
117+
//implementation of inherited methods
118+
virtual QString geometryType() const;
119+
virtual int dimension() const;
120+
virtual QgsPointV2* clone() const;
121+
void clear();
122+
virtual bool fromWkb( const unsigned char* wkb );
123+
virtual bool fromWkt( const QString& wkt );
124+
int wkbSize() const;
125+
unsigned char* asWkb( int& binarySize ) const;
126+
QString asWkt( int precision = 17 ) const;
127+
QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
128+
QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const;
129+
QString asJSON( int precision = 17 ) const;
130+
virtual QgsRectangle calculateBoundingBox() const;
131+
void draw( QPainter& p ) const;
132+
void transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform );
133+
void transform( const QTransform& t );
134+
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord /Out/ ) const;
135+
136+
//low-level editing
137+
virtual bool insertVertex( const QgsVertexId& position, const QgsPointV2& vertex );
138+
virtual bool moveVertex( const QgsVertexId& position, const QgsPointV2& newPos );
139+
virtual bool deleteVertex( const QgsVertexId& position );
140+
141+
double closestSegment( const QgsPointV2& pt, QgsPointV2& segmentPt, QgsVertexId& vertexAfter, bool* leftOf, double epsilon ) const;
142+
bool nextVertex( QgsVertexId& id, QgsPointV2& vertex ) const;
143+
144+
/** Angle undefined. Always returns 0.0
145+
@param vertex the vertex id
146+
@return 0.0*/
147+
double vertexAngle( const QgsVertexId& vertex ) const;
148+
149+
virtual int vertexCount(int part = 0, int ring = 0) const;
150+
virtual int ringCount(int part = 0) const;
151+
virtual int partCount() const;
152+
virtual QgsPointV2 vertexAt( const QgsVertexId& id ) const;
153+
154+
virtual bool addZValue( double zValue = 0 );
155+
virtual bool addMValue( double mValue = 0 );
72156
};

src/core/geometry/qgspointv2.h

Lines changed: 90 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,132 @@
2222

2323
/** \ingroup core
2424
* \class QgsPointV2
25-
* \brief Point geometry type.
25+
* \brief Point geometry type, with support for z-dimension and m-values.
2626
* \note added in QGIS 2.10
27-
* \note this API is not considered stable and may change for 2.12
2827
*/
2928
class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
3029
{
3130
public:
31+
32+
/** Construct a 2 dimensional point with an initial x and y coordinate.
33+
* @param x x-coordinate of point
34+
* @param y y-coordinate of point
35+
*/
3236
QgsPointV2( double x = 0.0, double y = 0.0 );
37+
38+
/** Construct a QgsPointV2 from a QgsPoint object
39+
*/
3340
QgsPointV2( const QgsPoint& p );
41+
42+
/** Construct a point with a specified type (eg PointZ, PointM) and initial x, y, z, and m values.
43+
* @param type point type
44+
* @param x x-coordinate of point
45+
* @param y y-coordinate of point
46+
* @param z z-coordinate of point, for PointZ or PointZM types
47+
* @param m m-value of point, for PointM or PointZM types
48+
*/
3449
QgsPointV2( QgsWKBTypes::Type type, double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
3550

3651
bool operator==( const QgsPointV2& pt ) const;
3752
bool operator!=( const QgsPointV2& pt ) const;
3853

39-
virtual QgsPointV2* clone() const override;
40-
void clear() override;
41-
54+
/** Returns the point's x-coordinate.
55+
* @see setX()
56+
* @see rx()
57+
*/
4258
double x() const { return mX; }
59+
60+
/** Returns the point's y-coordinate.
61+
* @see setY()
62+
* @see ry()
63+
*/
4364
double y() const { return mY; }
65+
66+
/** Returns the point's z-coordinate.
67+
* @see setZ()
68+
* @see rz()
69+
*/
4470
double z() const { return mZ; }
71+
72+
/** Returns the point's m value.
73+
* @see setM()
74+
* @see rm()
75+
*/
4576
double m() const { return mM; }
4677

78+
/** Returns a reference to the x-coordinate of this point.
79+
* Using a reference makes it possible to directly manipulate x in place.
80+
* @see x()
81+
* @see setX()
82+
* @note not available in Python bindings
83+
*/
84+
double &rx() { return mX; }
85+
86+
/** Returns a reference to the y-coordinate of this point.
87+
* Using a reference makes it possible to directly manipulate y in place.
88+
* @see y()
89+
* @see setY()
90+
* @note not available in Python bindings
91+
*/
92+
double &ry() { return mY; }
93+
94+
/** Returns a reference to the z-coordinate of this point.
95+
* Using a reference makes it possible to directly manipulate z in place.
96+
* @see z()
97+
* @see setZ()
98+
* @note not available in Python bindings
99+
*/
100+
double &rz() { return mZ; }
101+
102+
/** Returns a reference to the m value of this point.
103+
* Using a reference makes it possible to directly manipulate m in place.
104+
* @see m()
105+
* @see setM()
106+
* @note not available in Python bindings
107+
*/
108+
double &rm() { return mM; }
109+
110+
/** Sets the point's x-coordinate.
111+
* @see x()
112+
* @see rx()
113+
*/
47114
void setX( double x ) { mX = x; }
115+
116+
/** Sets the point's y-coordinate.
117+
* @see y()
118+
* @see ry()
119+
*/
48120
void setY( double y ) { mY = y; }
121+
122+
/** Sets the point's z-coordinate.
123+
* @see z()
124+
* @see rz()
125+
*/
49126
void setZ( double z ) { mZ = z; }
50-
void setM( double m ) { mM = m; }
51127

52-
virtual QString geometryType() const override { return "Point"; }
128+
/** Sets the point's m-value.
129+
* @see m()
130+
* @see rm()
131+
*/
132+
void setM( double m ) { mM = m; }
53133

54134
//implementation of inherited methods
135+
virtual QString geometryType() const override { return "Point"; }
55136
virtual int dimension() const override { return 0; }
56-
57-
137+
virtual QgsPointV2* clone() const override;
138+
void clear() override;
58139
virtual bool fromWkb( const unsigned char* wkb ) override;
59140
virtual bool fromWkt( const QString& wkt ) override;
60-
61141
int wkbSize() const override;
62142
unsigned char* asWkb( int& binarySize ) const override;
63143
QString asWkt( int precision = 17 ) const override;
64144
QDomElement asGML2( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const override;
65145
QDomElement asGML3( QDomDocument& doc, int precision = 17, const QString& ns = "gml" ) const override;
66146
QString asJSON( int precision = 17 ) const override;
67-
68147
virtual QgsRectangle calculateBoundingBox() const override { return QgsRectangle( mX, mY, mX, mY );}
69-
70148
void draw( QPainter& p ) const override;
71-
72-
/** Transforms the geometry using a coordinate transform
73-
* @param ct coordinate transform
74-
@param d transformation direction
75-
*/
76149
void transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d = QgsCoordinateTransform::ForwardTransform ) override;
77150
void transform( const QTransform& t ) override;
78-
79151
virtual void coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const override;
80152

81153
//low-level editing

0 commit comments

Comments
 (0)