Skip to content
Permalink
Browse files

[pal] Don't treat joined features as obstacles for each other

Eg, if the "merge connected features" option for a layer is checked
then label candidates generated for the merged line should not
be marked as in conflict with any part of the merged line.
Previously they would be marked in conflict with all but one part
of the merged line, resulting in false penalties being applied
to these candidates and non-ideal final label placements.
  • Loading branch information
nyalldawson committed Nov 24, 2015
1 parent e03f554 commit 3e618916eba9698a0abc921d3f144359d28ed1a5
Showing with 29 additions and 1 deletion.
  1. +12 −1 src/core/pal/feature.cpp
  2. +10 −0 src/core/pal/layer.cpp
  3. +7 −0 src/core/pal/layer.h
@@ -170,7 +170,18 @@ namespace pal
if ( !part )
return false;

return mLF->id() == part->featureId() && mLF->layer()->name() == part->layer()->name();
if ( mLF->layer()->name() != part->layer()->name() )
return false;

if ( mLF->id() == part->featureId() )
return true;

// any part of joined features are also treated as having the same label feature
int connectedFeatureId = mLF->layer()->connectedFeatureId( mLF->id() );
if ( connectedFeatureId >= 0 && connectedFeatureId == mLF->layer()->connectedFeatureId( part->featureId() ) )
return true;

return false;
}

LabelPosition::Quadrant FeaturePart::quadrantFromOffset() const
@@ -357,11 +357,14 @@ namespace pal
void Layer::joinConnectedFeatures()
{
// go through all label texts
int connectedFeaturesId = 0;
Q_FOREACH ( const QString& labelText, mConnectedTexts )
{
if ( !mConnectedHashtable.contains( labelText ) )
continue; // shouldn't happen

connectedFeaturesId++;

QLinkedList<FeaturePart*>* parts = mConnectedHashtable.value( labelText );

// go one-by-one part, try to merge
@@ -381,11 +384,13 @@ namespace pal
mFeatureIndex->Remove( bmin, bmax, partCheck );
mFeatureParts.removeOne( partCheck );

mConnectedFeaturesIds.insert( partCheck->featureId(), connectedFeaturesId );
otherPart->getBoundingBox( bmin, bmax );

// merge points from partCheck to p->item
if ( otherPart->mergeWithFeaturePart( partCheck ) )
{
mConnectedFeaturesIds.insert( otherPart->featureId(), connectedFeaturesId );
// reinsert p->item to r-tree (probably not needed)
mFeatureIndex->Remove( bmin, bmax, otherPart );
otherPart->getBoundingBox( bmin, bmax );
@@ -409,6 +414,11 @@ namespace pal
mConnectedTexts.clear();
}

int Layer::connectedFeatureId( QgsFeatureId featureId ) const
{
return mConnectedFeaturesIds.value( featureId, -1 );
}

void Layer::chopFeaturesAtRepeatDistance()
{
GEOSContextHandle_t geosctxt = geosContext();
@@ -239,6 +239,12 @@ namespace pal
/** Join connected features with the same label text */
void joinConnectedFeatures();

/** Returns the connected feature ID for a label feature ID, which is unique for all features
* which have been joined as a result of joinConnectedFeatures()
* @returns connected feature ID, or -1 if feature was not joined
*/
int connectedFeatureId( QgsFeatureId featureId ) const;

/** Chop layer features at the repeat distance **/
void chopFeaturesAtRepeatDistance();

@@ -281,6 +287,7 @@ namespace pal

QHash< QString, QLinkedList<FeaturePart*>* > mConnectedHashtable;
QStringList mConnectedTexts;
QHash< QgsFeatureId, int > mConnectedFeaturesIds;

QMutex mMutex;

0 comments on commit 3e61891

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