Navigation Menu

Skip to content

Commit

Permalink
Fix crash when smoothing feature with a curved geometry type
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored and nyalldawson committed Jul 9, 2020
1 parent 32a04fd commit e540cbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/core/geometry/qgsgeometry.cpp
Expand Up @@ -3172,38 +3172,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 ) );
}
Expand Down
6 changes: 6 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -17098,6 +17098,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()
Expand Down

0 comments on commit e540cbb

Please sign in to comment.