Skip to content
Permalink
Browse files
Labeling: clip geometries to current extent if they are not completel…
…y inside. Also fixes #4083
  • Loading branch information
wonder-sk committed Jul 14, 2011
1 parent 98562b3 commit 17e864bb99c5c6b2e1f0493a952870f183d9d9c0
Showing with 29 additions and 6 deletions.
  1. +28 −6 src/core/qgspallabeling.cpp
  2. +1 −0 src/core/qgspallabeling.h
@@ -131,7 +131,7 @@ class QgsPalGeometry : public PalGeometry
// -------------

QgsPalLayerSettings::QgsPalLayerSettings()
: palLayer( NULL ), fontMetrics( NULL ), ct( NULL )
: palLayer( NULL ), fontMetrics( NULL ), ct( NULL ), extentGeom( NULL )
{
placement = AroundPoint;
placementFlags = 0;
@@ -185,6 +185,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
dataDefinedProperties = s.dataDefinedProperties;
fontMetrics = NULL;
ct = NULL;
extentGeom = NULL;
}


@@ -194,6 +195,8 @@ QgsPalLayerSettings::~QgsPalLayerSettings()

delete fontMetrics;
delete ct;

delete extentGeom;
}

static QColor _readColor( QgsVectorLayer* layer, QString property )
@@ -466,15 +469,31 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
if ( ct ) // reproject the geometry if necessary
geom->transform( *ct );

GEOSGeometry* geos_geom = geom->asGeos();
if ( geos_geom == NULL )
return; // invalid geometry

if ( !checkMinimumSizeMM( context, geom, minFeatureSize ) )
{
return;
}

// CLIP the geometry if it is bigger than the extent
QgsGeometry* geomClipped = NULL;
GEOSGeometry* geos_geom;
bool do_clip = !extentGeom->contains( geom );
if ( do_clip )
{
geomClipped = geom->intersection( extentGeom ); // creates new geometry
geos_geom = geomClipped->asGeos();
}
else
{
geos_geom = geom->asGeos();
}

if ( geos_geom == NULL )
return; // invalid geometry
GEOSGeometry* geos_geom_clone = GEOSGeom_clone( geos_geom );
if ( do_clip )
delete geomClipped;

//data defined position / alignment / rotation?
bool dataDefinedPosition = false;
bool dataDefinedRotation = false;
@@ -569,7 +588,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
}
}

QgsPalGeometry* lbl = new QgsPalGeometry( f.id(), labelText, GEOSGeom_clone( geos_geom ) );
QgsPalGeometry* lbl = new QgsPalGeometry( f.id(), labelText, geos_geom_clone );

// record the created geometry - it will be deleted at the end.
geometries.append( lbl );
@@ -766,6 +785,9 @@ int QgsPalLabeling::prepareLayer( QgsVectorLayer* layer, QSet<int>& attrIndices,
lyr.ptZero = lyr.xform->toMapCoordinates( 0, 0 );
lyr.ptOne = lyr.xform->toMapCoordinates( 1, 0 );

// rect for clipping
lyr.extentGeom = QgsGeometry::fromRect( mMapRenderer->extent() );

return 1; // init successful
}

@@ -143,6 +143,7 @@ class CORE_EXPORT QgsPalLayerSettings
const QgsCoordinateTransform* ct;
QgsPoint ptZero, ptOne;
QList<QgsPalGeometry*> geometries;
QgsGeometry* extentGeom;

/**Stores field indices for data defined layer properties*/
QMap< DataDefinedProperties, int > dataDefinedProperties;

0 comments on commit 17e864b

Please sign in to comment.