mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Add QgsGeometry::isEmpty to test if underlying geometry exists
This commit is contained in:
parent
64e43f806a
commit
53218948b1
@ -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 );
|
||||
|
Loading…
x
Reference in New Issue
Block a user