Skip to content
Permalink
Browse files

Fix reverse expression function doesn't handle multicurve geometries

  • Loading branch information
nyalldawson committed May 18, 2018
1 parent 0153434 commit 610d99c3382a0aa2e7ac3dfd49d68492152a5985
Showing with 27 additions and 5 deletions.
  1. +26 −5 src/core/expression/qgsexpressionfunction.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -2662,12 +2662,33 @@ static QVariant fcnReverse( const QVariantList &values, const QgsExpressionConte
if ( fGeom.isNull() )
return QVariant();

const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( fGeom.constGet() );
if ( !curve )
return QVariant();
QVariant result;
if ( !fGeom.isMultipart() )
{
const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( fGeom.constGet() );
if ( !curve )
return QVariant();

QgsCurve *reversed = curve->reversed();
QVariant result = reversed ? QVariant::fromValue( QgsGeometry( reversed ) ) : QVariant();
QgsCurve *reversed = curve->reversed();
result = reversed ? QVariant::fromValue( QgsGeometry( reversed ) ) : QVariant();
}
else
{
const QgsGeometryCollection *collection = qgsgeometry_cast< const QgsGeometryCollection *>( fGeom.constGet() );
std::unique_ptr< QgsGeometryCollection > reversed( collection->createEmptyWithSameType() );
for ( int i = 0; i < collection->numGeometries(); ++i )
{
if ( const QgsCurve *curve = qgsgeometry_cast<const QgsCurve * >( collection->geometryN( i ) ) )
{
reversed->addGeometry( curve->reversed() );
}
else
{
reversed->addGeometry( collection->geometryN( i )->clone() );
}
}
result = reversed ? QVariant::fromValue( QgsGeometry( std::move( reversed ) ) ) : QVariant();
}
return result;
}

@@ -851,6 +851,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "reverse point" ) << "reverse(geom_from_wkt('POINT(1 2)'))" << false << QVariant();
QTest::newRow( "reverse polygon" ) << "reverse(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant();
QTest::newRow( "reverse line" ) << "geom_to_wkt(reverse(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)')))" << false << QVariant( "LineString (2 2, 1 1, 0 0)" );
QTest::newRow( "reverse multiline" ) << "geom_to_wkt(reverse(geom_from_wkt('MULTILINESTRING((0 0, 1 1, 2 2),(10 10, 11 11, 12 12))')))" << false << QVariant( "MultiLineString ((2 2, 1 1, 0 0),(12 12, 11 11, 10 10))" );
QTest::newRow( "exterior_ring not geom" ) << "exterior_ring('g')" << true << QVariant();
QTest::newRow( "exterior_ring null" ) << "exterior_ring(NULL)" << false << QVariant();
QTest::newRow( "exterior_ring point" ) << "exterior_ring(geom_from_wkt('POINT(1 2)'))" << false << QVariant();

0 comments on commit 610d99c

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