mirror of
https://github.com/qgis/QGIS.git
synced 2025-12-15 00:07:25 -05:00
Add expression is_empty(geom)
This commit is contained in:
parent
5910a7b9f1
commit
23c9a61a99
10
resources/function_help/json/is_empty
Normal file
10
resources/function_help/json/is_empty
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "is_empty",
|
||||
"type": "function",
|
||||
"description": "Returns true if a geometry is empty (without coordinates) or false if a is empty."
|
||||
"arguments": [ {"arg":"geom","description":"a geometry"}],
|
||||
"examples": [ { "expression":"is_empty(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))", "returns":"false"},
|
||||
{ "expression":"is_empty(geom_from_wkt('LINESTRING EMPTY'))", "returns":"true"}]
|
||||
{ "expression":"is_empty(geom_from_wkt('POINT(7 4)'))", "returns":"false"}]
|
||||
{ "expression":"is_empty(geom_from_wkt('POINT EMPTY'))", "returns":"true"}]
|
||||
}
|
||||
@ -3068,6 +3068,15 @@ static QVariant fcnIsClosed( const QVariantList &values, const QgsExpressionCont
|
||||
return QVariant::fromValue( curve->isClosed() );
|
||||
}
|
||||
|
||||
static QVariant fcnIsEmpty( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
||||
{
|
||||
QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
|
||||
if ( fGeom.isNull() )
|
||||
return QVariant();
|
||||
|
||||
return QVariant::fromValue( fGeom.isEmpty() );
|
||||
}
|
||||
|
||||
static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
||||
{
|
||||
if ( values.length() < 2 || values.length() > 3 )
|
||||
@ -5596,6 +5605,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "bounds_width" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geom" ) ), fcnBoundsWidth, QStringLiteral( "GeometryGroup" ) )
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "bounds_height" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geom" ) ), fcnBoundsHeight, QStringLiteral( "GeometryGroup" ) )
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "is_closed" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geom" ) ), fcnIsClosed, QStringLiteral( "GeometryGroup" ) )
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "is_empty" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geom" ) ), fcnIsEmpty, QStringLiteral( "GeometryGroup" ) )
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "convex_hull" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ), fcnConvexHull, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>(), false, QStringList() << QStringLiteral( "convexHull" ) )
|
||||
<< new QgsStaticExpressionFunction( QStringLiteral( "oriented_bbox" ), QgsExpressionFunction::ParameterList()
|
||||
<< QgsExpressionFunction::Parameter( QStringLiteral( "geometry" ) ),
|
||||
|
||||
@ -980,6 +980,12 @@ class TestQgsExpression: public QObject
|
||||
QTest::newRow( "is_closed multiline" ) << "is_closed(geom_from_wkt('MultiLineString ((6501338.13976828 4850981.51459331, 6501343.09036573 4850984.01453377, 6501338.13976828 4850988.96491092, 6501335.63971657 4850984.01453377, 6501338.13976828 4850981.51459331))'))" << false << QVariant( true );
|
||||
QTest::newRow( "is_closed multiline" ) << "is_closed(geom_from_wkt('MultiLineString ((6501338.13976828 4850981.51459331, 6501343.09036573 4850984.01453377, 6501338.13976828 4850988.96491092, 6501335.63971657 4850984.01453377, 6501438.13976828 4850981.51459331))'))" << false << QVariant( false );
|
||||
QTest::newRow( "is_closed multiline" ) << "is_closed(geom_from_wkt('MultiLineString EMPTY'))" << false << QVariant();
|
||||
QTest::newRow( "is_empty not geom" ) << "is_empty('g')" << true << QVariant();
|
||||
QTest::newRow( "is_empty null" ) << "is_empty(NULL)" << false << QVariant();
|
||||
QTest::newRow( "is_empty point" ) << "is_empty(geom_from_wkt('POINT(1 2)'))" << false << QVariant( false );
|
||||
QTest::newRow( "is_empty empty point" ) << "is_empty(geom_from_wkt('POINT EMPTY'))" << false << QVariant( true );
|
||||
QTest::newRow( "is_empty polygon" ) << "is_empty(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant( false );
|
||||
QTest::newRow( "is_empty empty polygon" ) << "is_empty(geom_from_wkt('POLYGON EMPTY'))" << false << QVariant( true );
|
||||
QTest::newRow( "collect_geometries none" ) << "geom_to_wkt(collect_geometries())" << false << QVariant( "" );
|
||||
QTest::newRow( "collect_geometries not" ) << "geom_to_wkt(collect_geometries(45))" << true << QVariant();
|
||||
QTest::newRow( "collect_geometries one" ) << "geom_to_wkt(collect_geometries(make_point(4,5)))" << false << QVariant( "MultiPoint ((4 5))" );
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user