Skip to content
Permalink
Browse files

Fix crash when smoothing feature with a curved geometry type

Fixes #37663
  • Loading branch information
nyalldawson committed Jul 9, 2020
1 parent 6ddff0d commit a98f914b9b990f9a6997a092d5a96c0a4d7a25ee
Showing with 12 additions and 6 deletions.
  1. +6 −6 src/core/geometry/qgsgeometry.cpp
  2. +6 −0 tests/src/core/testqgsgeometry.cpp
@@ -3173,38 +3173,38 @@ QgsGeometry QgsGeometry::smooth( const unsigned int iterations, const double off

case QgsWkbTypes::LineString:
{
QgsLineString *lineString = static_cast< QgsLineString * >( d->geometry.get() );
const QgsLineString *lineString = qgsgeometry_cast< const QgsLineString * >( geom.constGet() );
return QgsGeometry( smoothLine( *lineString, iterations, offset, minimumDistance, maxAngle ) );
}

case QgsWkbTypes::MultiLineString:
{
QgsMultiLineString *multiLine = static_cast< QgsMultiLineString * >( d->geometry.get() );
const QgsMultiLineString *multiLine = qgsgeometry_cast< const QgsMultiLineString * >( geom.constGet() );

std::unique_ptr< QgsMultiLineString > resultMultiline = qgis::make_unique< QgsMultiLineString> ();
resultMultiline->reserve( multiLine->numGeometries() );
for ( int i = 0; i < multiLine->numGeometries(); ++i )
{
resultMultiline->addGeometry( smoothLine( *( static_cast< QgsLineString * >( multiLine->geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
resultMultiline->addGeometry( smoothLine( *( qgsgeometry_cast< const QgsLineString * >( multiLine->geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
}
return QgsGeometry( std::move( resultMultiline ) );
}

case QgsWkbTypes::Polygon:
{
QgsPolygon *poly = static_cast< QgsPolygon * >( d->geometry.get() );
const QgsPolygon *poly = qgsgeometry_cast< const QgsPolygon * >( geom.constGet() );
return QgsGeometry( smoothPolygon( *poly, iterations, offset, minimumDistance, maxAngle ) );
}

case QgsWkbTypes::MultiPolygon:
{
QgsMultiPolygon *multiPoly = static_cast< QgsMultiPolygon * >( d->geometry.get() );
const QgsMultiPolygon *multiPoly = qgsgeometry_cast< const QgsMultiPolygon * >( geom.constGet() );

std::unique_ptr< QgsMultiPolygon > resultMultiPoly = qgis::make_unique< QgsMultiPolygon >();
resultMultiPoly->reserve( multiPoly->numGeometries() );
for ( int i = 0; i < multiPoly->numGeometries(); ++i )
{
resultMultiPoly->addGeometry( smoothPolygon( *( static_cast< QgsPolygon * >( multiPoly->geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
resultMultiPoly->addGeometry( smoothPolygon( *( qgsgeometry_cast< const QgsPolygon * >( multiPoly->geometryN( i ) ) ), iterations, offset, minimumDistance, maxAngle ).release() );
}
return QgsGeometry( std::move( resultMultiPoly ) );
}
@@ -17119,6 +17119,12 @@ void TestQgsGeometry::smoothCheck()
<< QgsPointXY( 4.0, 3.8 ) << QgsPointXY( 3.8, 4.0 ) << QgsPointXY( 2.2, 4.0 ) << QgsPointXY( 2.0, 3.8 )
<< QgsPointXY( 2, 2.2 ) << QgsPointXY( 2.2, 2 ) ) );
QVERIFY( QgsGeometry::compare( multipoly, expectedMultiPoly ) );

// curved geometry
wkt = QStringLiteral( "CurvePolygon (CompoundCurve (CircularString (-70.75639028391421448 42.11076979194393743, -70.75300889449444242 42.10738840252416537, -70.75639028391421448 42.10400701310439331, -70.75977167333398654 42.10738840252416537, -70.75639028391421448 42.11076979194393743))) 1" );
geom = QgsGeometry::fromWkt( wkt );
result = geom.smooth( 3 );
QCOMPARE( result.wkbType(), QgsWkbTypes::Polygon );
}

void TestQgsGeometry::unaryUnion()

0 comments on commit a98f914

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