Skip to content

Commit

Permalink
Simplify geometry for labeling
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuarte47 committed May 25, 2016
1 parent 51f06ed commit 01ece90
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/core/qgspallabeling.cpp
Expand Up @@ -58,6 +58,7 @@
#include <qgsproject.h>
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsmaptopixelgeometrysimplifier.h"
#include <QMessageBox>


Expand Down Expand Up @@ -2422,6 +2423,25 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
return;
}

// simplify?
const QgsVectorSimplifyMethod &simplifyMethod = context.vectorSimplifyMethod();
QScopedPointer<QgsGeometry> scopedClonedGeom;
if ( simplifyMethod.simplifyHints() != QgsVectorSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
{
int simplifyHints = simplifyMethod.simplifyHints() | QgsMapToPixelSimplifier::SimplifyEnvelope;
QgsGeometry* g = new QgsGeometry( *geom );

if ( QgsMapToPixelSimplifier::simplifyGeometry( g, simplifyHints, simplifyMethod.tolerance() ) )
{
geom = g;
scopedClonedGeom.reset( g );
}
else
{
delete g;
}
}

// whether we're going to create a centroid for polygon
bool centroidPoly = (( placement == QgsPalLayerSettings::AroundPoint
|| placement == QgsPalLayerSettings::OverPoint )
Expand Down Expand Up @@ -2982,6 +3002,25 @@ void QgsPalLayerSettings::registerObstacleFeature( QgsFeature& f, QgsRenderConte
return;
}

// simplify?
const QgsVectorSimplifyMethod &simplifyMethod = context.vectorSimplifyMethod();
QScopedPointer<QgsGeometry> scopedClonedGeom;
if ( simplifyMethod.simplifyHints() != QgsVectorSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
{
int simplifyHints = simplifyMethod.simplifyHints() | QgsMapToPixelSimplifier::SimplifyEnvelope;
QgsGeometry* g = new QgsGeometry( *geom );

if ( QgsMapToPixelSimplifier::simplifyGeometry( g, simplifyHints, simplifyMethod.tolerance() ) )
{
geom = g;
scopedClonedGeom.reset( g );
}
else
{
delete g;
}
}

const GEOSGeometry* geos_geom = nullptr;
QScopedPointer<QgsGeometry> scopedPreparedGeom;

Expand Down

0 comments on commit 01ece90

Please sign in to comment.