Skip to content

Commit 4e41f1a

Browse files
committedAug 9, 2016
Improve polygon perimeter labeling
This commit changes the way polygon perimeter labeling works. Previously the polygon would be clipped to the view extent, and then the boundary of the clipped polygon used for perimeter labeling. This tended to push the labels to the outside of the map extent (the clip boundary), since that's the longest straight section of the resultant geometry. Now, the boundary is taken *before* the clip, so that perimeter based labels will never be placed on the artificial boundary created at the map's extent. (cherry-picked from 27697e6)
1 parent 5ab62a9 commit 4e41f1a

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed
 

‎src/core/qgspallabeling.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2442,6 +2442,16 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
24422442
}
24432443
}
24442444

2445+
// if using perimeter based labeling for polygons, get the polygon's
2446+
// linear boundary and use that for the label geometry
2447+
if (( geom->type() == QGis::Polygon )
2448+
&& ( placement == Line || placement == PerimeterCurved ) )
2449+
{
2450+
QgsGeometry* boundaryGeom = new QgsGeometry( geom->geometry()->boundary() );
2451+
geom = boundaryGeom;
2452+
scopedClonedGeom.reset( boundaryGeom );
2453+
}
2454+
24452455
// whether we're going to create a centroid for polygon
24462456
bool centroidPoly = (( placement == QgsPalLayerSettings::AroundPoint
24472457
|| placement == QgsPalLayerSettings::OverPoint )
@@ -2461,6 +2471,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
24612471
if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, ct, doClip ? extentGeom : nullptr ) )
24622472
{
24632473
scopedPreparedGeom.reset( QgsPalLabeling::prepareGeometry( geom, context, ct, doClip ? extentGeom : nullptr ) );
2474+
24642475
if ( !scopedPreparedGeom.data() )
24652476
return;
24662477
preparedGeom = scopedPreparedGeom.data();
@@ -2516,16 +2527,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
25162527
}
25172528
}
25182529

2519-
GEOSGeometry* geos_geom_clone;
2520-
GEOSGeomTypes geomType = ( GEOSGeomTypes ) GEOSGeomTypeId_r( QgsGeometry::getGEOSHandler(), geos_geom );
2521-
if (( geomType == GEOS_POLYGON || geomType == GEOS_MULTIPOLYGON ) && repeatDistance > 0 && ( placement == Line || placement == PerimeterCurved ) )
2522-
{
2523-
geos_geom_clone = GEOSBoundary_r( QgsGeometry::getGEOSHandler(), geos_geom );
2524-
}
2525-
else
2526-
{
2527-
geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
2528-
}
2530+
GEOSGeometry* geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
25292531
GEOSGeometry* geosObstacleGeomClone = nullptr;
25302532
if ( geosObstacleGeom )
25312533
{

0 commit comments

Comments
 (0)
Please sign in to comment.