Skip to content
Permalink
Browse files

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)
  • Loading branch information
nyalldawson committed Aug 9, 2016
1 parent 5ab62a9 commit 4e41f1a79a5cf88fcd388a0705841a234bfceeb2
Showing with 12 additions and 10 deletions.
  1. +12 −10 src/core/qgspallabeling.cpp
@@ -2442,6 +2442,16 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
}
}

// if using perimeter based labeling for polygons, get the polygon's
// linear boundary and use that for the label geometry
if (( geom->type() == QGis::Polygon )
&& ( placement == Line || placement == PerimeterCurved ) )
{
QgsGeometry* boundaryGeom = new QgsGeometry( geom->geometry()->boundary() );
geom = boundaryGeom;
scopedClonedGeom.reset( boundaryGeom );
}

// whether we're going to create a centroid for polygon
bool centroidPoly = (( placement == QgsPalLayerSettings::AroundPoint
|| placement == QgsPalLayerSettings::OverPoint )
@@ -2461,6 +2471,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
if ( QgsPalLabeling::geometryRequiresPreparation( geom, context, ct, doClip ? extentGeom : nullptr ) )
{
scopedPreparedGeom.reset( QgsPalLabeling::prepareGeometry( geom, context, ct, doClip ? extentGeom : nullptr ) );

if ( !scopedPreparedGeom.data() )
return;
preparedGeom = scopedPreparedGeom.data();
@@ -2516,16 +2527,7 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, QgsRenderContext &cont
}
}

GEOSGeometry* geos_geom_clone;
GEOSGeomTypes geomType = ( GEOSGeomTypes ) GEOSGeomTypeId_r( QgsGeometry::getGEOSHandler(), geos_geom );
if (( geomType == GEOS_POLYGON || geomType == GEOS_MULTIPOLYGON ) && repeatDistance > 0 && ( placement == Line || placement == PerimeterCurved ) )
{
geos_geom_clone = GEOSBoundary_r( QgsGeometry::getGEOSHandler(), geos_geom );
}
else
{
geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
}
GEOSGeometry* geos_geom_clone = GEOSGeom_clone_r( QgsGeometry::getGEOSHandler(), geos_geom );
GEOSGeometry* geosObstacleGeomClone = nullptr;
if ( geosObstacleGeom )
{

0 comments on commit 4e41f1a

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