Skip to content
Permalink
Browse files

Merge pull request #38831 from pblottiere/fcngeomz_null

Check if a point is 3D before returning its z value
  • Loading branch information
pblottiere committed Sep 30, 2020
2 parents 8351e06 + 1aee462 commit 9cf95ff49a08a3ebed7c518c67f2015bfb6a78db
Showing with 8 additions and 0 deletions.
  1. +6 −0 src/core/expression/qgsexpressionfunction.cpp
  2. +2 −0 tests/src/core/testqgsexpression.cpp
@@ -2349,6 +2349,9 @@ static QVariant fcnGeomZ( const QVariantList &values, const QgsExpressionContext
if ( geom.isNull() )
return QVariant(); //or 0?

if ( !geom.constGet()->is3D() )
return QVariant();

//if single point, return the point's z coordinate
if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() )
{
@@ -2377,6 +2380,9 @@ static QVariant fcnGeomM( const QVariantList &values, const QgsExpressionContext
if ( geom.isNull() )
return QVariant(); //or 0?

if ( !geom.constGet()->isMeasure() )
return QVariant();

//if single point, return the point's m value
if ( geom.type() == QgsWkbTypes::PointGeometry && !geom.isMultipart() )
{
@@ -1159,8 +1159,10 @@ class TestQgsExpression: public QObject
QTest::newRow( "y point" ) << "y(make_point(2.2,4.4))" << false << QVariant( 4.4 );
QTest::newRow( "z point" ) << "z(make_point(2.2,4.4,6.6))" << false << QVariant( 6.6 );
QTest::newRow( "z not point" ) << "z(geom_from_wkt('LINESTRING(2 0,2 2, 3 2, 3 0)'))" << false << QVariant();
QTest::newRow( "z no z coord" ) << "z( geom_from_wkt( 'POINT ( 0 0 )' ) )" << false << QVariant();
QTest::newRow( "m point" ) << "m(make_point_m(2.2,4.4,7.7))" << false << QVariant( 7.7 );
QTest::newRow( "m not point" ) << "m(geom_from_wkt('LINESTRING(2 0,2 2, 3 2, 3 0)'))" << false << QVariant();
QTest::newRow( "m no m coord" ) << "m( geom_from_wkt( 'POINT ( 0 0 )' ) )" << false << QVariant();
QTest::newRow( "x line" ) << "x(geom_from_wkt('LINESTRING(2 0,2 2, 3 2, 3 0)'))" << false << QVariant( 2.5 );
QTest::newRow( "x line" ) << "y(geom_from_wkt('LINESTRING(2 0,2 2, 3 2, 3 0)'))" << false << QVariant( 1.2 );
QTest::newRow( "x polygon" ) << "x(geom_from_wkt('POLYGON((2 0,2 2, 3 2, 3 0, 2 0))'))" << false << QVariant( 2.5 );

0 comments on commit 9cf95ff

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