Skip to content
Permalink
Browse files

Simplify geometry for labeling

  • Loading branch information
ahuarte47 committed Mar 23, 2016
1 parent 51f06ed commit 01ece90f51ab7c8014fc2751310fd7206c2ed65c
Showing with 39 additions and 0 deletions.
  1. +39 −0 src/core/qgspallabeling.cpp
@@ -58,6 +58,7 @@
#include <qgsproject.h>
#include "qgssymbolv2.h"
#include "qgssymbollayerv2utils.h"
#include "qgsmaptopixelgeometrysimplifier.h"
#include <QMessageBox>


@@ -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 )
@@ -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;

0 comments on commit 01ece90

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