Skip to content
Permalink
Browse files

Add QgsGeometry::isEmpty to test if underlying geometry exists

  • Loading branch information
nyalldawson committed Jun 13, 2015
1 parent 64e43f8 commit 53218948b1686149d31642e5962f503c0e457512
@@ -45,14 +45,23 @@ class QgsGeometry

/** Returns the underlying geometry store.
* @note added in QGIS 2.10
* @see setGeometry
*/
const QgsAbstractGeometryV2* geometry() const;

/** Sets the underlying geometry store. Ownership of geometry is transferred.
* @note added in QGIS 2.10
* @see geometry
*/
void setGeometry( QgsAbstractGeometryV2* geometry /Transfer/ );

/** Returns true if the geometry is empty (ie, contains no underlying geometry
* accessible via @link geometry @endlink).
* @see geometry
* @note added in QGIS 2.10
*/
bool isEmpty() const;

/** Creates a new geometry from a WKT string */
static QgsGeometry* fromWkt( QString wkt ) /Factory/;
/** Creates a new geometry from a QgsPoint object*/
@@ -149,6 +149,11 @@ void QgsGeometry::setGeometry( QgsAbstractGeometryV2* geometry )
d->geometry = geometry;
}

bool QgsGeometry::isEmpty() const
{
return !d || !d->geometry;
}

QgsGeometry* QgsGeometry::fromWkt( QString wkt )
{
QgsAbstractGeometryV2* geom = QgsGeometryImport::geomFromWkt( wkt );
@@ -91,14 +91,23 @@ class CORE_EXPORT QgsGeometry

/** Returns the underlying geometry store.
* @note added in QGIS 2.10
* @see setGeometry
*/
const QgsAbstractGeometryV2* geometry() const;

/** Sets the underlying geometry store. Ownership of geometry is transferred.
* @note added in QGIS 2.10
* @see geometry
*/
void setGeometry( QgsAbstractGeometryV2* geometry );

/** Returns true if the geometry is empty (ie, contains no underlying geometry
* accessible via @link geometry @endlink).
* @see geometry
* @note added in QGIS 2.10
*/
bool isEmpty() const;

/** Creates a new geometry from a WKT string */
static QgsGeometry* fromWkt( QString wkt );
/** Creates a new geometry from a QgsPoint object*/
@@ -54,6 +54,7 @@ class TestQgsGeometry : public QObject
void copy();
void assignment();
void asVariant(); //test conversion to and from a QVariant
void isEmpty();

void fromQgsPoint();
void fromQPoint();
@@ -286,6 +287,18 @@ void TestQgsGeometry::asVariant()
QCOMPARE( fromVar3.geometry()->vertexAt( QgsVertexId( 0, 0, 0 ) ).y(), 2.0 );
}

void TestQgsGeometry::isEmpty()
{
QgsGeometry geom;
QVERIFY( geom.isEmpty() );

geom.setGeometry( new QgsPointV2( 1.0, 2.0 ) );
QVERIFY( !geom.isEmpty() );

geom.setGeometry( 0 );
QVERIFY( geom.isEmpty() );
}

void TestQgsGeometry::fromQgsPoint()
{
QgsPoint point( 1.0, 2.0 );

0 comments on commit 5321894

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