Skip to content
Permalink
Browse files

Fix #11825 - handle centroid calculation also for invalid geometries

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 b26556e55190fc45b5ca700827230682a661742e
Showing with 11 additions and 0 deletions.
  1. +11 −0 src/core/symbology-ng/qgssymbollayerv2utils.cpp
@@ -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;

0 comments on commit b26556e

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