diff --git a/src/core/geometry/qgspolygon.cpp b/src/core/geometry/qgspolygon.cpp index 104279704b74..6f46c70eca51 100644 --- a/src/core/geometry/qgspolygon.cpp +++ b/src/core/geometry/qgspolygon.cpp @@ -316,11 +316,14 @@ QgsPolygon *QgsPolygon::surfaceToPolygon() const QgsCurvePolygon *QgsPolygon::toCurveType() const { QgsCurvePolygon *curvePolygon = new QgsCurvePolygon(); - curvePolygon->setExteriorRing( mExteriorRing->clone() ); - int nInteriorRings = mInteriorRings.size(); - for ( int i = 0; i < nInteriorRings; ++i ) + if ( mExteriorRing ) { - curvePolygon->addInteriorRing( mInteriorRings.at( i )->clone() ); + curvePolygon->setExteriorRing( mExteriorRing->clone() ); + int nInteriorRings = mInteriorRings.size(); + for ( int i = 0; i < nInteriorRings; ++i ) + { + curvePolygon->addInteriorRing( mInteriorRings.at( i )->clone() ); + } } return curvePolygon; } diff --git a/tests/src/core/geometry/testqgspolygon.cpp b/tests/src/core/geometry/testqgspolygon.cpp index 70cb31551fc6..e472a7bb20f5 100644 --- a/tests/src/core/geometry/testqgspolygon.cpp +++ b/tests/src/core/geometry/testqgspolygon.cpp @@ -592,7 +592,10 @@ void TestQgsPolygon::polygon() QCOMPARE( *toP, p12 ); //toCurveType - std::unique_ptr< QgsCurvePolygon > curveType( p12.toCurveType() ); + std::unique_ptr< QgsCurvePolygon > curveType( QgsPolygon().toCurveType() ); + QCOMPARE( curveType->wkbType(), QgsWkbTypes::CurvePolygon ); + + curveType.reset( p12.toCurveType() ); QCOMPARE( curveType->wkbType(), QgsWkbTypes::CurvePolygonZM ); QCOMPARE( curveType->exteriorRing()->numPoints(), 5 ); QCOMPARE( curveType->exteriorRing()->vertexAt( QgsVertexId( 0, 0, 0 ) ), QgsPoint( QgsWkbTypes::PointZM, 0, 0, 1, 5 ) );