QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
•All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // cppcheck-suppress returnDanglingLifetime
98 return res;
99}
100
101std::unique_ptr<Problem> Pal::extractProblem( const QgsRectangle &extent, const QgsGeometry &mapBoundary, QgsRenderContext &context )
102{
103 QgsLabelingEngineFeedback *feedback = qobject_cast< QgsLabelingEngineFeedback * >( context.feedback() );
104
105 // expand out the incoming buffer by 1000x -- that's the visible map extent, yet we may be getting features which exceed this extent
106 // (while 1000x may seem excessive here, this value is only used for scaling coordinates in the spatial indexes
107 // and the consequence of inserting coordinates outside this extent is worse than the consequence of setting this value too large.)
108 const QgsRectangle maxCoordinateExtentForSpatialIndices = extent.buffered( std::max( extent.width(), extent.height() ) * 1000 );
109
110 // to store obstacles
111 PalRtree< FeaturePart > obstacles( maxCoordinateExtentForSpatialIndices );
112 PalRtree< LabelPosition > allCandidatesFirstRound( maxCoordinateExtentForSpatialIndices );
113 std::vector< FeaturePart * > allObstacleParts;
114 std::unique_ptr< Problem > prob = std::make_unique< Problem >( maxCoordinateExtentForSpatialIndices );
115
116 double bbx[4];
117 double bby[4];
118
119 bbx[0] = bbx[3] = prob->mMapExtentBounds[0] = extent.xMinimum();
120 bby[0] = bby[1] = prob->mMapExtentBounds[1] = extent.yMinimum();
121 bbx[1] = bbx[2] = prob->mMapExtentBounds[2] = extent.xMaximum();
122 bby[2] = bby[3] = prob->mMapExtentBounds[3] = extent.yMaximum();
123
124 prob->pal = this;
125
126 std::list< std::unique_ptr< Feats > > features;
127
128 // prepare map boundary
129 geos::unique_ptr mapBoundaryGeos( QgsGeos::asGeos( mapBoundary ) );
130 geos::prepared_unique_ptr mapBoundaryPrepared( GEOSPrepare_r( QgsGeos::getGEOSHandler(), mapBoundaryGeos.get() ) );
131
132 int obstacleCount = 0;
133
134 // first step : extract features from layers
135
136 std::size_t previousFeatureCount = 0;
137 int previousObstacleCount = 0;
138
139 QStringList layersWithFeaturesInBBox;
140
141 QMutexLocker palLocker( &mMutex );
142
143 double step = !mLayers.empty() ? 100.0 / mLayers.size() : 1;
144 int index = -1;
145 for ( const auto &it : mLayers )
146 {
147 index++;
148 if ( feedback )
149 feedback->setProgress( index * step );
150
151 Layer *layer = it.second.get();
152 if ( !layer )
153 {
154 // invalid layer name
155 continue;
156 }
157
158 // only select those who are active
159 if ( !layer->active() )
160 continue;
161
162 if ( feedback )
163 feedback->emit candidateCreationAboutToBegin( it.first );
164
165 // check for connected features with the same label text and join them
166 if ( layer->mergeConnectedLines() )
167 layer->joinConnectedFeatures();
168
169 if ( isCanceled() )
170 return nullptr;
171
173
174 if ( isCanceled() )
175 return nullptr;
176
177 QMutexLocker locker( &layer->mMutex );
178
179 const double featureStep = !layer->mFeatureParts.empty() ? step / layer->mFeatureParts.size() : 1;
180 std::size_t featureIndex = 0;
181 // generate candidates for all features
182 for ( const std::unique_ptr< FeaturePart > &featurePart : std::as_const( layer->mFeatureParts ) )
183 {
184 if ( feedback )
185 feedback->setProgress( index * step + featureIndex * featureStep );
186 featureIndex++;
187
188 if ( isCanceled() )
189 break;
190
191 // Holes of the feature are obstacles
192 for ( int i = 0; i < featurePart->getNumSelfObstacles(); i++ )
193 {
194 FeaturePart *selfObstacle = featurePart->getSelfObstacle( i );
195 obstacles.insert( selfObstacle, selfObstacle->boundingBox() );
196 allObstacleParts.emplace_back( selfObstacle );
197
198 if ( !featurePart->getSelfObstacle( i )->getHoleOf() )
199 {
200 //ERROR: SHOULD HAVE A PARENT!!!!!
201 }
202 }
203
204 // generate candidates for the feature part
205 std::vector< std::unique_ptr< LabelPosition > > candidates = featurePart->createCandidates( this );
206
207 if ( isCanceled() )
208 break;
209
210 // purge candidates that are outside the bbox
211 candidates.erase( std::remove_if( candidates.begin(), candidates.end(), [&mapBoundaryPrepared, this]( std::unique_ptr< LabelPosition > &candidate )
212 {
213 if ( showPartialLabels() )
214 return !candidate->intersects( mapBoundaryPrepared.get() );
215 else
216 return !candidate->within( mapBoundaryPrepared.get() );
217 } ), candidates.end() );
218
219 if ( isCanceled() )
220 break;
221
222 if ( !candidates.empty() )
223 {
224 for ( std::unique_ptr< LabelPosition > &candidate : candidates )
225 {
226 candidate->insertIntoIndex( allCandidatesFirstRound );
227 candidate->setGlobalId( mNextCandidateId++ );
228 }
229
230 std::sort( candidates.begin(), candidates.end(), CostCalculator::candidateSortGrow );
231
232 // valid features are added to fFeats
233 std::unique_ptr< Feats > ft = std::make_unique< Feats >();
234 ft->feature = featurePart.get();
235 ft->shape = nullptr;
236 ft->candidates = std::move( candidates );
237 ft->priority = featurePart->calculatePriority();
238 features.emplace_back( std::move( ft ) );
239 }
240 else
241 {
242 // no candidates, so generate a default "point on surface" one
243 std::unique_ptr< LabelPosition > unplacedPosition = featurePart->createCandidatePointOnSurface( featurePart.get() );
244 if ( !unplacedPosition )
245 continue;
246
247 if ( featurePart->feature()->allowDegradedPlacement() )
248 {
249 // if we are allowing degraded placements, we throw the default candidate in too
250 unplacedPosition->insertIntoIndex( allCandidatesFirstRound );
251 unplacedPosition->setGlobalId( mNextCandidateId++ );
252 candidates.emplace_back( std::move( unplacedPosition ) );
253
254 // valid features are added to fFeats
255 std::unique_ptr< Feats > ft = std::make_unique< Feats >();
256 ft->feature = featurePart.get();
257 ft->shape = nullptr;
258 ft->candidates = std::move( candidates );
259 ft->priority = featurePart->calculatePriority();
260 features.emplace_back( std::move( ft ) );
261 }
262 else
263 {
264 // not displaying all labels for this layer, so it goes into the unlabeled feature list
265 prob->positionsWithNoCandidates()->emplace_back( std::move( unplacedPosition ) );
266 }
267 }
268 }
269 if ( isCanceled() )
270 return nullptr;
271
272 // collate all layer obstacles
273 for ( FeaturePart *obstaclePart : std::as_const( layer->mObstacleParts ) )
274 {
275 if ( isCanceled() )
276 break; // do not continue searching
277
278 // insert into obstacles
279 obstacles.insert( obstaclePart, obstaclePart->boundingBox() );
280 allObstacleParts.emplace_back( obstaclePart );
281 obstacleCount++;
282 }
283
284 if ( isCanceled() )
285 return nullptr;
286
287 locker.unlock();
288
289 if ( features.size() - previousFeatureCount > 0 || obstacleCount > previousObstacleCount )
290 {
291 layersWithFeaturesInBBox << layer->name();
292 }
293 previousFeatureCount = features.size();
294 previousObstacleCount = obstacleCount;
295
296 if ( feedback )
297 feedback->emit candidateCreationFinished( it.first );
298 }
299 palLocker.unlock();
300
301 if ( isCanceled() )
302 return nullptr;
303
304 prob->mLayerCount = layersWithFeaturesInBBox.size();
305 prob->labelledLayersName = layersWithFeaturesInBBox;
306
307 prob->mFeatureCount = features.size();
308 prob->mTotalCandidates = 0;
309 prob->mFeatNbLp.resize( prob->mFeatureCount );
310 prob->mFeatStartId.resize( prob->mFeatureCount );
311 prob->mInactiveCost.resize( prob->mFeatureCount );
312
313 if ( !features.empty() )
314 {
315 if ( feedback )
316 feedback->emit obstacleCostingAboutToBegin();
317 // Filtering label positions against obstacles
318 index = -1;
319 step = !allObstacleParts.empty() ? 100.0 / allObstacleParts.size() : 1;
320
321 for ( FeaturePart *obstaclePart : allObstacleParts )
322 {
323 index++;
324 if ( feedback )
325 feedback->setProgress( step * index );
326
327 if ( isCanceled() )
328 break; // do not continue searching
329
330 allCandidatesFirstRound.intersects( obstaclePart->boundingBox(), [obstaclePart, this]( const LabelPosition * candidatePosition ) -> bool
331 {
332 // test whether we should ignore this obstacle for the candidate. We do this if:
333 // 1. it's not a hole, and the obstacle belongs to the same label feature as the candidate (e.g.,
334 // features aren't obstacles for their own labels)
335 // 2. it IS a hole, and the hole belongs to a different label feature to the candidate (e.g., holes
336 // are ONLY obstacles for the labels of the feature they belong to)
337 // 3. The label is set to "Always Allow" overlap mode
338 if ( candidatePosition->getFeaturePart()->feature()->overlapHandling() == Qgis::LabelOverlapHandling::AllowOverlapAtNoCost
339 || ( !obstaclePart->getHoleOf() && candidatePosition->getFeaturePart()->hasSameLabelFeatureAs( obstaclePart ) )
340 || ( obstaclePart->getHoleOf() && !candidatePosition->getFeaturePart()->hasSameLabelFeatureAs( dynamic_cast< FeaturePart * >( obstaclePart->getHoleOf() ) ) ) )
341 {
342 return true;
343 }
344
345 CostCalculator::addObstacleCostPenalty( const_cast< LabelPosition * >( candidatePosition ), obstaclePart, this );
346
347 return true;
348 } );
349 }
350
351 if ( feedback )
352 feedback->emit obstacleCostingFinished();
353
354 if ( isCanceled() )
355 {
356 return nullptr;
357 }
358
359 step = prob->mFeatureCount != 0 ? 100.0 / prob->mFeatureCount : 1;
360 if ( feedback )
361 feedback->emit calculatingConflictsAboutToBegin();
362
363 int idlp = 0;
364 for ( std::size_t i = 0; i < prob->mFeatureCount; i++ ) /* for each feature into prob */
365 {
366 if ( feedback )
367 feedback->setProgress( i * step );
368
369 std::unique_ptr< Feats > feat = std::move( features.front() );
370 features.pop_front();
371
372 prob->mFeatStartId[i] = idlp;
373 prob->mInactiveCost[i] = std::pow( 2, 10 - 10 * feat->priority );
374
375 std::size_t maxCandidates = 0;
376 switch ( feat->feature->getGeosType() )
377 {
378 case GEOS_POINT:
379 // this is usually 0, i.e. no maximum
380 maxCandidates = feat->feature->maximumPointCandidates();
381 break;
382
383 case GEOS_LINESTRING:
384 maxCandidates = feat->feature->maximumLineCandidates();
385 break;
386
387 case GEOS_POLYGON:
388 maxCandidates = std::max( static_cast< std::size_t >( 16 ), feat->feature->maximumPolygonCandidates() );
389 break;
390 }
391
392 if ( isCanceled() )
393 return nullptr;
394
395 auto pruneHardConflicts = [&]
396 {
397 switch ( mPlacementVersion )
398 {
399 case Qgis::LabelPlacementEngineVersion::Version1:
400 break;
401
402 case Qgis::LabelPlacementEngineVersion::Version2:
403 {
404 // v2 placement rips out candidates where the candidate cost is too high when compared to
405 // their inactive cost
406
407 // note, we start this at the SECOND candidate (you'll see why after this loop)
408 feat->candidates.erase( std::remove_if( feat->candidates.begin() + 1, feat->candidates.end(), [ & ]( std::unique_ptr< LabelPosition > &candidate )
409 {
410 if ( candidate->hasHardObstacleConflict() )
411 {
412 return true;
413 }
414 return false;
415 } ), feat->candidates.end() );
416
417 if ( feat->candidates.size() == 1 && feat->candidates[ 0 ]->hasHardObstacleConflict() )
418 {
419 switch ( feat->feature->feature()->overlapHandling() )
420 {
422 {
423 // we're going to end up removing ALL candidates for this label. Oh well, that's allowed. We just need to
424 // make sure we move this last candidate to the unplaced labels list
425 prob->positionsWithNoCandidates()->emplace_back( std::move( feat->candidates.front() ) );
426 feat->candidates.clear();
427 break;
428 }
429
432 // we can't avoid overlaps for this label, but in this mode we are allowing overlaps as a last resort.
433 // => don't discard this last remaining candidate.
434 break;
435 }
436 }
437 }
438 }
439 };
440
441 // if we're not showing all labels (including conflicts) for this layer, then we prune the candidates
442 // upfront to avoid extra work...
443 switch ( feat->feature->feature()->overlapHandling() )
444 {
446 pruneHardConflicts();
447 break;
448
451 break;
452 }
453
454 if ( feat->candidates.empty() )
455 continue;
456
457 // calculate final costs
458 CostCalculator::finalizeCandidatesCosts( feat.get(), bbx, bby );
459
460 // sort candidates list, best label to worst
461 std::sort( feat->candidates.begin(), feat->candidates.end(), CostCalculator::candidateSortGrow );
462
463 // but if we ARE showing all labels (including conflicts), let's go ahead and prune them now.
464 // Since we've calculated all their costs and sorted them, if we've hit the situation that ALL
465 // candidates have conflicts, then at least when we pick the first candidate to display it will be
466 // the lowest cost (i.e. best possible) overlapping candidate...
467 switch ( feat->feature->feature()->overlapHandling() )
468 {
470 break;
473 pruneHardConflicts();
474 break;
475 }
476
477 // only keep the 'maxCandidates' best candidates
478 if ( maxCandidates > 0 && feat->candidates.size() > maxCandidates )
479 {
480 feat->candidates.resize( maxCandidates );
481 }
482
483 if ( isCanceled() )
484 return nullptr;
485
486 // update problem's # candidate
487 prob->mFeatNbLp[i] = static_cast< int >( feat->candidates.size() );
488 prob->mTotalCandidates += static_cast< int >( feat->candidates.size() );
489
490 // add all candidates into a rtree (to speed up conflicts searching)
491 for ( std::unique_ptr< LabelPosition > &candidate : feat->candidates )
492 {
493 candidate->insertIntoIndex( prob->allCandidatesIndex() );
494 candidate->setProblemIds( static_cast< int >( i ), idlp++ );
495 }
496 features.emplace_back( std::move( feat ) );
497 }
498
499 if ( feedback )
500 feedback->emit calculatingConflictsFinished();
501
502 int nbOverlaps = 0;
503
504 double amin[2];
505 double amax[2];
506
507 if ( feedback )
508 feedback->emit finalizingCandidatesAboutToBegin();
509
510 index = -1;
511 step = !features.empty() ? 100.0 / features.size() : 1;
512 while ( !features.empty() ) // for each feature
513 {
514 index++;
515 if ( feedback )
516 feedback->setProgress( step * index );
517
518 if ( isCanceled() )
519 return nullptr;
520
521 std::unique_ptr< Feats > feat = std::move( features.front() );
522 features.pop_front();
523
524 for ( std::unique_ptr< LabelPosition > &candidate : feat->candidates )
525 {
526 std::unique_ptr< LabelPosition > lp = std::move( candidate );
527
528 lp->resetNumOverlaps();
529
530 // make sure that candidate's cost is less than 1
531 lp->validateCost();
532
533 //prob->feat[idlp] = j;
534
535 // lookup for overlapping candidate
536 lp->getBoundingBox( amin, amax );
537 prob->allCandidatesIndex().intersects( QgsRectangle( amin[0], amin[1], amax[0], amax[1] ), [&lp, this]( const LabelPosition * lp2 )->bool
538 {
539 if ( candidatesAreConflicting( lp.get(), lp2 ) )
540 {
541 lp->incrementNumOverlaps();
542 }
543
544 return true;
545
546 } );
547
548 nbOverlaps += lp->getNumOverlaps();
549
550 prob->addCandidatePosition( std::move( lp ) );
551
552 if ( isCanceled() )
553 return nullptr;
554 }
555 }
556
557 if ( feedback )
558 feedback->emit finalizingCandidatesFinished();
559
560 nbOverlaps /= 2;
561 prob->mAllNblp = prob->mTotalCandidates;
562 prob->mNbOverlap = nbOverlaps;
563 }
564
565 return prob;
566}
567
569{
570 fnIsCanceled = fnCanceled;
571 fnIsCanceledContext = context;
572}
573
574
575QList<LabelPosition *> Pal::solveProblem( Problem *prob, QgsRenderContext &context, bool displayAll, QList<LabelPosition *> *unlabeled )
576{
577 QgsLabelingEngineFeedback *feedback = qobject_cast< QgsLabelingEngineFeedback * >( context.feedback() );
578
579 if ( !prob )
580 return QList<LabelPosition *>();
581
582 if ( feedback )
583 feedback->emit reductionAboutToBegin();
584
585 prob->reduce();
586
587 if ( feedback )
588 feedback->emit reductionFinished();
589
590 if ( feedback )
591 feedback->emit solvingPlacementAboutToBegin();
592
593 try
594 {
595 prob->chainSearch( context );
596 }
597 catch ( InternalException::Empty & )
598 {
599 return QList<LabelPosition *>();
600 }
601
602 if ( feedback )
603 feedback->emit solvingPlacementFinished();
604
605 return prob->getSolution( displayAll, unlabeled );
606}
607
608void Pal::setMinIt( int min_it )
609{
610 if ( min_it >= 0 )
611 mTabuMinIt = min_it;
612}
613
614void Pal::setMaxIt( int max_it )
615{
616 if ( max_it > 0 )
617 mTabuMaxIt = max_it;
618}
619
620void Pal::setPopmusicR( int r )
621{
622 if ( r > 0 )
623 mPopmusicR = r;
624}
625
626void Pal::setEjChainDeg( int degree )
627{
628 this->mEjChainDeg = degree;
629}
630
631void Pal::setTenure( int tenure )
632{
633 this->mTenure = tenure;
634}
635
636void Pal::setCandListSize( double fact )
637{
638 this->mCandListSize = fact;
639}
640
642{
643 this->mShowPartialLabels = show;
644}
645
647{
648 return mPlacementVersion;
649}
650
652{
653 mPlacementVersion = placementVersion;
654}
655
657{
658 // we cache the value -- this can be costly to calculate, and we check this multiple times
659 // per candidate during the labeling problem solving
660
661 // conflicts are commutative - so we always store them in the cache using the smaller id as the first element of the key pair
662 auto key = qMakePair( std::min( lp1->globalId(), lp2->globalId() ), std::max( lp1->globalId(), lp2->globalId() ) );
663 auto it = mCandidateConflicts.constFind( key );
664 if ( it != mCandidateConflicts.constEnd() )
665 return *it;
666
667 const bool res = lp1->isInConflict( lp2 );
668 mCandidateConflicts.insert( key, res );
669 return res;
670}
671
672int Pal::getMinIt() const
673{
674 return mTabuMaxIt;
675}
676
677int Pal::getMaxIt() const
678{
679 return mTabuMinIt;
680}
681
683{
684 return mShowPartialLabels;
685}
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:782
LabelPlacementEngineVersion
Labeling placement engine version.
Definition: qgis.h:1930
@ 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:3451
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:309
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:651
void setShowPartialLabels(bool show)
Sets whether partial labels show be allowed.
Definition: pal.cpp:641
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:101
Qgis::LabelPlacementEngineVersion placementVersion() const
Returns the placement engine version, which dictates how the label placement problem is solved.
Definition: pal.cpp:646
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:656
bool(* FnIsCanceled)(void *ctx)
Definition: pal.h:128
bool showPartialLabels() const
Returns whether partial labels should be allowed.
Definition: pal.cpp:682
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:575
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:568
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:662
void chainSearch(QgsRenderContext &context)
Test with very-large scale neighborhood.
Definition: problem.cpp:578
void reduce()
Definition: problem.cpp:71
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