Skip to content
Permalink
Browse files
When make_polygon is called on a geometry which is already a polygon,
just return that geometry instead of NULL
  • Loading branch information
nyalldawson committed Nov 1, 2021
1 parent 30b1ff2 commit 09dfe8c93876a54bdd3ead7f5b47ede633c9110d
Showing with 5 additions and 0 deletions.
  1. +4 −0 src/core/expression/qgsexpressionfunction.cpp
  2. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -2840,6 +2840,10 @@ static QVariant fcnMakePolygon( const QVariantList &values, const QgsExpressionC
}

QgsGeometry outerRing = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );

if ( outerRing.type() == QgsWkbTypes::PolygonGeometry )
return outerRing; // if it's already a polygon we have nothing to do

if ( outerRing.type() != QgsWkbTypes::LineGeometry || outerRing.isNull() )
return QVariant();

@@ -1116,6 +1116,7 @@ class TestQgsExpression: public QObject
QTest::newRow( "make_line array empty" ) << "geom_to_wkt(make_line(array()))" << false << QVariant();
QTest::newRow( "make_polygon bad" ) << "make_polygon(make_point(2,4))" << false << QVariant();
QTest::newRow( "make_polygon" ) << "geom_to_wkt(make_polygon(geom_from_wkt('LINESTRING( 0 0, 0 1, 1 1, 1 0, 0 0 )')))" << false << QVariant( "Polygon ((0 0, 0 1, 1 1, 1 0, 0 0))" );
QTest::newRow( "make_polygon already polygon" ) << "geom_to_wkt(make_polygon(geom_from_wkt('POLYGON(( 0 0, 0 1, 1 1, 1 0, 0 0 ))')))" << false << QVariant( "Polygon ((0 0, 0 1, 1 1, 1 0, 0 0))" );
QTest::newRow( "make_polygon rings" ) << "geom_to_wkt(make_polygon(geom_from_wkt('LINESTRING( 0 0, 0 1, 1 1, 1 0, 0 0 )'),geom_from_wkt('LINESTRING( 0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2 0.1, 0.1 0.1 )'),geom_from_wkt('LINESTRING( 0.8 0.8, 0.8 0.9, 0.9 0.9, 0.9 0.8, 0.8 0.8 )')))" << false
<< QVariant( "Polygon ((0 0, 0 1, 1 1, 1 0, 0 0),(0.1 0.1, 0.1 0.2, 0.2 0.2, 0.2 0.1, 0.1 0.1),(0.8 0.8, 0.8 0.9, 0.9 0.9, 0.9 0.8, 0.8 0.8))" );
QTest::newRow( "make_triangle not geom" ) << "geom_to_wkt(make_triangle(make_point(2,4), 'g', make_point(3,5)))" << true << QVariant();

0 comments on commit 09dfe8c

Please sign in to comment.