QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
pal.cpp
Go to the documentation of this file.
1/*
2 * libpal - Automated Placement of Labels Library
3 *
4 * Copyright (C) 2008 Maxence Laurent, MIS-TIC, HEIG-VD
5 * University of Applied Sciences, Western Switzerland
6 * http://www.hes-so.ch
7 *
8 * Contact:
9 * maxence.laurent <at> heig-vd <dot> ch
10 * or
11 * eric.taillard <at> heig-vd <dot> ch
12 *
13 * This file is part of libpal.
14 *
15 * libpal is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * libpal is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with libpal. If not, see <http://www.gnu.org/licenses/>.
27 *
28 */
29
30#include "qgsgeometry.h"
31#include "pal.h"
32#include "layer.h"
33#include "palexception.h"
34#include "palstat.h"
35#include "costcalculator.h"
36#include "feature.h"
37#include "geomfunction.h"
38#include "labelposition.h"
39#include "problem.h"
40#include "pointset.h"
41#include "internalexception.h"
42#include "util.h"
43#include "palrtree.h"
44#include "qgslabelingengine.h"
45#include "qgsrendercontext.h"
47
48#include <cfloat>
49#include <list>
50
51
52using namespace pal;
53
54const QgsSettingsEntryInteger *Pal::settingsRenderingLabelCandidatesLimitPoints = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-points" ), sTreePal, 0 );
55const QgsSettingsEntryInteger *Pal::settingsRenderingLabelCandidatesLimitLines = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-lines" ), sTreePal, 0 );
56const QgsSettingsEntryInteger *Pal::settingsRenderingLabelCandidatesLimitPolygons = new QgsSettingsEntryInteger( QStringLiteral( "label-candidates-limit-polygons" ), sTreePal, 0 );
57
58
59Pal::Pal()
60{
61 mGlobalCandidatesLimitPoint = Pal::settingsRenderingLabelCandidatesLimitPoints->value();
62 mGlobalCandidatesLimitLine = Pal::settingsRenderingLabelCandidatesLimitLines->value();
63 mGlobalCandidatesLimitPolygon = Pal::settingsRenderingLabelCandidatesLimitPolygons->value();
64}
65
66Pal::~Pal() = default;
67
68void Pal::removeLayer( Layer *layer )
69{
70 if ( !layer )
71 return;
72
73 mMutex.lock();
74
75 for ( auto it = mLayers.begin(); it != mLayers.end(); ++it )
76 {
77 if ( it->second.get() == layer )
78 {
79 mLayers.erase( it );
80 break;
81 }
82 }
83 mMutex.unlock();
84}
85
86Layer *Pal::addLayer( QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel )
87{
88 mMutex.lock();
89
90 Q_ASSERT( mLayers.find( provider ) == mLayers.end() );
91
92 std::unique_ptr< Layer > layer = std::make_unique< Layer >( provider, layerName, arrangement, defaultPriority, active, toLabel, this );
93 Layer *res = layer.get();
94 mLayers.insert( std::pair<QgsAbstractLabelProvider *, std::unique_ptr< Layer >>( provider, std::move( layer ) ) );
95 mMutex.unlock();
96
97 return res;
98}
99
100std::unique_ptr<Problem> Pal::extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context )
101{
102 QgsLabelingEngineFeedback *feedback = qobject_cast< QgsLabelingEngineFeedback * >( context.feedback() );
103
104 // expand out the incoming buffer by 1000x -- that's the visible map extent, yet we may be getting features which exceed this extent
105 // (while 1000x may seem excessive here, this value is only used for scaling coordinates in the spatial indexes
106 // and the consequence of inserting coordinates outside this extent is worse than the consequence of setting this value too large.)
107 const QgsRectangle maxCoordinateExtentForSpatialIndices = extent.buffered( std::max( extent.width(), extent.height() ) * 1000 );
108
109 // to store obstacles
110 PalRtree< FeaturePart > obstacles( maxCoordinateExtentForSpatialIndices );
111 PalRtree< LabelPosition > allCandidatesFirstRound( maxCoordinateExtentForSpatialIndices );
112 std::vector< FeaturePart * > allObstacleParts;
113 std::unique_ptr< Problem > prob = std::make_unique< Problem >( maxCoordinateExtentForSpatialIndices );
114
115 double bbx[4];
116 double bby[4];
117
118 bbx[0] = bbx[3] = prob->mMapExtentBounds[0] = extent.xMinimum();
119 bby[0] = bby[1] = prob->mMapExtentBounds[1] = extent.yMinimum();
120 bbx[1] = bbx[2] = prob->mMapExtentBounds[2] = extent.xMaximum();
121 bby[2] = bby[3] = prob->mMapExtentBounds[3] = extent.yMaximum();
122
123 prob->pal = this;
124
125 std::list< std::unique_ptr< Feats > > features;
126
127 // prepare map boundary
128 geos::unique_ptr mapBoundaryGeos( QgsGeos::asGeos( mapBoundary ) );
129 geos::prepared_unique_ptr mapBoundaryPrepared( GEOSPrepare_r( QgsGeos::getGEOSHandler(), mapBoundaryGeos.get() ) );
130
131 int obstacleCount = 0;
132
133 // first step : extract features from layers
134
135 std::size_t previousFeatureCount = 0;
136 int previousObstacleCount = 0;
137
138 QStringList layersWithFeaturesInBBox;
139
140 QMutexLocker palLocker( &mMutex );
141
142 double step = !mLayers.empty() ? 100.0 / mLayers.size() : 1;
143 int index = -1;
144 for ( const auto &it : mLayers )
145 {
146 index++;
147 if ( feedback )
148 feedback->setProgress( index * step );
149
150 Layer *layer = it.second.get();
151 if ( !layer )
152 {
153 // invalid layer name
154 continue;
155 }
156
157 // only select those who are active
158 if ( !layer->active() )
159 continue;
160
161 if ( feedback )
162 feedback->emit candidateCreationAboutToBegin( it.first );
163
164 // check for connected features with the same label text and join them
165 if ( layer->mergeConnectedLines() )
166 layer->joinConnectedFeatures();
167
168 if ( isCanceled() )
169 return nullptr;
170
172
173 if ( isCanceled() )
174 return nullptr;
175
176 QMutexLocker locker( &layer->mMutex );
177
178 const double featureStep = !layer->mFeatureParts.empty() ? step / layer->mFeatureParts.size() : 1;
179 std::size_t featureIndex = 0;
180 // generate candidates for all features
181 for ( const std::unique_ptr< FeaturePart > &featurePart : std::as_const( layer->mFeatureParts ) )
182 {
183 if ( feedback )
184 feedback->setProgress( index * step + featureIndex * featureStep );
185 featureIndex++;
186
187 if ( isCanceled() )
188 break;
189
190 // Holes of the feature are obstacles
191 for ( int i = 0; i < featurePart->getNumSelfObstacles(); i++ )
192 {
193 FeaturePart *selfObstacle = featurePart->getSelfObstacle( i );
194 obstacles.insert( selfObstacle, selfObstacle->boundingBox() );
195 allObstacleParts.emplace_back( selfObstacle );
196
197 if ( !featurePart->getSelfObstacle( i )->getHoleOf() )
198 {
199 //ERROR: SHOULD HAVE A PARENT!!!!!
200 }
201 }
202
203 // generate candidates for the feature part
204 std::vector< std::unique_ptr< LabelPosition > > candidates = featurePart->createCandidates( this );
205
206 if ( isCanceled() )
207 break;
208
209 // purge candidates that are outside the bbox
210 candidates.erase( std::remove_if( candidates.begin(), candidates.end(), [&mapBoundaryPrepared, this]( std::unique_ptr< LabelPosition > &candidate )
211 {
212 if ( showPartialLabels() )
213 return !candidate->intersects( mapBoundaryPrepared.get() );
214 else
215 return !candidate->within( mapBoundaryPrepared.get() );
216 } ), candidates.end() );
217
218 if ( isCanceled() )
219 break;
220
221 if ( !candidates.empty() )
222 {
223 for ( std::unique_ptr< LabelPosition > &candidate : candidates )
224 {
225 candidate->insertIntoIndex( allCandidatesFirstRound );
226 candidate->setGlobalId( mNextCandidateId++ );
227 }
228
229 std::sort( candidates.begin(), candidates.end(), CostCalculator::candidateSortGrow );
230
231 // valid features are added to fFeats
232 std::unique_ptr< Feats > ft = std::make_unique< Feats >();
233 ft->feature = featurePart.get();
234 ft->shape = nullptr;
235 ft->candidates = std::move( candidates );
236 ft->priority = featurePart->calculatePriority();
237 features.emplace_back( std::move( ft ) );
238 }
239 else
240 {
241 // no candidates, so generate a default "point on surface" one
242 std::unique_ptr< LabelPosition > unplacedPosition = featurePart->createCandidatePointOnSurface( featurePart.get() );
243 if ( !unplacedPosition )
244 continue;
245
246 if ( featurePart->feature()->allowDegradedPlacement() )
247 {
248 // if we are allowing degraded placements, we throw the default candidate in too
249 unplacedPosition->insertIntoIndex( allCandidatesFirstRound );
250 unplacedPosition->setGlobalId( mNextCandidateId++ );
251 candidates.emplace_back( std::move( unplacedPosition ) );
252
253 // valid features are added to fFeats
254 std::unique_ptr< Feats > ft = std::make_unique< Feats >();
255 ft->feature = featurePart.get();
256 ft->shape = nullptr;
257 ft->candidates = std::move( candidates );
258 ft->priority = featurePart->calculatePriority();
259 features.emplace_back( std::move( ft ) );
260 }
261 else
262 {
263 // not displaying all labels for this layer, so it goes into the unlabeled feature list
264 prob->positionsWithNoCandidates()->emplace_back( std::move( unplacedPosition ) );
265 }
266 }
267 }
268 if ( isCanceled() )
269 return nullptr;
270
271 // collate all layer obstacles
272 for ( FeaturePart *obstaclePart : std::as_const( layer->mObstacleParts ) )
273 {
274 if ( isCanceled() )
275 break; // do not continue searching
276
277 // insert into obstacles
278 obstacles.insert( obstaclePart, obstaclePart->boundingBox() );
279 allObstacleParts.emplace_back( obstaclePart );
280 obstacleCount++;
281 }
282
283 if ( isCanceled() )
284 return nullptr;
285
286 locker.unlock();
287
288 if ( features.size() - previousFeatureCount > 0 || obstacleCount > previousObstacleCount )
289 {
290 layersWithFeaturesInBBox << layer->name();
291 }
292 previousFeatureCount = features.size();
293 previousObstacleCount = obstacleCount;
294
295 if ( feedback )
296 feedback->emit candidateCreationFinished( it.first );
297 }
298 palLocker.unlock();
299
300 if ( isCanceled() )
301 return nullptr;
302
303 prob->mLayerCount = layersWithFeaturesInBBox.size();
304 prob->labelledLayersName = layersWithFeaturesInBBox;
305
306 prob->mFeatureCount = features.size();
307 prob->mTotalCandidates = 0;
308 prob->mFeatNbLp.resize( prob->mFeatureCount );
309 prob->mFeatStartId.resize( prob->mFeatureCount );
310 prob->mInactiveCost.resize( prob->mFeatureCount );
311
312 if ( !features.empty() )
313 {
314 if ( feedback )
315 feedback->emit obstacleCostingAboutToBegin();
316 // Filtering label positions against obstacles
317 index = -1;
318 step = !allObstacleParts.empty() ? 100.0 / allObstacleParts.size() : 1;
319
320 for ( FeaturePart *obstaclePart : allObstacleParts )
321 {
322 index++;
323 if ( feedback )
324 feedback->setProgress( step * index );
325
326 if ( isCanceled() )
327 break; // do not continue searching
328
329 allCandidatesFirstRound.intersects( obstaclePart->boundingBox(), [obstaclePart, this]( const LabelPosition * candidatePosition ) -> bool
330 {
331 // test whether we should ignore this obstacle for the candidate. We do this if:
332 // 1. it's not a hole, and the obstacle belongs to the same label feature as the candidate (e.g.,
333 // features aren't obstacles for their own labels)
334 // 2. it IS a hole, and the hole belongs to a different label feature to the candidate (e.g., holes
335 // are ONLY obstacles for the labels of the feature they belong to)
336 // 3. The label is set to "Always Allow" overlap mode
337 if ( candidatePosition->getFeaturePart()->feature()->overlapHandling() == Qgis::LabelOverlapHandling::AllowOverlapAtNoCost
338 || ( !obstaclePart->getHoleOf() && candidatePosition->getFeaturePart()->hasSameLabelFeatureAs( obstaclePart ) )
339 || ( obstaclePart->getHoleOf() && !candidatePosition->getFeaturePart()->hasSameLabelFeatureAs( dynamic_cast< FeaturePart * >( obstaclePart->getHoleOf() ) ) ) )
340 {
341 return true;
342 }
343
344 CostCalculator::addObstacleCostPenalty( const_cast< LabelPosition * >( candidatePosition ), obstaclePart, this );
345
346 return true;
347 } );
348 }
349
350 if ( feedback )
351 feedback->emit obstacleCostingFinished();
352
353 if ( isCanceled() )
354 {
355 return nullptr;
356 }
357
358 step = prob->mFeatureCount != 0 ? 100.0 / prob->mFeatureCount : 1;
359 if ( feedback )
360 feedback->emit calculatingConflictsAboutToBegin();
361
362 int idlp = 0;
363 for ( std::size_t i = 0; i < prob->mFeatureCount; i++ ) /* for each feature into prob */
364 {
365 if ( feedback )
366 feedback->setProgress( i * step );
367
368 std::unique_ptr< Feats > feat = std::move( features.front() );
369 features.pop_front();
370
371 prob->mFeatStartId[i] = idlp;
372 prob->mInactiveCost[i] = std::pow( 2, 10 - 10 * feat->priority );
373
374 std::size_t maxCandidates = 0;
375 switch ( feat->feature->getGeosType() )
376 {
377 case GEOS_POINT:
378 // this is usually 0, i.e. no maximum
379 maxCandidates = feat->feature->maximumPointCandidates();
380 break;
381
382 case GEOS_LINESTRING:
383 maxCandidates = feat->feature->maximumLineCandidates();
384 break;
385
386 case GEOS_POLYGON:
387 maxCandidates = std::max( static_cast< std::size_t >( 16 ), feat->feature->maximumPolygonCandidates() );
388 break;
389 }
390
391 if ( isCanceled() )
392 return nullptr;
393
394 auto pruneHardConflicts = [&]
395 {
396 switch ( mPlacementVersion )
397 {
398 case Qgis::LabelPlacementEngineVersion::Version1:
399 break;
400
401 case Qgis::LabelPlacementEngineVersion::Version2:
402 {
403 // v2 placement rips out candidates where the candidate cost is too high when compared to
404 // their inactive cost
405
406 // note, we start this at the SECOND candidate (you'll see why after this loop)
407 feat->candidates.erase( std::remove_if( feat->candidates.begin() + 1, feat->candidates.end(), [ & ]( std::unique_ptr< LabelPosition > &candidate )
408 {
409 if ( candidate->hasHardObstacleConflict() )
410 {
411 return true;
412 }
413 return false;
414 } ), feat->candidates.end() );
415
416 if ( feat->candidates.size() == 1 && feat->candidates[ 0 ]->hasHardObstacleConflict() )
417 {
418 switch ( feat->feature->feature()->overlapHandling() )
419 {
421 {
422 // we're going to end up removing ALL candidates for this label. Oh well, that's allowed. We just need to
423 // make sure we move this last candidate to the unplaced labels list
424 prob->positionsWithNoCandidates()->emplace_back( std::move( feat->candidates.front() ) );
425 feat->candidates.clear();
426 break;
427 }
428
431 // we can't avoid overlaps for this label, but in this mode we are allowing overlaps as a last resort.
432 // => don't discard this last remaining candidate.
433 break;
434 }
435 }
436 }
437 }
438 };
439
440 // if we're not showing all labels (including conflicts) for this layer, then we prune the candidates
441 // upfront to avoid extra work...
442 switch ( feat->feature->feature()->overlapHandling() )
443 {
445 pruneHardConflicts();
446 break;
447
450 break;
451 }
452
453 if ( feat->candidates.empty() )
454 continue;
455
456 // calculate final costs
457 CostCalculator::finalizeCandidatesCosts( feat.get(), bbx, bby );
458
459 // sort candidates list, best label to worst
460 std::sort( feat->candidates.begin(), feat->candidates.end(), CostCalculator::candidateSortGrow );
461
462 // but if we ARE showing all labels (including conflicts), let's go ahead and prune them now.
463 // Since we've calculated all their costs and sorted them, if we've hit the situation that ALL
464 // candidates have conflicts, then at least when we pick the first candidate to display it will be
465 // the lowest cost (i.e. best possible) overlapping candidate...
466 switch ( feat->feature->feature()->overlapHandling() )
467 {
469 break;
472 pruneHardConflicts();
473 break;
474 }
475
476 // only keep the 'maxCandidates' best candidates
477 if ( maxCandidates > 0 && feat->candidates.size() > maxCandidates )
478 {
479 feat->candidates.resize( maxCandidates );
480 }
481
482 if ( isCanceled() )
483 return nullptr;
484
485 // update problem's # candidate
486 prob->mFeatNbLp[i] = static_cast< int >( feat->candidates.size() );
487 prob->mTotalCandidates += static_cast< int >( feat->candidates.size() );
488
489 // add all candidates into a rtree (to speed up conflicts searching)
490 for ( std::unique_ptr< LabelPosition > &candidate : feat->candidates )
491 {
492 candidate->insertIntoIndex( prob->allCandidatesIndex() );
493 candidate->setProblemIds( static_cast< int >( i ), idlp++ );
494 }
495 features.emplace_back( std::move( feat ) );
496 }
497
498 if ( feedback )
499 feedback->emit calculatingConflictsFinished();
500
501 int nbOverlaps = 0;
502
503 double amin[2];
504 double amax[2];
505
506 if ( feedback )
507 feedback->emit finalizingCandidatesAboutToBegin();
508
509 index = -1;
510 step = !features.empty() ? 100.0 / features.size() : 1;
511 while ( !features.empty() ) // for each feature
512 {
513 index++;
514 if ( feedback )
515 feedback->setProgress( step * index );
516
517 if ( isCanceled() )
518 return nullptr;
519
520 std::unique_ptr< Feats > feat = std::move( features.front() );
521 features.pop_front();
522
523 for ( std::unique_ptr< LabelPosition > &candidate : feat->candidates )
524 {
525 std::unique_ptr< LabelPosition > lp = std::move( candidate );
526
527 lp->resetNumOverlaps();
528
529 // make sure that candidate's cost is less than 1
530 lp->validateCost();
531
532 //prob->feat[idlp] = j;
533
534 // lookup for overlapping candidate
535 lp->getBoundingBox( amin, amax );
536 prob->allCandidatesIndex().intersects( QgsRectangle( amin[0], amin[1], amax[0], amax[1] ), [&lp, this]( const LabelPosition * lp2 )->bool
537 {
538 if ( candidatesAreConflicting( lp.get(), lp2 ) )
539 {
540 lp->incrementNumOverlaps();
541 }
542
543 return true;
544
545 } );
546
547 nbOverlaps += lp->getNumOverlaps();
548
549 prob->addCandidatePosition( std::move( lp ) );
550
551 if ( isCanceled() )
552 return nullptr;
553 }
554 }
555
556 if ( feedback )
557 feedback->emit finalizingCandidatesFinished();
558
559 nbOverlaps /= 2;
560 prob->mAllNblp = prob->mTotalCandidates;
561 prob->mNbOverlap = nbOverlaps;
562 }
563
564 return prob;
565}
566
568{
569 fnIsCanceled = fnCanceled;
570 fnIsCanceledContext = context;
571}
572
573
574QList<LabelPosition *> Pal::solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<LabelPosition *> *unlabeled )
575{
576 QgsLabelingEngineFeedback *feedback = qobject_cast< QgsLabelingEngineFeedback * >( context.feedback() );
577
578 if ( !prob )
579 return QList<LabelPosition *>();
580
581 if ( feedback )
582 feedback->emit reductionAboutToBegin();
583
584 prob->reduce();
585
586 if ( feedback )
587 feedback->emit reductionFinished();
588
589 if ( feedback )
590 feedback->emit solvingPlacementAboutToBegin();
591
592 try
593 {
594 prob->chainSearch( context );
595 }
596 catch ( InternalException::Empty & )
597 {
598 return QList<LabelPosition *>();
599 }
600
601 if ( feedback )
602 feedback->emit solvingPlacementFinished();
603
604 return prob->getSolution( displayAll, unlabeled );
605}
606
607void Pal::setMinIt( int min_it )
608{
609 if ( min_it >= 0 )
610 mTabuMinIt = min_it;
611}
612
613void Pal::setMaxIt( int max_it )
614{
615 if ( max_it > 0 )
616 mTabuMaxIt = max_it;
617}
618
619void Pal::setPopmusicR( int r )
620{
621 if ( r > 0 )
622 mPopmusicR = r;
623}
624
625void Pal::setEjChainDeg( int degree )
626{
627 this->mEjChainDeg = degree;
628}
629
630void Pal::setTenure( int tenure )
631{
632 this->mTenure = tenure;
633}
634
635void Pal::setCandListSize( double fact )
636{
637 this->mCandListSize = fact;
638}
639
641{
642 this->mShowPartialLabels = show;
643}
644
646{
647 return mPlacementVersion;
648}
649
651{
652 mPlacementVersion = placementVersion;
653}
654
656{
657 // we cache the value -- this can be costly to calculate, and we check this multiple times
658 // per candidate during the labeling problem solving
659
660 // conflicts are commutative - so we always store them in the cache using the smaller id as the first element of the key pair
661 auto key = qMakePair( std::min( lp1->globalId(), lp2->globalId() ), std::max( lp1->globalId(), lp2->globalId() ) );
662 auto it = mCandidateConflicts.constFind( key );
663 if ( it != mCandidateConflicts.constEnd() )
664 return *it;
665
666 const bool res = lp1->isInConflict( lp2 );
667 mCandidateConflicts.insert( key, res );
668 return res;
669}
670
671int Pal::getMinIt() const
672{
673 return mTabuMaxIt;
674}
675
676int Pal::getMaxIt() const
677{
678 return mTabuMinIt;
679}
680
682{
683 return mShowPartialLabels;
684}
A rtree spatial index for use in the pal labeling engine.
Definition: palrtree.h:36
void insert(T *data, const QgsRectangle &bounds)
Inserts new data into the spatial index, with the specified bounds.
Definition: palrtree.h:59
bool intersects(const QgsRectangle &bounds, const std::function< bool(T *data)> &callback) const
Performs an intersection check against the index, for data intersecting the specified bounds.
Definition: palrtree.h:96
LabelPlacement
Placement modes which determine how label candidates are generated for a feature.
Definition: qgis.h:731
LabelPlacementEngineVersion
Labeling placement engine version.
Definition: qgis.h:1772
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
@ AllowOverlapIfRequired
Avoids overlapping labels when possible, but permit overlaps if labels for features cannot otherwise ...
@ PreventOverlap
Do not allow labels to overlap other labels.
The QgsAbstractLabelProvider class is an interface class.
void setProgress(double progress)
Sets the current progress for the feedback object.
Definition: qgsfeedback.h:63
A geometry is the spatial representation of a feature.
Definition: qgsgeometry.h:164
static geos::unique_ptr asGeos(const QgsGeometry &geometry, double precision=0)
Returns a geos geometry - caller takes ownership of the object (should be deleted with GEOSGeom_destr...
Definition: qgsgeos.cpp:220
static GEOSContextHandle_t getGEOSHandler()
Definition: qgsgeos.cpp:3450
QgsFeedback subclass for granular reporting of labeling engine progress.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
double height() const SIP_HOLDGIL
Returns the height of the rectangle.
Definition: qgsrectangle.h:230
double width() const SIP_HOLDGIL
Returns the width of the rectangle.
Definition: qgsrectangle.h:223
QgsRectangle buffered(double width) const
Gets rectangle enlarged by buffer.
Definition: qgsrectangle.h:325
Contains information about the context of a rendering operation.
QgsFeedback * feedback() const
Returns the feedback object that can be queried regularly during rendering to check if rendering shou...
T value(const QString &dynamicKeyPart=QString()) const
Returns settings value.
An integer settings entry.
static void addObstacleCostPenalty(pal::LabelPosition *lp, pal::FeaturePart *obstacle, Pal *pal)
Increase candidate's cost according to its collision with passed feature.
static void finalizeCandidatesCosts(Feats *feat, double bbx[4], double bby[4])
Sort candidates by costs, skip the worse ones, evaluate polygon candidates.
static bool candidateSortGrow(const std::unique_ptr< pal::LabelPosition > &c1, const std::unique_ptr< pal::LabelPosition > &c2)
Sorts label candidates in ascending order of cost.
Main class to handle feature.
Definition: feature.h:65
FeaturePart * getSelfObstacle(int i)
Gets hole (inner ring) - considered as obstacle.
Definition: feature.h:308
Thrown when trying to access an empty data set.
LabelPosition is a candidate feature label position.
Definition: labelposition.h:56
bool isInConflict(const LabelPosition *ls) const
Check whether or not this overlap with another labelPosition.
unsigned int globalId() const
Returns the global ID for the candidate, which is unique for a single run of the pal labelling engine...
A set of features which influence the labeling process.
Definition: layer.h:63
QMutex mMutex
Definition: layer.h:345
std::deque< std::unique_ptr< FeaturePart > > mFeatureParts
List of feature parts.
Definition: layer.h:316
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
Definition: layer.h:319
QString name() const
Returns the layer's name.
Definition: layer.h:162
bool active() const
Returns whether the layer is currently active.
Definition: layer.h:198
bool mergeConnectedLines() const
Returns whether connected lines will be merged before labeling.
Definition: layer.h:256
void joinConnectedFeatures()
Join connected features with the same label text.
Definition: layer.cpp:297
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance.
Definition: layer.cpp:365
void setPlacementVersion(Qgis::LabelPlacementEngineVersion placementVersion)
Sets the placement engine version, which dictates how the label placement problem is solved.
Definition: pal.cpp:650
void setShowPartialLabels(bool show)
Sets whether partial labels show be allowed.
Definition: pal.cpp:640
std::unique_ptr< Problem > extractProblem(const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context)
Extracts the labeling problem for the specified map extent - only features within this extent will be...
Definition: pal.cpp:100
Qgis::LabelPlacementEngineVersion placementVersion() const
Returns the placement engine version, which dictates how the label placement problem is solved.
Definition: pal.cpp:645
void removeLayer(Layer *layer)
remove a layer
Definition: pal.cpp:68
bool candidatesAreConflicting(const LabelPosition *lp1, const LabelPosition *lp2) const
Returns true if a labelling candidate lp1 conflicts with lp2.
Definition: pal.cpp:655
bool(* FnIsCanceled)(void *ctx)
Definition: pal.h:128
bool showPartialLabels() const
Returns whether partial labels should be allowed.
Definition: pal.cpp:681
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitLines
Definition: pal.h:92
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPoints
Definition: pal.h:91
static const QgsSettingsEntryInteger * settingsRenderingLabelCandidatesLimitPolygons
Definition: pal.h:93
bool isCanceled()
Check whether the job has been canceled.
Definition: pal.h:134
QList< LabelPosition * > solveProblem(Problem *prob, QgsRenderContext &context, bool displayAll, QList< pal::LabelPosition * > *unlabeled=nullptr)
Solves the labeling problem, selecting the best candidate locations for all labels and returns a list...
Definition: pal.cpp:574
void registerCancellationCallback(FnIsCanceled fnCanceled, void *context)
Register a function that returns whether this job has been canceled - PAL calls it during the computa...
Definition: pal.cpp:567
Layer * addLayer(QgsAbstractLabelProvider *provider, const QString &layerName, Qgis::LabelPlacement arrangement, double defaultPriority, bool active, bool toLabel)
add a new layer
Definition: pal.cpp:86
QgsRectangle boundingBox() const
Returns the point set bounding box.
Definition: pointset.h:163
Representation of a labeling problem.
Definition: problem.h:73
QList< LabelPosition * > getSolution(bool returnInactive, QList< LabelPosition * > *unlabeled=nullptr)
Solves the labeling problem, selecting the best candidate locations for all labels and returns a list...
Definition: problem.cpp:659
void chainSearch(QgsRenderContext &context)
Test with very-large scale neighborhood.
Definition: problem.cpp:573
void reduce()
Definition: problem.cpp:66
std::unique_ptr< const GEOSPreparedGeometry, GeosDeleter > prepared_unique_ptr
Scoped GEOS prepared geometry pointer.
Definition: qgsgeos.h:79
std::unique_ptr< GEOSGeometry, GeosDeleter > unique_ptr
Scoped GEOS pointer.
Definition: qgsgeos.h:74