Skip to content
Permalink
Browse files

[labeling] Fix minimum feature size settings not taking merged lines …

…into account
  • Loading branch information
nirvn authored and nyalldawson committed Apr 7, 2021
1 parent ad1b06d commit 7dd97e60f0a259605584542447ccac3c7e2011c9
Showing with 42 additions and 2 deletions.
  1. +21 −0 src/core/labeling/qgslabelfeature.h
  2. +15 −2 src/core/labeling/qgspallabeling.cpp
  3. +6 −0 src/core/pal/layer.cpp
@@ -530,6 +530,24 @@ class CORE_EXPORT QgsLabelFeature
*/
void setOriginalFeatureCrs( const QgsCoordinateReferenceSystem &crs );

/**
* Returns the minimum size (in map unit) for a feature to be labelled.
*
* \note At the moment this is only used when labeling merged lines
* \see minimumSize()
* \since QGIS 3.20
*/
double minimumSize() const { return mMinimumSize; }

/**
* Sets the minimum \a size (in map unit) for a feature to be labelled.
*
* \note At the moment this is only used when labeling merged lines
* \see setMinimumSize()
* \since QGIS 3.20
*/
void setMinimumSize( double size ) { mMinimumSize = size; }

protected:
//! Pointer to PAL layer (assigned when registered to PAL)
pal::Layer *mLayer = nullptr;
@@ -611,6 +629,9 @@ class CORE_EXPORT QgsLabelFeature
QgsLabelLineSettings::AnchorType mLineAnchorType = QgsLabelLineSettings::AnchorType::HintOnly;

QgsCoordinateReferenceSystem mOriginalFeatureCrs;

double mMinimumSize = 0.0;

};

#endif // QGSLABELFEATURE_H
@@ -2104,8 +2104,20 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
QgsLabelThinningSettings featureThinningSettings = mThinningSettings;
featureThinningSettings.updateDataDefinedProperties( mDataDefinedProperties, context.expressionContext() );

if ( featureThinningSettings.minimumFeatureSize() > 0 && !checkMinimumSizeMM( context, geom, featureThinningSettings.minimumFeatureSize() ) )
return;
double minimumSize = 0.0;
if ( featureThinningSettings.minimumFeatureSize() > 0 )
{
// for minimum feature size on merged lines, we need to delay the filtering after the merging occurred in PAL
if ( geom.type() == QgsWkbTypes::LineGeometry && mLineSettings.mergeLines() )
{
minimumSize = context.convertToMapUnits( featureThinningSettings.minimumFeatureSize(), QgsUnitTypes::RenderMillimeters );
}
else
{
if ( !checkMinimumSizeMM( context, geom, featureThinningSettings.minimumFeatureSize() ) )
return;
}
}

if ( !geos_geom_clone )
return; // invalid geometry
@@ -2493,6 +2505,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
( *labelFeature )->setLineAnchorType( lineSettings.anchorType() );
( *labelFeature )->setLabelAllParts( labelAll );
( *labelFeature )->setOriginalFeatureCrs( context.coordinateTransform().sourceCrs() );
( *labelFeature )->setMinimumSize( minimumSize );
if ( geom.type() == QgsWkbTypes::PointGeometry && !obstacleGeometry.isNull() )
{
//register symbol size
@@ -338,6 +338,12 @@ void Layer::joinConnectedFeatures()
}
}
mConnectedHashtable.clear();

// Expunge feature parts that are smaller than the minimum size required
mFeatureParts.erase( std::remove_if( mFeatureParts.begin(), mFeatureParts.end(), []( FeaturePart * part )
{
return part->feature()->minimumSize() != 0.0 && part->length() < part->feature()->minimumSize();
} ), mFeatureParts.end() );
}

int Layer::connectedFeatureId( QgsFeatureId featureId ) const

0 comments on commit 7dd97e6

Please sign in to comment.