mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
add expression is_empty_or_null
This commit is contained in:
parent
780d9e9fd7
commit
c7bc3af96c
11
resources/function_help/json/is_empty_or_null
Normal file
11
resources/function_help/json/is_empty_or_null
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "is_empty_or_null",
|
||||
"type": "function",
|
||||
"description": "Returns true if a geometry is NULL or empty (without coordinates) or false otherwise. This function is like the expression '$geometry IS NULL or is_empty($geometry)'",
|
||||
"arguments": [ {"arg":"geom","description":"a geometry"}],
|
||||
"examples": [ { "expression":"is_empty_or_null(NULL)", "returns":"true"},
|
||||
{ "expression":"is_empty_or_null(geom_from_wkt('LINESTRING(0 0, 1 1, 2 2)'))", "returns":"false"},
|
||||
{ "expression":"is_empty_or_null(geom_from_wkt('LINESTRING EMPTY'))", "returns":"true"},
|
||||
{ "expression":"is_empty_or_null(geom_from_wkt('POINT(7 4)'))", "returns":"false"},
|
||||
{ "expression":"is_empty_or_null(geom_from_wkt('POINT EMPTY'))", "returns":"true"} ]
|
||||
}
|
||||
@ -3077,6 +3077,15 @@ static QVariant fcnIsEmpty( const QVariantList &values, const QgsExpressionConte
|
||||
return QVariant::fromValue( fGeom.isEmpty() );
|
||||
}
|
||||
|
||||
static QVariant fcnIsEmptyOrNull( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
||||
{
|
||||
if ( values.at( 0 ).isNull() )
|
||||
return QVariant::fromValue( true );
|
||||
|
||||
QgsGeometry fGeom = QgsExpressionUtils::getGeometry( values.at( 0 ), parent );
|
||||
return QVariant::fromValue( fGeom.isNull() || fGeom.isEmpty() );
|
||||
}
|
||||
|
||||
static QVariant fcnRelate( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
|
||||
{
|
||||
if ( values.length() < 2 || values.length() > 3 )
|
||||
@ -5606,6 +5615,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
|
||||
<< 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( "is_empty_or_null" ), QgsExpressionFunction::ParameterList() << QgsExpressionFunction::Parameter( QStringLiteral( "geom" ) ), fcnIsEmptyOrNull, QStringLiteral( "GeometryGroup" ), QString(), false, QSet<QString>(), false, QStringList(), true )
|
||||
<< 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" ) ),
|
||||
|
||||
@ -986,6 +986,12 @@ class TestQgsExpression: public QObject
|
||||
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( "is_empty_or_null not geom" ) << "is_empty_or_null('g')" << true << QVariant();
|
||||
QTest::newRow( "is_empty_or_null null" ) << "is_empty_or_null(NULL)" << false << QVariant( true );
|
||||
QTest::newRow( "is_empty_or_null point" ) << "is_empty_or_null(geom_from_wkt('POINT(1 2)'))" << false << QVariant( false );
|
||||
QTest::newRow( "is_empty_or_null empty point" ) << "is_empty_or_null(geom_from_wkt('POINT EMPTY'))" << false << QVariant( true );
|
||||
QTest::newRow( "is_empty_or_null polygon" ) << "is_empty_or_null(geom_from_wkt('POLYGON((-1 -1, 4 0, 4 2, 0 2, -1 -1))'))" << false << QVariant( false );
|
||||
QTest::newRow( "is_empty_or_null empty polygon" ) << "is_empty_or_null(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