QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
feature.h
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#ifndef FEATURE_H
31#define FEATURE_H
32
33
34#include <cmath>
35#include <fstream>
36#include <iostream>
37
38#include "labelposition.h"
39#include "pointset.h"
40#include "qgis_core.h"
41#include "qgslabelfeature.h"
43
44#include <QString>
45
46#define SIP_NO_FILE
47
48namespace pal
49{
50 class LabelPosition;
51 class FeaturePart;
52
59 class CORE_EXPORT FeaturePart : public PointSet
60 {
61 public:
69
75 FeaturePart( QgsLabelFeature *lf, const GEOSGeometry *geom );
76
77 FeaturePart( const FeaturePart &other );
78
82 ~FeaturePart() override;
83
88
92 Layer *layer();
93
97 QgsFeatureId featureId() const;
98
103 int subPartId() const;
104
108 std::size_t maximumPointCandidates() const;
109
113 std::size_t maximumLineCandidates() const;
114
118 std::size_t maximumPolygonCandidates() const;
119
123 std::vector<std::unique_ptr<LabelPosition> > createCandidates( Pal *pal );
124
133 std::size_t createCandidatesAroundPoint( double x, double y, std::vector<std::unique_ptr<LabelPosition> > &lPos, double angle );
134
143 std::size_t createCandidatesOverPoint( double x, double y, std::vector<std::unique_ptr<LabelPosition> > &lPos, double angle );
144
153 std::size_t createCandidateCenteredOverPoint( double x, double y, std::vector<std::unique_ptr<LabelPosition> > &lPos, double angle );
154
161 std::unique_ptr< LabelPosition > createCandidatePointOnSurface( PointSet *mapShape );
162
171 std::size_t createCandidatesAtOrderedPositionsOverPoint( double x, double y, std::vector<std::unique_ptr<LabelPosition> > &lPos, double angle );
172
181 std::size_t createCandidatesAlongLine( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, bool allowOverrun, Pal *pal );
182
190 std::size_t createHorizontalCandidatesAlongLine( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, Pal *pal );
191
200 std::size_t createCandidatesAlongLineNearStraightSegments( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, Pal *pal );
201
212 std::size_t createCandidatesAlongLineNearMidpoint( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, double initialCost = 0.0, Pal *pal = nullptr );
213
227 std::unique_ptr< LabelPosition > curvedPlacementAtOffset(
228 PointSet *mapShape,
229 const std::vector<double> &pathDistances,
231 double distance,
232 bool &labeledLineSegmentIsRightToLeft,
233 bool applyAngleConstraints,
235 double additionalCharacterSpacing,
236 double additionalWordSpacing
237 );
238
247 std::size_t createCurvedCandidatesAlongLine( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, bool allowOverrun, Pal *pal );
248
257 std::size_t createDefaultCurvedCandidatesAlongLine( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, bool allowOverrun, Pal *pal );
258
266 std::size_t createCurvedCandidateWithCharactersAtVertices( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, Pal *pal );
267
275 std::size_t createCandidatesForPolygon( std::vector<std::unique_ptr<LabelPosition> > &lPos, PointSet *mapShape, Pal *pal );
276
283 std::size_t createCandidatesOutsidePolygon( std::vector<std::unique_ptr<LabelPosition> > &lPos, Pal *pal );
284
291 bool hasSameLabelFeatureAs( FeaturePart *part ) const;
292
296 double getLabelWidth( double angle = 0.0 ) const { return mLF->size( angle ).width(); }
297
301 double getLabelHeight( double angle = 0.0 ) const { return mLF->size( angle ).height(); }
302
307 double getLabelDistance() const { return mLF->distLabel(); }
308
310 bool hasFixedRotation() const { return mLF->hasFixedAngle(); }
311
313 double fixedAngle() const { return mLF->fixedAngle(); }
314
316 bool hasFixedPosition() const { return mLF->hasFixedPosition(); }
317
322 bool alwaysShow() const { return mLF->alwaysShow(); }
323
327 const QgsLabelObstacleSettings &obstacleSettings() const { return mLF->obstacleSettings(); }
328
330 double repeatDistance() const { return mLF->repeatDistance(); }
331
333 int getNumSelfObstacles() const { return mHoles.count(); }
335 FeaturePart *getSelfObstacle( int i ) { return mHoles.at( i ); }
336
338 bool isConnected( FeaturePart *p2 );
339
344 bool mergeWithFeaturePart( FeaturePart *other );
345
351 void addSizePenalty( std::vector<std::unique_ptr<LabelPosition> > &lPos, double bbx[4], double bby[4] ) const;
352
357 double calculatePriority() const;
358
360 bool onlyShowUprightLabels() const;
361
366 int totalRepeats() const;
367
372 void setTotalRepeats( int repeats );
373
374 protected:
376 QList<FeaturePart *> mHoles;
377
379 void extractCoords( const GEOSGeometry *geom );
380
381 private:
382 Qgis::LabelQuadrantPosition quadrantFromOffset() const;
383
384 int mTotalRepeats = 0;
385
386 mutable std::size_t mCachedMaxLineCandidates = 0;
387 mutable std::size_t mCachedMaxPolygonCandidates = 0;
388
389 FeaturePart &operator=( const FeaturePart & ) = delete;
390 };
391
392} // end namespace pal
393
394#endif
LabelQuadrantPosition
Label quadrant positions.
Definition qgis.h:1320
QFlags< CurvedTextFlag > CurvedTextFlags
Flags controlling behavior of curved text generation.
Definition qgis.h:3104
Describes a feature that should be used within the labeling engine.
Contains settings related to how the label engine treats features as obstacles.
LabelLineDirection
Controls behavior of curved text with respect to line directions.
Represents a part of a label feature.
Definition feature.h:60
FeaturePart(QgsLabelFeature *lf, const GEOSGeometry *geom)
Creates a new generic feature.
Definition feature.cpp:55
bool hasFixedRotation() const
Returns true if the feature's label has a fixed rotation.
Definition feature.h:310
double getLabelHeight(double angle=0.0) const
Returns the height of the label, optionally taking an angle (in radians) into account.
Definition feature.h:301
QList< FeaturePart * > mHoles
Definition feature.h:376
double getLabelDistance() const
Returns the distance from the anchor point to the label.
Definition feature.h:307
bool hasFixedPosition() const
Returns true if the feature's label has a fixed position.
Definition feature.h:316
double fixedAngle() const
Returns the fixed angle for the feature's label.
Definition feature.h:313
double repeatDistance() const
Returns the distance between repeating labels for this feature.
Definition feature.h:330
int getNumSelfObstacles() const
Gets number of holes (inner rings) - they are considered as obstacles.
Definition feature.h:333
QgsLabelFeature * mLF
Definition feature.h:375
double getLabelWidth(double angle=0.0) const
Returns the width of the label, optionally taking an angle (in radians) into account.
Definition feature.h:296
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the feature's obstacle settings.
Definition feature.h:327
bool alwaysShow() const
Returns true if the feature's label should always been shown, even when it collides with other labels...
Definition feature.h:322
QgsLabelFeature * feature()
Returns the parent feature.
Definition feature.h:87
PathOffset
Path offset variances used in curved placement.
Definition feature.h:64
FeaturePart * getSelfObstacle(int i)
Gets hole (inner ring) - considered as obstacle.
Definition feature.h:335
void extractCoords(const GEOSGeometry *geom)
read coordinates from a GEOS geom
Definition feature.cpp:93
A set of features which influence the labeling process.
Definition layer.h:63
Main Pal labeling class.
Definition pal.h:87
The underlying raw pal geometry class.
Definition pointset.h:76
qint64 QgsFeatureId
64 bit feature ids negative numbers are used for uncommitted/newly added features
struct GEOSGeom_t GEOSGeometry
Definition util.h:41