From c07f02d6dc814bc2857811a5600cd848e17ea137 Mon Sep 17 00:00:00 2001 From: Matthias Kuhn Date: Mon, 6 Jun 2016 09:39:09 +0200 Subject: [PATCH] QgsAbstractGeometryV2::wkbType always returns a valid type --- .../core/geometry/qgsabstractgeometryv2.sip | 5 --- python/core/geometry/qgscircularstringv2.sip | 1 - python/core/geometry/qgscompoundcurvev2.sip | 1 - python/core/geometry/qgscurvepolygonv2.sip | 1 - .../core/geometry/qgsgeometrycollectionv2.sip | 1 - python/core/geometry/qgslinestringv2.sip | 1 - python/core/geometry/qgsmulticurvev2.sip | 1 - python/core/geometry/qgsmultilinestringv2.sip | 1 - python/core/geometry/qgsmultipointv2.sip | 1 - python/core/geometry/qgsmultipolygonv2.sip | 1 - python/core/geometry/qgsmultisurfacev2.sip | 1 - python/core/geometry/qgspointv2.sip | 1 - python/core/geometry/qgspolygonv2.sip | 2 +- src/core/geometry/qgsabstractgeometryv2.h | 9 +---- src/core/geometry/qgscircularstringv2.cpp | 4 +- src/core/geometry/qgscircularstringv2.h | 1 - src/core/geometry/qgscompoundcurvev2.cpp | 5 ++- src/core/geometry/qgscompoundcurvev2.h | 1 - src/core/geometry/qgscurvepolygonv2.cpp | 7 ++-- src/core/geometry/qgscurvepolygonv2.h | 1 - src/core/geometry/qgsgeometrycollectionv2.cpp | 5 +-- src/core/geometry/qgsgeometrycollectionv2.h | 1 - src/core/geometry/qgslinestringv2.cpp | 2 +- src/core/geometry/qgslinestringv2.h | 1 - src/core/geometry/qgsmulticurvev2.cpp | 6 +++ src/core/geometry/qgsmulticurvev2.h | 2 +- src/core/geometry/qgsmultilinestringv2.cpp | 6 +++ src/core/geometry/qgsmultilinestringv2.h | 2 +- src/core/geometry/qgsmultipointv2.cpp | 6 +++ src/core/geometry/qgsmultipointv2.h | 2 +- src/core/geometry/qgsmultipolygonv2.cpp | 6 +++ src/core/geometry/qgsmultipolygonv2.h | 2 +- src/core/geometry/qgsmultisurfacev2.cpp | 6 +++ src/core/geometry/qgsmultisurfacev2.h | 2 +- src/core/geometry/qgspointv2.cpp | 1 - src/core/geometry/qgspointv2.h | 1 - src/core/geometry/qgspolygonv2.cpp | 6 +++ src/core/geometry/qgspolygonv2.h | 2 +- tests/src/core/testqgsgeometry.cpp | 29 +++++++------- tests/src/python/test_qgsgeometry.py | 39 +++++++++++++++++++ tests/src/python/test_qgssymbolv2.py | 2 +- 41 files changed, 111 insertions(+), 64 deletions(-) diff --git a/python/core/geometry/qgsabstractgeometryv2.sip b/python/core/geometry/qgsabstractgeometryv2.sip index 56900a4f019..60f26e9a7ba 100644 --- a/python/core/geometry/qgsabstractgeometryv2.sip +++ b/python/core/geometry/qgsabstractgeometryv2.sip @@ -114,11 +114,6 @@ class QgsAbstractGeometryV2 */ QgsWKBTypes::Type wkbType() const; - /** Returns the flat WKB type of the geometry class. Corresponds to information obtained from - * geometryType(). - */ - virtual QgsWKBTypes::Type flatWkbType() const = 0; - /** Returns the WKT type string of the geometry. * @see geometryType * @see wkbType diff --git a/python/core/geometry/qgscircularstringv2.sip b/python/core/geometry/qgscircularstringv2.sip index ef9ef42ff28..3d23aaddf4e 100644 --- a/python/core/geometry/qgscircularstringv2.sip +++ b/python/core/geometry/qgscircularstringv2.sip @@ -12,7 +12,6 @@ class QgsCircularStringV2: public QgsCurveV2 virtual bool operator!=( const QgsCurveV2& other ) const; virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual int dimension() const; virtual QgsCircularStringV2* clone() const; virtual void clear(); diff --git a/python/core/geometry/qgscompoundcurvev2.sip b/python/core/geometry/qgscompoundcurvev2.sip index 0cf7fda805f..4aacff1ddf6 100644 --- a/python/core/geometry/qgscompoundcurvev2.sip +++ b/python/core/geometry/qgscompoundcurvev2.sip @@ -14,7 +14,6 @@ class QgsCompoundCurveV2: public QgsCurveV2 virtual bool operator!=( const QgsCurveV2& other ) const; virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual int dimension() const; virtual QgsCompoundCurveV2* clone() const; virtual void clear(); diff --git a/python/core/geometry/qgscurvepolygonv2.sip b/python/core/geometry/qgscurvepolygonv2.sip index ec696475f66..b4c4c7ac69c 100644 --- a/python/core/geometry/qgscurvepolygonv2.sip +++ b/python/core/geometry/qgscurvepolygonv2.sip @@ -11,7 +11,6 @@ class QgsCurvePolygonV2: public QgsSurfaceV2 ~QgsCurvePolygonV2(); virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual int dimension() const; virtual QgsCurvePolygonV2* clone() const; void clear(); diff --git a/python/core/geometry/qgsgeometrycollectionv2.sip b/python/core/geometry/qgsgeometrycollectionv2.sip index 8b2a2d17d47..9263be59813 100644 --- a/python/core/geometry/qgsgeometrycollectionv2.sip +++ b/python/core/geometry/qgsgeometrycollectionv2.sip @@ -29,7 +29,6 @@ class QgsGeometryCollectionV2: public QgsAbstractGeometryV2 //methods inherited from QgsAbstractGeometry virtual int dimension() const; virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual void clear(); /** Adds a geometry and takes ownership. Returns true in case of success.*/ diff --git a/python/core/geometry/qgslinestringv2.sip b/python/core/geometry/qgslinestringv2.sip index 4ff8dcc99f9..b973b1193f7 100644 --- a/python/core/geometry/qgslinestringv2.sip +++ b/python/core/geometry/qgslinestringv2.sip @@ -113,7 +113,6 @@ class QgsLineStringV2: public QgsCurveV2 //reimplemented methods virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual int dimension() const; virtual QgsLineStringV2* clone() const /Factory/; virtual void clear(); diff --git a/python/core/geometry/qgsmulticurvev2.sip b/python/core/geometry/qgsmulticurvev2.sip index b0991151a3b..f40774bba69 100644 --- a/python/core/geometry/qgsmulticurvev2.sip +++ b/python/core/geometry/qgsmulticurvev2.sip @@ -6,7 +6,6 @@ class QgsMultiCurveV2: public QgsGeometryCollectionV2 public: virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsMultiCurveV2* clone() const; bool fromWkt( const QString& wkt ); diff --git a/python/core/geometry/qgsmultilinestringv2.sip b/python/core/geometry/qgsmultilinestringv2.sip index 68a3bbe3eee..f42c39ec53c 100644 --- a/python/core/geometry/qgsmultilinestringv2.sip +++ b/python/core/geometry/qgsmultilinestringv2.sip @@ -6,7 +6,6 @@ class QgsMultiLineStringV2: public QgsMultiCurveV2 public: virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsMultiLineStringV2* clone() const; bool fromWkt( const QString& wkt ); diff --git a/python/core/geometry/qgsmultipointv2.sip b/python/core/geometry/qgsmultipointv2.sip index eaf8a402f92..28384511f13 100644 --- a/python/core/geometry/qgsmultipointv2.sip +++ b/python/core/geometry/qgsmultipointv2.sip @@ -5,7 +5,6 @@ class QgsMultiPointV2: public QgsGeometryCollectionV2 %End public: virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsMultiPointV2* clone() const; bool fromWkt( const QString& wkt ); diff --git a/python/core/geometry/qgsmultipolygonv2.sip b/python/core/geometry/qgsmultipolygonv2.sip index 7dd7abe5a50..f5d5ebd4e31 100644 --- a/python/core/geometry/qgsmultipolygonv2.sip +++ b/python/core/geometry/qgsmultipolygonv2.sip @@ -5,7 +5,6 @@ class QgsMultiPolygonV2: public QgsMultiSurfaceV2 %End public: virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsMultiPolygonV2* clone() const; bool fromWkt( const QString& wkt ); diff --git a/python/core/geometry/qgsmultisurfacev2.sip b/python/core/geometry/qgsmultisurfacev2.sip index e7589755417..2e406d119c7 100644 --- a/python/core/geometry/qgsmultisurfacev2.sip +++ b/python/core/geometry/qgsmultisurfacev2.sip @@ -5,7 +5,6 @@ class QgsMultiSurfaceV2: public QgsGeometryCollectionV2 %End public: virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsMultiSurfaceV2* clone() const; bool fromWkt( const QString& wkt ); diff --git a/python/core/geometry/qgspointv2.sip b/python/core/geometry/qgspointv2.sip index 694b16e9a6d..13d3f48bba9 100644 --- a/python/core/geometry/qgspointv2.sip +++ b/python/core/geometry/qgspointv2.sip @@ -141,7 +141,6 @@ class QgsPointV2: public QgsAbstractGeometryV2 //implementation of inherited methods virtual QgsRectangle boundingBox() const; virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual int dimension() const; virtual QgsPointV2* clone() const /Factory/; void clear(); diff --git a/python/core/geometry/qgspolygonv2.sip b/python/core/geometry/qgspolygonv2.sip index dedc19c3965..859cd24f9f3 100644 --- a/python/core/geometry/qgspolygonv2.sip +++ b/python/core/geometry/qgspolygonv2.sip @@ -11,8 +11,8 @@ class QgsPolygonV2: public QgsCurvePolygonV2 bool operator!=( const QgsPolygonV2& other ) const; virtual QString geometryType() const; - virtual QgsWKBTypes::Type flatWkbType() const; virtual QgsPolygonV2* clone() const; + void clear(); virtual bool fromWkb( QgsConstWkbPtr wkb ); diff --git a/src/core/geometry/qgsabstractgeometryv2.h b/src/core/geometry/qgsabstractgeometryv2.h index 6b74140d0f6..0f945fcf394 100644 --- a/src/core/geometry/qgsabstractgeometryv2.h +++ b/src/core/geometry/qgsabstractgeometryv2.h @@ -75,23 +75,18 @@ class CORE_EXPORT QgsAbstractGeometryV2 virtual int dimension() const = 0; //virtual int coordDim() const { return mCoordDimension; } - /** Returns a unique string representing the geometry class type. + /** Returns a unique string representing the geometry type. * @see wkbType * @see wktTypeStr */ virtual QString geometryType() const = 0; - /** Returns the WKB type of the saved geometry. + /** Returns the WKB type of the geometry. * @see geometryType * @see wktTypeStr */ QgsWKBTypes::Type wkbType() const { return mWkbType; } - /** Returns the flat WKB type of the geometry class. Corresponds to information obtained from - * geometryType(). - */ - virtual QgsWKBTypes::Type flatWkbType() const = 0; - /** Returns the WKT type string of the geometry. * @see geometryType * @see wkbType diff --git a/src/core/geometry/qgscircularstringv2.cpp b/src/core/geometry/qgscircularstringv2.cpp index b1314213e88..ba7fca7d1eb 100644 --- a/src/core/geometry/qgscircularstringv2.cpp +++ b/src/core/geometry/qgscircularstringv2.cpp @@ -28,7 +28,7 @@ QgsCircularStringV2::QgsCircularStringV2(): QgsCurveV2() { - + mWkbType = QgsWKBTypes::CircularString; } QgsCircularStringV2::~QgsCircularStringV2() @@ -57,11 +57,11 @@ QgsCircularStringV2 *QgsCircularStringV2::clone() const void QgsCircularStringV2::clear() { + mWkbType = QgsWKBTypes::CircularString; mX.clear(); mY.clear(); mZ.clear(); mM.clear(); - mWkbType = QgsWKBTypes::Unknown; clearCache(); } diff --git a/src/core/geometry/qgscircularstringv2.h b/src/core/geometry/qgscircularstringv2.h index c51bf8de74d..9bee28538ab 100644 --- a/src/core/geometry/qgscircularstringv2.h +++ b/src/core/geometry/qgscircularstringv2.h @@ -37,7 +37,6 @@ class CORE_EXPORT QgsCircularStringV2: public QgsCurveV2 virtual bool operator!=( const QgsCurveV2& other ) const override; virtual QString geometryType() const override { return "CircularString"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CircularString; } virtual int dimension() const override { return 1; } virtual QgsCircularStringV2* clone() const override; virtual void clear() override; diff --git a/src/core/geometry/qgscompoundcurvev2.cpp b/src/core/geometry/qgscompoundcurvev2.cpp index cd935f0095d..239d86e6925 100644 --- a/src/core/geometry/qgscompoundcurvev2.cpp +++ b/src/core/geometry/qgscompoundcurvev2.cpp @@ -27,7 +27,7 @@ QgsCompoundCurveV2::QgsCompoundCurveV2(): QgsCurveV2() { - + mWkbType = QgsWKBTypes::CompoundCurve; } QgsCompoundCurveV2::~QgsCompoundCurveV2() @@ -51,6 +51,7 @@ bool QgsCompoundCurveV2::operator!=( const QgsCurveV2& other ) const QgsCompoundCurveV2::QgsCompoundCurveV2( const QgsCompoundCurveV2& curve ): QgsCurveV2( curve ) { + mWkbType = QgsWKBTypes::CompoundCurve; Q_FOREACH ( const QgsCurveV2* c, curve.mCurves ) { mCurves.append( static_cast( c->clone() ) ); @@ -78,9 +79,9 @@ QgsCompoundCurveV2 *QgsCompoundCurveV2::clone() const void QgsCompoundCurveV2::clear() { + mWkbType = QgsWKBTypes::CompoundCurve; qDeleteAll( mCurves ); mCurves.clear(); - mWkbType = QgsWKBTypes::Unknown; clearCache(); } diff --git a/src/core/geometry/qgscompoundcurvev2.h b/src/core/geometry/qgscompoundcurvev2.h index d59919c9507..ea800c5d2df 100644 --- a/src/core/geometry/qgscompoundcurvev2.h +++ b/src/core/geometry/qgscompoundcurvev2.h @@ -38,7 +38,6 @@ class CORE_EXPORT QgsCompoundCurveV2: public QgsCurveV2 virtual bool operator!=( const QgsCurveV2& other ) const override; virtual QString geometryType() const override { return "CompoundCurve"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CompoundCurve; } virtual int dimension() const override { return 1; } virtual QgsCompoundCurveV2* clone() const override; virtual void clear() override; diff --git a/src/core/geometry/qgscurvepolygonv2.cpp b/src/core/geometry/qgscurvepolygonv2.cpp index 719d11b8e28..83288a9d746 100644 --- a/src/core/geometry/qgscurvepolygonv2.cpp +++ b/src/core/geometry/qgscurvepolygonv2.cpp @@ -28,7 +28,7 @@ QgsCurvePolygonV2::QgsCurvePolygonV2(): QgsSurfaceV2(), mExteriorRing( nullptr ) { - + mWkbType = QgsWKBTypes::CurvePolygon; } QgsCurvePolygonV2::~QgsCurvePolygonV2() @@ -40,6 +40,7 @@ QgsCurvePolygonV2::QgsCurvePolygonV2( const QgsCurvePolygonV2& p ) : QgsSurfaceV2( p ) , mExteriorRing( nullptr ) { + mWkbType = p.mWkbType; if ( p.mExteriorRing ) { mExteriorRing = static_cast( p.mExteriorRing->clone() ); @@ -77,11 +78,11 @@ QgsCurvePolygonV2* QgsCurvePolygonV2::clone() const void QgsCurvePolygonV2::clear() { + mWkbType = QgsWKBTypes::CurvePolygon; delete mExteriorRing; mExteriorRing = nullptr; qDeleteAll( mInteriorRings ); mInteriorRings.clear(); - mWkbType = QgsWKBTypes::Unknown; clearCache(); } @@ -149,7 +150,7 @@ bool QgsCurvePolygonV2::fromWkt( const QString& wkt ) QPair parts = QgsGeometryUtils::wktReadBlock( wkt ); - if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::Polygon ) + if ( QgsWKBTypes::geometryType( parts.first ) != QgsWKBTypes::PolygonGeometry ) return false; mWkbType = parts.first; diff --git a/src/core/geometry/qgscurvepolygonv2.h b/src/core/geometry/qgscurvepolygonv2.h index f52bcda962c..7b3b616e7ad 100644 --- a/src/core/geometry/qgscurvepolygonv2.h +++ b/src/core/geometry/qgscurvepolygonv2.h @@ -37,7 +37,6 @@ class CORE_EXPORT QgsCurvePolygonV2: public QgsSurfaceV2 ~QgsCurvePolygonV2(); virtual QString geometryType() const override { return "CurvePolygon"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::CurvePolygon; } virtual int dimension() const override { return 2; } virtual QgsCurvePolygonV2* clone() const override; void clear() override; diff --git a/src/core/geometry/qgsgeometrycollectionv2.cpp b/src/core/geometry/qgsgeometrycollectionv2.cpp index 8b3fa3c50e9..7c9f77086d4 100644 --- a/src/core/geometry/qgsgeometrycollectionv2.cpp +++ b/src/core/geometry/qgsgeometrycollectionv2.cpp @@ -72,7 +72,6 @@ void QgsGeometryCollectionV2::clear() { qDeleteAll( mGeometries ); mGeometries.clear(); - mWkbType = QgsWKBTypes::Unknown; clearCache(); //set bounding box invalid } @@ -491,7 +490,7 @@ bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList QPair parts = QgsGeometryUtils::wktReadBlock( wkt ); - if ( QgsWKBTypes::flatType( parts.first ) != flatWkbType() ) + if ( QgsWKBTypes::flatType( parts.first ) != QgsWKBTypes::flatType( wkbType() ) ) return false; mWkbType = parts.first; @@ -504,7 +503,7 @@ bool QgsGeometryCollectionV2::fromCollectionWkt( const QString &wkt, const QList bool success = false; Q_FOREACH ( const QgsAbstractGeometryV2* geom, subtypes ) { - if ( QgsWKBTypes::flatType( childParts.first ) == geom->flatWkbType() ) + if ( QgsWKBTypes::flatType( childParts.first ) == QgsWKBTypes::flatType( geom->wkbType() ) ) { mGeometries.append( geom->clone() ); if ( mGeometries.back()->fromWkt( childWkt ) ) diff --git a/src/core/geometry/qgsgeometrycollectionv2.h b/src/core/geometry/qgsgeometrycollectionv2.h index eab2dd235c5..7f6be42cf94 100644 --- a/src/core/geometry/qgsgeometrycollectionv2.h +++ b/src/core/geometry/qgsgeometrycollectionv2.h @@ -53,7 +53,6 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2 //methods inherited from QgsAbstractGeometry virtual int dimension() const override; virtual QString geometryType() const override { return "GeometryCollection"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::GeometryCollection; } virtual void clear() override; /** Adds a geometry and takes ownership. Returns true in case of success.*/ diff --git a/src/core/geometry/qgslinestringv2.cpp b/src/core/geometry/qgslinestringv2.cpp index f021658e41a..19229e650ab 100644 --- a/src/core/geometry/qgslinestringv2.cpp +++ b/src/core/geometry/qgslinestringv2.cpp @@ -87,7 +87,7 @@ void QgsLineStringV2::clear() mY.clear(); mZ.clear(); mM.clear(); - mWkbType = QgsWKBTypes::Unknown; + mWkbType = QgsWKBTypes::LineString; clearCache(); } diff --git a/src/core/geometry/qgslinestringv2.h b/src/core/geometry/qgslinestringv2.h index de8e76d7d45..53e4099c9f1 100644 --- a/src/core/geometry/qgslinestringv2.h +++ b/src/core/geometry/qgslinestringv2.h @@ -139,7 +139,6 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2 //reimplemented methods virtual QString geometryType() const override { return "LineString"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::LineString; } virtual int dimension() const override { return 1; } virtual QgsLineStringV2* clone() const override; virtual void clear() override; diff --git a/src/core/geometry/qgsmulticurvev2.cpp b/src/core/geometry/qgsmulticurvev2.cpp index e5e4a1aff94..d812e3ff66f 100644 --- a/src/core/geometry/qgsmulticurvev2.cpp +++ b/src/core/geometry/qgsmulticurvev2.cpp @@ -21,6 +21,12 @@ email : marco.hugentobler at sourcepole dot com #include "qgsgeometryutils.h" #include "qgslinestringv2.h" +QgsMultiCurveV2::QgsMultiCurveV2() + : QgsGeometryCollectionV2() +{ + mWkbType = QgsWKBTypes::MultiCurve; +} + QgsMultiCurveV2 *QgsMultiCurveV2::clone() const { return new QgsMultiCurveV2( *this ); diff --git a/src/core/geometry/qgsmulticurvev2.h b/src/core/geometry/qgsmulticurvev2.h index 35af6e4adaf..5724c93de1a 100644 --- a/src/core/geometry/qgsmulticurvev2.h +++ b/src/core/geometry/qgsmulticurvev2.h @@ -27,8 +27,8 @@ email : marco.hugentobler at sourcepole dot com class CORE_EXPORT QgsMultiCurveV2: public QgsGeometryCollectionV2 { public: + QgsMultiCurveV2(); virtual QString geometryType() const override { return "MultiCurve"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiCurve; } QgsMultiCurveV2* clone() const override; bool fromWkt( const QString& wkt ) override; diff --git a/src/core/geometry/qgsmultilinestringv2.cpp b/src/core/geometry/qgsmultilinestringv2.cpp index a83bdc6d24f..de5b55ed789 100644 --- a/src/core/geometry/qgsmultilinestringv2.cpp +++ b/src/core/geometry/qgsmultilinestringv2.cpp @@ -22,6 +22,12 @@ email : marco.hugentobler at sourcepole dot com #include "qgslinestringv2.h" #include "qgsmulticurvev2.h" +QgsMultiLineStringV2::QgsMultiLineStringV2() + : QgsMultiCurveV2() +{ + mWkbType = QgsWKBTypes::MultiLineString; +} + QgsMultiLineStringV2* QgsMultiLineStringV2::clone() const { return new QgsMultiLineStringV2( *this ); diff --git a/src/core/geometry/qgsmultilinestringv2.h b/src/core/geometry/qgsmultilinestringv2.h index 3200508dd0f..b2cacc76bf5 100644 --- a/src/core/geometry/qgsmultilinestringv2.h +++ b/src/core/geometry/qgsmultilinestringv2.h @@ -27,8 +27,8 @@ email : marco.hugentobler at sourcepole dot com class CORE_EXPORT QgsMultiLineStringV2: public QgsMultiCurveV2 { public: + QgsMultiLineStringV2(); virtual QString geometryType() const override { return "MultiLineString"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiLineString; } QgsMultiLineStringV2* clone() const override; bool fromWkt( const QString& wkt ) override; diff --git a/src/core/geometry/qgsmultipointv2.cpp b/src/core/geometry/qgsmultipointv2.cpp index 1189a8ea8f1..aeff6f7f762 100644 --- a/src/core/geometry/qgsmultipointv2.cpp +++ b/src/core/geometry/qgsmultipointv2.cpp @@ -19,6 +19,12 @@ email : marco.hugentobler at sourcepole dot com #include "qgspointv2.h" #include "qgswkbptr.h" +QgsMultiPointV2::QgsMultiPointV2() + : QgsGeometryCollectionV2() +{ + mWkbType = QgsWKBTypes::MultiPoint; +} + QgsMultiPointV2 *QgsMultiPointV2::clone() const { return new QgsMultiPointV2( *this ); diff --git a/src/core/geometry/qgsmultipointv2.h b/src/core/geometry/qgsmultipointv2.h index c5d5d815cc8..8448891b3e0 100644 --- a/src/core/geometry/qgsmultipointv2.h +++ b/src/core/geometry/qgsmultipointv2.h @@ -27,8 +27,8 @@ email : marco.hugentobler at sourcepole dot com class CORE_EXPORT QgsMultiPointV2: public QgsGeometryCollectionV2 { public: + QgsMultiPointV2(); virtual QString geometryType() const override { return "MultiPoint"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiPoint; } QgsMultiPointV2* clone() const override; bool fromWkt( const QString& wkt ) override; diff --git a/src/core/geometry/qgsmultipolygonv2.cpp b/src/core/geometry/qgsmultipolygonv2.cpp index 8277989f326..cf74def40c8 100644 --- a/src/core/geometry/qgsmultipolygonv2.cpp +++ b/src/core/geometry/qgsmultipolygonv2.cpp @@ -21,6 +21,12 @@ email : marco.hugentobler at sourcepole dot com #include "qgspolygonv2.h" #include "qgscurvepolygonv2.h" +QgsMultiPolygonV2::QgsMultiPolygonV2() + : QgsMultiSurfaceV2() +{ + mWkbType = QgsWKBTypes::MultiPolygon; +} + QgsMultiPolygonV2 *QgsMultiPolygonV2::clone() const { return new QgsMultiPolygonV2( *this ); diff --git a/src/core/geometry/qgsmultipolygonv2.h b/src/core/geometry/qgsmultipolygonv2.h index 886888343f6..527e0a84dd2 100644 --- a/src/core/geometry/qgsmultipolygonv2.h +++ b/src/core/geometry/qgsmultipolygonv2.h @@ -27,8 +27,8 @@ email : marco.hugentobler at sourcepole dot com class CORE_EXPORT QgsMultiPolygonV2: public QgsMultiSurfaceV2 { public: + QgsMultiPolygonV2(); virtual QString geometryType() const override { return "MultiPolygon"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiPolygon; } QgsMultiPolygonV2* clone() const override; bool fromWkt( const QString& wkt ) override; diff --git a/src/core/geometry/qgsmultisurfacev2.cpp b/src/core/geometry/qgsmultisurfacev2.cpp index 28a886acbed..b87e3a6f5d5 100644 --- a/src/core/geometry/qgsmultisurfacev2.cpp +++ b/src/core/geometry/qgsmultisurfacev2.cpp @@ -22,6 +22,12 @@ email : marco.hugentobler at sourcepole dot com #include "qgspolygonv2.h" #include "qgscurvepolygonv2.h" +QgsMultiSurfaceV2::QgsMultiSurfaceV2() + : QgsGeometryCollectionV2() +{ + mWkbType = QgsWKBTypes::MultiSurface; +} + QgsMultiSurfaceV2 *QgsMultiSurfaceV2::clone() const { return new QgsMultiSurfaceV2( *this ); diff --git a/src/core/geometry/qgsmultisurfacev2.h b/src/core/geometry/qgsmultisurfacev2.h index f44dd6a7e8b..40ea625a3ac 100644 --- a/src/core/geometry/qgsmultisurfacev2.h +++ b/src/core/geometry/qgsmultisurfacev2.h @@ -27,8 +27,8 @@ email : marco.hugentobler at sourcepole dot com class CORE_EXPORT QgsMultiSurfaceV2: public QgsGeometryCollectionV2 { public: + QgsMultiSurfaceV2(); virtual QString geometryType() const override { return "MultiSurface"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::MultiSurface; } QgsMultiSurfaceV2* clone() const override; bool fromWkt( const QString& wkt ) override; diff --git a/src/core/geometry/qgspointv2.cpp b/src/core/geometry/qgspointv2.cpp index 095e74fb58b..281c7f96db5 100644 --- a/src/core/geometry/qgspointv2.cpp +++ b/src/core/geometry/qgspointv2.cpp @@ -253,7 +253,6 @@ void QgsPointV2::draw( QPainter& p ) const void QgsPointV2::clear() { - mWkbType = QgsWKBTypes::Unknown; mX = mY = mZ = mM = 0.; clearCache(); } diff --git a/src/core/geometry/qgspointv2.h b/src/core/geometry/qgspointv2.h index 1e9d34b6dfd..2ed1e648ca8 100644 --- a/src/core/geometry/qgspointv2.h +++ b/src/core/geometry/qgspointv2.h @@ -153,7 +153,6 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2 //implementation of inherited methods virtual QgsRectangle boundingBox() const override { return QgsRectangle( mX, mY, mX, mY ); } virtual QString geometryType() const override { return "Point"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::Point; } virtual int dimension() const override { return 0; } virtual QgsPointV2* clone() const override; void clear() override; diff --git a/src/core/geometry/qgspolygonv2.cpp b/src/core/geometry/qgspolygonv2.cpp index 9fecf25e93b..39fe7bcf25f 100644 --- a/src/core/geometry/qgspolygonv2.cpp +++ b/src/core/geometry/qgspolygonv2.cpp @@ -70,6 +70,12 @@ QgsPolygonV2* QgsPolygonV2::clone() const return new QgsPolygonV2( *this ); } +void QgsPolygonV2::clear() +{ + QgsCurvePolygonV2::clear(); + mWkbType = QgsWKBTypes::Polygon; +} + bool QgsPolygonV2::fromWkb( QgsConstWkbPtr wkbPtr ) { clear(); diff --git a/src/core/geometry/qgspolygonv2.h b/src/core/geometry/qgspolygonv2.h index ceb7e19ec7d..70417ffa3f1 100644 --- a/src/core/geometry/qgspolygonv2.h +++ b/src/core/geometry/qgspolygonv2.h @@ -35,8 +35,8 @@ class CORE_EXPORT QgsPolygonV2: public QgsCurvePolygonV2 bool operator!=( const QgsPolygonV2& other ) const; virtual QString geometryType() const override { return "Polygon"; } - virtual QgsWKBTypes::Type flatWkbType() const override { return QgsWKBTypes::Polygon; } virtual QgsPolygonV2* clone() const override; + void clear() override; virtual bool fromWkb( QgsConstWkbPtr wkb ) override; diff --git a/tests/src/core/testqgsgeometry.cpp b/tests/src/core/testqgsgeometry.cpp index e46c0f4a686..c7896e19f81 100644 --- a/tests/src/core/testqgsgeometry.cpp +++ b/tests/src/core/testqgsgeometry.cpp @@ -514,7 +514,7 @@ void TestQgsGeometry::pointV2() //clear QgsPointV2 p11( 5.0, 6.0 ); p11.clear(); - QCOMPARE( p11.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p11.wkbType(), QgsWKBTypes::Point ); QCOMPARE( p11.x(), 0.0 ); QCOMPARE( p11.y(), 0.0 ); @@ -538,14 +538,14 @@ void TestQgsGeometry::pointV2() //bad WKB - check for no crash p13 = QgsPointV2( 1, 2 ); QVERIFY( !p13.fromWkb( QgsConstWkbPtr( nullptr, 0 ) ) ); - QCOMPARE( p13.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p13.wkbType(), QgsWKBTypes::Point ); QgsLineStringV2 line; p13 = QgsPointV2( 1, 2 ); wkb = line.asWkb( size ); QVERIFY( !p13.fromWkb( QgsConstWkbPtr( wkb, size ) ) ); delete[] wkb; wkb = 0; - QCOMPARE( p13.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p13.wkbType(), QgsWKBTypes::Point ); //to/from WKT p13 = QgsPointV2( QgsWKBTypes::PointZM, 1.0, 2.0, 3.0, -4.0 ); @@ -557,7 +557,6 @@ void TestQgsGeometry::pointV2() //bad WKT QVERIFY( !p14.fromWkt( "Polygon()" ) ); - QCOMPARE( p14.wkbType(), QgsWKBTypes::Unknown ); //asGML2 QgsPointV2 exportPoint( 1, 2 ); @@ -873,7 +872,7 @@ void TestQgsGeometry::lineStringV2() QCOMPARE( l7.partCount(), 0 ); QVERIFY( !l7.is3D() ); QVERIFY( !l7.isMeasure() ); - QCOMPARE( l7.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( l7.wkbType(), QgsWKBTypes::LineString ); //setPoints QgsLineStringV2 l8; @@ -897,7 +896,7 @@ void TestQgsGeometry::lineStringV2() QCOMPARE( l8.nCoordinates(), 0 ); QCOMPARE( l8.ringCount(), 0 ); QCOMPARE( l8.partCount(), 0 ); - QCOMPARE( l8.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( l8.wkbType(), QgsWKBTypes::LineString ); //setPoints with z l8.setPoints( QgsPointSequenceV2() << QgsPointV2( QgsWKBTypes::PointZ, 1, 2, 3 ) << QgsPointV2( QgsWKBTypes::PointZ, 2, 3, 4 ) ); @@ -1318,13 +1317,13 @@ void TestQgsGeometry::lineStringV2() QCOMPARE( cloned->numPoints(), 0 ); QVERIFY( !cloned->is3D() ); QVERIFY( !cloned->isMeasure() ); - QCOMPARE( cloned->wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( cloned->wkbType(), QgsWKBTypes::LineString ); segmentized.reset( static_cast< QgsLineStringV2* >( l14.segmentize() ) ); QVERIFY( segmentized->isEmpty() ); QCOMPARE( segmentized->numPoints(), 0 ); QVERIFY( !segmentized->is3D() ); QVERIFY( !segmentized->isMeasure() ); - QCOMPARE( segmentized->wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( segmentized->wkbType(), QgsWKBTypes::LineString ); //to/from WKB QgsLineStringV2 l15; @@ -1355,13 +1354,13 @@ void TestQgsGeometry::lineStringV2() //bad WKB - check for no crash l16.clear(); QVERIFY( !l16.fromWkb( QgsConstWkbPtr( nullptr, 0 ) ) ); - QCOMPARE( l16.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( l16.wkbType(), QgsWKBTypes::LineString ); QgsPointV2 point( 1, 2 ); wkb = point.asWkb( size ) ; QVERIFY( !l16.fromWkb( QgsConstWkbPtr( wkb, size ) ) ); delete[] wkb; wkb = 0; - QCOMPARE( l16.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( l16.wkbType(), QgsWKBTypes::LineString ); //to/from WKT QgsLineStringV2 l17; @@ -1389,7 +1388,7 @@ void TestQgsGeometry::lineStringV2() QCOMPARE( l18.numPoints(), 0 ); QVERIFY( !l18.is3D() ); QVERIFY( !l18.isMeasure() ); - QCOMPARE( l18.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( l18.wkbType(), QgsWKBTypes::LineString ); //asGML2 QgsLineStringV2 exportLine; @@ -2568,7 +2567,7 @@ void TestQgsGeometry::polygonV2() QCOMPARE( p9.partCount(), 0 ); QVERIFY( !p9.is3D() ); QVERIFY( !p9.isMeasure() ); - QCOMPARE( p9.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p9.wkbType(), QgsWKBTypes::Polygon ); //equality operator QgsPolygonV2 p10; @@ -2772,13 +2771,13 @@ void TestQgsGeometry::polygonV2() //bad WKB - check for no crash p17.clear(); QVERIFY( !p17.fromWkb( QgsConstWkbPtr( nullptr, 0 ) ) ); - QCOMPARE( p17.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p17.wkbType(), QgsWKBTypes::Polygon ); QgsPointV2 point( 1, 2 ); wkb = point.asWkb( size ) ; QVERIFY( !p17.fromWkb( QgsConstWkbPtr( wkb, size ) ) ); delete[] wkb; wkb = 0; - QCOMPARE( p17.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p17.wkbType(), QgsWKBTypes::Polygon ); //to/from WKT QgsPolygonV2 p18; @@ -2806,7 +2805,7 @@ void TestQgsGeometry::polygonV2() QCOMPARE( p19.numInteriorRings(), 0 ); QVERIFY( !p19.is3D() ); QVERIFY( !p19.isMeasure() ); - QCOMPARE( p19.wkbType(), QgsWKBTypes::Unknown ); + QCOMPARE( p19.wkbType(), QgsWKBTypes::Polygon ); //as JSON QgsPolygonV2 exportPolygon; diff --git a/tests/src/python/test_qgsgeometry.py b/tests/src/python/test_qgsgeometry.py index da4143a316a..c15a9dea599 100644 --- a/tests/src/python/test_qgsgeometry.py +++ b/tests/src/python/test_qgsgeometry.py @@ -21,6 +21,17 @@ from qgis.core import ( QgsFeature, QgsPoint, QgsPointV2, + QgsCircularStringV2, + QgsCompoundCurveV2, + QgsCurvePolygonV2, + QgsGeometryCollectionV2, + QgsLineStringV2, + QgsMultiCurveV2, + QgsMultiLineStringV2, + QgsMultiPointV2, + QgsMultiPolygonV2, + QgsMultiSurfaceV2, + QgsPolygonV2, QgsCoordinateTransform, QgsRectangle, QgsWKBTypes, @@ -1853,6 +1864,34 @@ class TestQgsGeometry(unittest.TestCase): self.assertEqual(g.distanceToVertex(4), 4) self.assertEqual(g.distanceToVertex(5), -1) + def testTypeInformation(self): + """ Test type information """ + types = [ + (QgsCircularStringV2, "CircularString", QgsWKBTypes.CircularString), + (QgsCompoundCurveV2, "CompoundCurve", QgsWKBTypes.CompoundCurve), + (QgsCurvePolygonV2, "CurvePolygon", QgsWKBTypes.CurvePolygon), + (QgsGeometryCollectionV2, "GeometryCollection", QgsWKBTypes.GeometryCollection), + (QgsLineStringV2, "LineString", QgsWKBTypes.LineString), + (QgsMultiCurveV2, "MultiCurve", QgsWKBTypes.MultiCurve), + (QgsMultiLineStringV2, "MultiLineString", QgsWKBTypes.MultiLineString), + (QgsMultiPointV2, "MultiPoint", QgsWKBTypes.MultiPoint), + (QgsMultiPolygonV2, "MultiPolygon", QgsWKBTypes.MultiPolygon), + (QgsMultiSurfaceV2, "MultiSurface", QgsWKBTypes.MultiSurface), + (QgsPointV2, "Point", QgsWKBTypes.Point), + (QgsPolygonV2, "Polygon", QgsWKBTypes.Polygon), + ] + + for geomtype in types: + geom = geomtype[0]() + self.assertEqual(geom.geometryType(), geomtype[1]) + self.assertEqual(geom.wkbType(), geomtype[2]) + geom.clear() + self.assertEqual(geom.geometryType(), geomtype[1]) + self.assertEqual(geom.wkbType(), geomtype[2]) + clone = geom.clone() + self.assertEqual(clone.geometryType(), geomtype[1]) + self.assertEqual(clone.wkbType(), geomtype[2]) + def testRelates(self): """ Test relationships between geometries. Note the bulk of these tests were taken from the PostGIS relate testdata """ with open(os.path.join(TEST_DATA_DIR, 'relates_data.csv'), 'r') as d: diff --git a/tests/src/python/test_qgssymbolv2.py b/tests/src/python/test_qgssymbolv2.py index 63f4330fb50..c3d2ac5e7b3 100644 --- a/tests/src/python/test_qgssymbolv2.py +++ b/tests/src/python/test_qgssymbolv2.py @@ -104,7 +104,7 @@ class TestQgsSymbolV2(unittest.TestCase): for test in tests: geom = QgsGeometry.fromWkt(test['wkt']) - assert geom and not geom.isEmpty(), 'Could not create geometry' + assert geom and not geom.isEmpty(), 'Could not create geometry {}'.format(test['wkt']) rendered_image = self.renderGeometry(geom) assert self.imageCheck(test['name'], test['reference_image'], rendered_image)