Skip to content
Permalink
Browse files
add test for multi line geometries with a single part and update the …
…error string
  • Loading branch information
Koyaani authored and nyalldawson committed Aug 23, 2021
1 parent 0ad4a7d commit 1b8be09c2b0b9def9b1e5f4bd54c5e4ed7544954
Showing with 2 additions and 1 deletion.
  1. +1 −1 src/core/expression/qgsexpressionfunction.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -3609,7 +3609,7 @@ static QVariant fcnStraightDistance2d( const QVariantList &values, const QgsExpr
const QgsCurve *curve = geom.constGet() ? qgsgeometry_cast< const QgsCurve * >( geom.constGet()->simplifiedTypeRef() ) : nullptr;
if ( !curve )
{
parent->setEvalErrorString( QObject::tr( "Function `straight_distance_2d` requires a line geometry." ) );
parent->setEvalErrorString( QObject::tr( "Function `straight_distance_2d` requires a line geometry or a multi line geometry with a single part." ) );
return QVariant();
}

@@ -1329,6 +1329,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "straight_distance_2d null" ) << "straight_distance_2d(NULL)" << false << QVariant();
QTest::newRow( "straight_distance_2d point" ) << "straight_distance_2d(geom_from_wkt('POINT(1 2)'))" << true << QVariant();
QTest::newRow( "straight_distance_2d multi linestring" ) << "straight_distance_2d(geom_from_wkt('MULTILINESTRING( (0 0, 1 1), (2 2, 3 3) )'))" << true << QVariant();
QTest::newRow( "straight_distance_2d multi linestring with single part" ) << "straight_distance_2d(geom_from_wkt('MULTILINESTRING( (0 0, 0 1) ) )'))" << false << QVariant( 1.0 );
QTest::newRow( "straight_distance_2d linestring" ) << "straight_distance_2d(geom_from_wkt('LINESTRING(1 0, 4 4)'))" << false << QVariant( 5.0 );
QTest::newRow( "straight_distance_2d linestring" ) << "round(straight_distance_2d(geom_from_wkt('LINESTRING(1 4, 3 5, 5 0)')), 3)" << false << QVariant( 5.657 );
QTest::newRow( "straight_distance_2d closed linestring" ) << "straight_distance_2d(geom_from_wkt('LINESTRING(2 2, 3 6, 2 2)'))" << false << QVariant( 0.0 );

0 comments on commit 1b8be09

Please sign in to comment.