From 3b5df98332ded19e8d44ff5bce8c5304513b0f20 Mon Sep 17 00:00:00 2001 From: Marco Hugentobler Date: Tue, 9 Jun 2015 13:27:15 +0200 Subject: [PATCH] Implement segmentize method in QgsGeometryCollection2 instead of subclasses --- src/core/geometry/qgsgeometrycollectionv2.cpp | 17 +++++++++++++++++ src/core/geometry/qgsgeometrycollectionv2.h | 3 +++ src/core/geometry/qgsmulticurvev2.cpp | 11 ----------- src/core/geometry/qgsmulticurvev2.h | 2 -- src/core/geometry/qgsmultisurfacev2.cpp | 11 ----------- src/core/geometry/qgsmultisurfacev2.h | 3 --- 6 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/core/geometry/qgsgeometrycollectionv2.cpp b/src/core/geometry/qgsgeometrycollectionv2.cpp index 5fd2a99352a..63afb2a128e 100644 --- a/src/core/geometry/qgsgeometrycollectionv2.cpp +++ b/src/core/geometry/qgsgeometrycollectionv2.cpp @@ -476,3 +476,20 @@ bool QgsGeometryCollectionV2::hasCurvedSegments() const } return false; } + +QgsAbstractGeometryV2* QgsGeometryCollectionV2::segmentize() const +{ + QgsAbstractGeometryV2* geom = QgsGeometryImport::geomFromWkbType( mWkbType ); + QgsGeometryCollectionV2* geomCollection = dynamic_cast( geom ); + if ( !geomCollection ) + { + delete geom; return clone(); + } + + QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin(); + for ( ; geomIt != mGeometries.constEnd(); ++geomIt ) + { + geomCollection->addGeometry(( *geomIt )->segmentize() ); + } + return geomCollection; +} diff --git a/src/core/geometry/qgsgeometrycollectionv2.h b/src/core/geometry/qgsgeometrycollectionv2.h index 26c78052a3e..5a2c3e6b290 100644 --- a/src/core/geometry/qgsgeometrycollectionv2.h +++ b/src/core/geometry/qgsgeometrycollectionv2.h @@ -92,6 +92,9 @@ class CORE_EXPORT QgsGeometryCollectionV2: public QgsAbstractGeometryV2 bool hasCurvedSegments() const override; + /**Returns a geometry without curves. Caller takes ownership*/ + QgsAbstractGeometryV2* segmentize() const override; + protected: QVector< QgsAbstractGeometryV2* > mGeometries; diff --git a/src/core/geometry/qgsmulticurvev2.cpp b/src/core/geometry/qgsmulticurvev2.cpp index c3a3f9224e6..3a2133aca65 100644 --- a/src/core/geometry/qgsmulticurvev2.cpp +++ b/src/core/geometry/qgsmulticurvev2.cpp @@ -106,14 +106,3 @@ bool QgsMultiCurveV2::addGeometry( QgsAbstractGeometryV2* g ) setZMTypeFromSubGeometry( g, QgsWKBTypes::MultiCurve ); return QgsGeometryCollectionV2::addGeometry( g ); } - -QgsAbstractGeometryV2* QgsMultiCurveV2::segmentize() const -{ - QgsMultiCurveV2* c = new QgsMultiCurveV2(); - QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin(); - for ( ; geomIt != mGeometries.constEnd(); ++geomIt ) - { - c->addGeometry(( *geomIt )->segmentize() ); - } - return c; -} diff --git a/src/core/geometry/qgsmulticurvev2.h b/src/core/geometry/qgsmulticurvev2.h index 1cdcb27e81f..282ca51a035 100644 --- a/src/core/geometry/qgsmulticurvev2.h +++ b/src/core/geometry/qgsmulticurvev2.h @@ -36,8 +36,6 @@ class CORE_EXPORT QgsMultiCurveV2: public QgsGeometryCollectionV2 /**Adds a geometry and takes ownership. Returns true in case of success*/ virtual bool addGeometry( QgsAbstractGeometryV2* g ) override; - /**Returns a geometry without curves. Caller takes ownership*/ - QgsAbstractGeometryV2* segmentize() const override; }; #endif // QGSMULTICURVEV2_H diff --git a/src/core/geometry/qgsmultisurfacev2.cpp b/src/core/geometry/qgsmultisurfacev2.cpp index bd390294b0e..bbb7f1c8e8c 100644 --- a/src/core/geometry/qgsmultisurfacev2.cpp +++ b/src/core/geometry/qgsmultisurfacev2.cpp @@ -126,14 +126,3 @@ bool QgsMultiSurfaceV2::addGeometry( QgsAbstractGeometryV2* g ) setZMTypeFromSubGeometry( g, QgsWKBTypes::MultiSurface ); return QgsGeometryCollectionV2::addGeometry( g ); } - -QgsAbstractGeometryV2* QgsMultiSurfaceV2::segmentize() const -{ - QgsMultiSurfaceV2* c = new QgsMultiSurfaceV2(); - QVector< QgsAbstractGeometryV2* >::const_iterator geomIt = mGeometries.constBegin(); - for ( ; geomIt != mGeometries.constEnd(); ++geomIt ) - { - c->addGeometry(( *geomIt )->segmentize() ); - } - return c; -} diff --git a/src/core/geometry/qgsmultisurfacev2.h b/src/core/geometry/qgsmultisurfacev2.h index 13b540dc07c..c4641b9a611 100644 --- a/src/core/geometry/qgsmultisurfacev2.h +++ b/src/core/geometry/qgsmultisurfacev2.h @@ -36,9 +36,6 @@ class CORE_EXPORT QgsMultiSurfaceV2: public QgsGeometryCollectionV2 /**Adds a geometry and takes ownership. Returns true in case of success*/ virtual bool addGeometry( QgsAbstractGeometryV2* g ) override; - - /**Returns a geometry without curves. Caller takes ownership*/ - QgsAbstractGeometryV2* segmentize() const override; }; #endif // QGSMULTISURFACEV2_H