Skip to content
Permalink
Browse files

Add an easy to use Z/M default value constructor to QgsPoint

  • Loading branch information
m-kuhn committed Jun 14, 2017
1 parent 4eae087 commit 7e487190e8386ec0180b04fec590c9f0e231ecb9
@@ -22,9 +22,36 @@ class QgsPoint: QgsAbstractGeometry
%End
public:

QgsPoint( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
%Docstring
Construct a point with the provided initial coordinate values.
QgsPoint( double x = 0.0, double y = 0.0, SIP_PYOBJECT z = Py_None, SIP_PYOBJECT m = Py_None ) [( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 )];
% Docstring
Construct a point with the provided initial coordinate values.

If only z and m are not specified, the type will be a 2D point.
If any or both of the others are specified, the Z and M values will be added accordingly.
%End
%MethodCode
double z;
double m;

if ( a2 == Py_None )
{
z = std::numeric_limits<double>::quiet_NaN();
}
else
{
z = PyFloat_AsDouble( a2 );
}

if ( a3 == Py_None )
{
m = std::numeric_limits<double>::quiet_NaN();
}
else
{
m = PyFloat_AsDouble( a3 );
}

sipCpp = new sipQgsPoint( a0, a1, z, m );
%End

explicit QgsPoint( const QgsPointXY &p );
@@ -38,7 +38,17 @@ QgsPoint::QgsPoint( double x, double y, double z, double m )
, mZ( z )
, mM( m )
{
mWkbType = QgsWkbTypes::Point;
if ( qIsNaN( z ) )
{
if ( qIsNaN( m ) )
mWkbType = QgsWkbTypes::Point;
else
mWkbType = QgsWkbTypes::PointM;
}
else if ( qIsNaN( m ) )
mWkbType = QgsWkbTypes::PointZ;
else
mWkbType = QgsWkbTypes::PointZM;
}

QgsPoint::QgsPoint( const QgsPointXY &p )
@@ -46,8 +46,44 @@ class CORE_EXPORT QgsPoint: public QgsAbstractGeometry

/**
* Construct a point with the provided initial coordinate values.
*
* If only z and m are not specified, the type will be a 2D point.
* If any or both of the others are specified, the Z and M values will be added accordingly.
*/
QgsPoint( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 );
QgsPoint( double x = 0.0, double y = 0.0, double z = std::numeric_limits<double>::quiet_NaN(), double m = std::numeric_limits<double>::quiet_NaN() ) SIP_SKIP;
#ifdef SIP_RUN
QgsPoint( double x = 0.0, double y = 0.0, SIP_PYOBJECT z = Py_None, SIP_PYOBJECT m = Py_None ) [( double x = 0.0, double y = 0.0, double z = 0.0, double m = 0.0 )];
% Docstring
Construct a point with the provided initial coordinate values.

If only z and m are not specified, the type will be a 2D point.
If any or both of the others are specified, the Z and M values will be added accordingly.
% End
% MethodCode
double z;
double m;

if ( a2 == Py_None )
{
z = std::numeric_limits<double>::quiet_NaN();
}
else
{
z = PyFloat_AsDouble( a2 );
}

if ( a3 == Py_None )
{
m = std::numeric_limits<double>::quiet_NaN();
}
else
{
m = PyFloat_AsDouble( a3 );
}

sipCpp = new sipQgsPoint( a0, a1, z, m );
% End
#endif

/** Construct a QgsPoint from a QgsPointXY object
*/
@@ -4129,6 +4129,12 @@ def testCompare(self):
self.assertFalse(QgsGeometry.compare(lp, lp2))
self.assertTrue(QgsGeometry.compare(lp, lp2, 1e-6))

def testPoint(self):
self.assertEqual(QgsPoint(1, 2).wkbType(), QgsWkbTypes.Point)
self.assertEqual(QgsPoint(1, 2, 3).wkbType(), QgsWkbTypes.PointZ)
self.assertEqual(QgsPoint(1, 2, m=3).wkbType(), QgsWkbTypes.PointM)
self.assertEqual(QgsPoint(1, 2, 3, 4).wkbType(), QgsWkbTypes.PointZM)


if __name__ == '__main__':
unittest.main()

0 comments on commit 7e48719

Please sign in to comment.
You can’t perform that action at this time.