Skip to content

Commit

Permalink
Fix #11825 - handle centroid calculation also for invalid geometries
Browse files Browse the repository at this point in the history
The on the fly simplification can corrupt geometries so let's try to deal
with it best we can
  • Loading branch information
wonder-sk committed Feb 12, 2015
1 parent b48e7fd commit b26556e
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/core/symbology-ng/qgssymbollayerv2utils.cpp
Expand Up @@ -3656,6 +3656,17 @@ QPointF QgsSymbolLayerV2Utils::polygonCentroid( const QPolygonF& points )
cy += ( p1.y() + p2.y() ) * area;
}
sum *= 3.0;
if ( sum == 0 )
{
// the linear ring is invalid - let's fall back to a solution that will still
// allow us render at least something (instead of just returning point nan,nan)
if ( points.count() >= 2 )
return QPointF(( points[0].x() + points[1].x() ) / 2, ( points[0].y() + points[1].y() ) / 2 );
else if ( points.count() == 1 )
return points[0];
else
return QPointF(); // hopefully we shouldn't ever get here
}
cx /= sum;
cy /= sum;

Expand Down

0 comments on commit b26556e

Please sign in to comment.