@@ -1762,11 +1762,19 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
1762
1762
doClip = true ;
1763
1763
}
1764
1764
1765
- QScopedPointer<QgsGeometry> preparedGeom ( QgsPalLabeling::prepareGeometry ( geom, context, ct, minFeatureSize, doClip ? extentGeom : 0 ) );
1766
- if ( !preparedGeom.data () )
1767
- return ;
1768
-
1769
- const GEOSGeometry* geos_geom = preparedGeom.data ()->asGeos ();
1765
+ const GEOSGeometry* geos_geom = 0 ;
1766
+ QScopedPointer<QgsGeometry> preparedGeom;
1767
+ if ( QgsPalLabeling::geometryRequiresPreparation ( geom, context, ct, doClip ? extentGeom : 0 ) )
1768
+ {
1769
+ preparedGeom.reset ( QgsPalLabeling::prepareGeometry ( geom, context, ct, minFeatureSize, doClip ? extentGeom : 0 ) );
1770
+ if ( !preparedGeom.data () )
1771
+ return ;
1772
+ geos_geom = preparedGeom.data ()->asGeos ();
1773
+ }
1774
+ else
1775
+ {
1776
+ geos_geom = geom->asGeos ();
1777
+ }
1770
1778
1771
1779
if ( geos_geom == NULL )
1772
1780
return ; // invalid geometry
@@ -3358,6 +3366,33 @@ void QgsPalLabeling::registerFeature( const QString& layerID, QgsFeature& f, con
3358
3366
lyr.registerFeature ( f, context, dxfLayer );
3359
3367
}
3360
3368
3369
+ bool QgsPalLabeling::geometryRequiresPreparation ( QgsGeometry* geometry, const QgsRenderContext& context, const QgsCoordinateTransform* ct, QgsGeometry* clipGeometry )
3370
+ {
3371
+ if ( !geometry )
3372
+ {
3373
+ return false ;
3374
+ }
3375
+
3376
+ // requires reprojection
3377
+ if ( ct )
3378
+ return true ;
3379
+
3380
+ // requires fixing
3381
+ if ( geometry->type () == QGis::Polygon && !geometry->isGeosValid () )
3382
+ return true ;
3383
+
3384
+ // requires rotation
3385
+ const QgsMapToPixel& m2p = context.mapToPixel ();
3386
+ if ( !qgsDoubleNear ( m2p.mapRotation (), 0 ) )
3387
+ return true ;
3388
+
3389
+ // requires clip
3390
+ if ( clipGeometry && !clipGeometry->contains ( geometry ) )
3391
+ return true ;
3392
+
3393
+ return false ;
3394
+ }
3395
+
3361
3396
QgsGeometry* QgsPalLabeling::prepareGeometry ( QgsGeometry* geometry, const QgsRenderContext& context, const QgsCoordinateTransform* ct, double minSize, QgsGeometry* clipGeometry )
3362
3397
{
3363
3398
if ( !geometry )
@@ -3406,7 +3441,7 @@ QgsGeometry* QgsPalLabeling::prepareGeometry( QgsGeometry* geometry, const QgsRe
3406
3441
3407
3442
// Rotate the geometry if needed, before clipping
3408
3443
const QgsMapToPixel& m2p = context.mapToPixel ();
3409
- if ( m2p.mapRotation () )
3444
+ if ( ! qgsDoubleNear ( m2p.mapRotation (), 0 ) )
3410
3445
{
3411
3446
if ( geom->rotate ( m2p.mapRotation (), context.extent ().center () ) )
3412
3447
{
@@ -3500,11 +3535,20 @@ void QgsPalLabeling::registerDiagramFeature( const QString& layerID, QgsFeature&
3500
3535
QgsGeometry* geom = feat.geometry ();
3501
3536
QScopedPointer<QgsGeometry> extentGeom ( QgsGeometry::fromRect ( mMapSettings ->visibleExtent () ) );
3502
3537
3503
- QScopedPointer<QgsGeometry> preparedGeom ( QgsPalLabeling::prepareGeometry ( geom, context, layerIt.value ().ct , -1 , extentGeom.data () ) );
3504
- if ( !preparedGeom.data () )
3505
- return ;
3538
+ const GEOSGeometry* geos_geom = 0 ;
3539
+ QScopedPointer<QgsGeometry> preparedGeom;
3540
+ if ( QgsPalLabeling::geometryRequiresPreparation ( geom, context, layerIt.value ().ct , extentGeom.data () ) )
3541
+ {
3542
+ preparedGeom.reset ( QgsPalLabeling::prepareGeometry ( geom, context, layerIt.value ().ct , 0 , extentGeom.data () ) );
3543
+ if ( !preparedGeom.data () )
3544
+ return ;
3545
+ geos_geom = preparedGeom.data ()->asGeos ();
3546
+ }
3547
+ else
3548
+ {
3549
+ geos_geom = geom->asGeos ();
3550
+ }
3506
3551
3507
- const GEOSGeometry* geos_geom = preparedGeom.data ()->asGeos ();
3508
3552
if ( geos_geom == 0 )
3509
3553
{
3510
3554
return ; // invalid geometry
0 commit comments