Skip to content

Commit 01ece90

Browse files
committedMay 25, 2016
Simplify geometry for labeling
1 parent 51f06ed commit 01ece90

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
 

‎src/core/qgspallabeling.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
#include <qgsproject.h>
5959
#include "qgssymbolv2.h"
6060
#include "qgssymbollayerv2utils.h"
61+
#include "qgsmaptopixelgeometrysimplifier.h"
6162
#include <QMessageBox>
6263

6364

@@ -2422,6 +2423,25 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
24222423
return;
24232424
}
24242425

2426+
// simplify?
2427+
const QgsVectorSimplifyMethod &simplifyMethod = context.vectorSimplifyMethod();
2428+
QScopedPointer<QgsGeometry> scopedClonedGeom;
2429+
if ( simplifyMethod.simplifyHints() != QgsVectorSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
2430+
{
2431+
int simplifyHints = simplifyMethod.simplifyHints() | QgsMapToPixelSimplifier::SimplifyEnvelope;
2432+
QgsGeometry* g = new QgsGeometry( *geom );
2433+
2434+
if ( QgsMapToPixelSimplifier::simplifyGeometry( g, simplifyHints, simplifyMethod.tolerance() ) )
2435+
{
2436+
geom = g;
2437+
scopedClonedGeom.reset( g );
2438+
}
2439+
else
2440+
{
2441+
delete g;
2442+
}
2443+
}
2444+
24252445
// whether we're going to create a centroid for polygon
24262446
bool centroidPoly = (( placement == QgsPalLayerSettings::AroundPoint
24272447
|| placement == QgsPalLayerSettings::OverPoint )
@@ -2982,6 +3002,25 @@ void QgsPalLayerSettings::registerObstacleFeature( QgsFeature& f, QgsRenderConte
29823002
return;
29833003
}
29843004

3005+
// simplify?
3006+
const QgsVectorSimplifyMethod &simplifyMethod = context.vectorSimplifyMethod();
3007+
QScopedPointer<QgsGeometry> scopedClonedGeom;
3008+
if ( simplifyMethod.simplifyHints() != QgsVectorSimplifyMethod::NoSimplification && simplifyMethod.forceLocalOptimization() )
3009+
{
3010+
int simplifyHints = simplifyMethod.simplifyHints() | QgsMapToPixelSimplifier::SimplifyEnvelope;
3011+
QgsGeometry* g = new QgsGeometry( *geom );
3012+
3013+
if ( QgsMapToPixelSimplifier::simplifyGeometry( g, simplifyHints, simplifyMethod.tolerance() ) )
3014+
{
3015+
geom = g;
3016+
scopedClonedGeom.reset( g );
3017+
}
3018+
else
3019+
{
3020+
delete g;
3021+
}
3022+
}
3023+
29853024
const GEOSGeometry* geos_geom = nullptr;
29863025
QScopedPointer<QgsGeometry> scopedPreparedGeom;
29873026

0 commit comments

Comments
 (0)
Please sign in to comment.