QGIS API Documentation  2.12.0-Lyon
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 #include "qgsgeometry.h"
34 #include "pointset.h"
35 #include "util.h"
36 #include "labelposition.h"
37 #include <iostream>
38 #include <fstream>
39 #include <cmath>
40 #include <QString>
41 
42 #include "qgslabelingenginev2.h"
43 
44 namespace pal
45 {
47  class CORE_EXPORT LabelInfo
48  {
49  public:
50  typedef struct
51  {
52  double width;
53  } CharacterInfo;
54 
55  LabelInfo( int num, double height, double maxinangle = 20.0, double maxoutangle = -20.0 )
56  {
57  max_char_angle_inside = maxinangle;
58  // outside angle should be negative
59  max_char_angle_outside = maxoutangle > 0 ? -maxoutangle : maxoutangle;
60  label_height = height;
61  char_num = num;
62  char_info = new CharacterInfo[num];
63  }
64  ~LabelInfo() { delete [] char_info; }
65 
68  double label_height;
69  int char_num;
71  };
72 
73  class LabelPosition;
74  class FeaturePart;
75 
79  class CORE_EXPORT FeaturePart : public PointSet
80  {
81 
82  public:
83 
88  FeaturePart( QgsLabelFeature* lf, const GEOSGeometry* geom );
89 
92  virtual ~FeaturePart();
93 
102  int setPositionForPoint( double x, double y, QList<LabelPosition *> &lPos, double angle, PointSet *mapShape = 0 );
103 
112  int setPositionOverPoint( double x, double y, QList<LabelPosition *> &lPos, double angle, PointSet *mapShape = 0 );
113 
119  int setPositionForLine( QList<LabelPosition *> &lPos, PointSet *mapShape );
120 
121  LabelPosition* curvedPlacementAtOffset( PointSet* path_positions, double* path_distances,
122  int orientation, int index, double distance );
123 
129  int setPositionForLineCurved( QList<LabelPosition *> &lPos, PointSet* mapShape );
130 
136  int setPositionForPolygon( QList<LabelPosition *> &lPos, PointSet *mapShape );
137 
140  QgsLabelFeature* feature() { return mLF; }
141 
144  Layer* layer();
145 
155  int setPosition( QList<LabelPosition *> &lPos, double bbox_min[2], double bbox_max[2], PointSet *mapShape, RTree<LabelPosition*, double, 2, double>*candidates );
156 
159  QgsFeatureId featureId() const;
160 
161 
162 #if 0
163 
167  void print();
168 #endif
169 
170  double getLabelWidth() const { return mLF->size().width(); }
171  double getLabelHeight() const { return mLF->size().height(); }
172  double getLabelDistance() const { return mLF->distLabel(); }
173 
174  bool getFixedRotation() { return mLF->hasFixedAngle(); }
175  double getLabelAngle() { return mLF->fixedAngle(); }
176  bool getFixedPosition() { return mLF->hasFixedPosition(); }
177  bool getAlwaysShow() { return mLF->alwaysShow(); }
178  bool isObstacle() { return mLF->isObstacle(); }
179  double obstacleFactor() { return mLF->obstacleFactor(); }
180  double repeatDistance() { return mLF->repeatDistance(); }
181 
183  int getNumSelfObstacles() const { return mHoles.count(); }
185  FeaturePart* getSelfObstacle( int i ) { return mHoles.at( i ); }
186 
188  bool isConnected( FeaturePart* p2 );
189 
192  bool mergeWithFeaturePart( FeaturePart* other );
193 
194  void addSizePenalty( int nbp, QList<LabelPosition *> &lPos, double bbx[4], double bby[4] );
195 
201  double calculatePriority() const;
202 
203 
204  protected:
205 
208 
210  void extractCoords( const GEOSGeometry* geom );
211 
212  private:
213 
214  LabelPosition::Quadrant quadrantFromOffset() const;
215  };
216 
217 } // end namespace pal
218 
219 #endif
bool getAlwaysShow()
Definition: feature.h:177
static unsigned index
bool getFixedRotation()
Definition: feature.h:174
QList< FeaturePart * > mHoles
Definition: feature.h:207
double max_char_angle_outside
Definition: feature.h:67
QgsLabelFeature * feature()
Returns the parent feature.
Definition: feature.h:140
double getLabelHeight() const
Definition: feature.h:171
int getNumSelfObstacles() const
Get number of holes (inner rings) - they are considered as obstacles.
Definition: feature.h:183
A layer of spacial entites.
Definition: layer.h:57
double getLabelWidth() const
Definition: feature.h:170
LabelInfo(int num, double height, double maxinangle=20.0, double maxoutangle=-20.0)
Definition: feature.h:55
double repeatDistance()
Definition: feature.h:180
CharacterInfo * char_info
Definition: feature.h:70
double getLabelDistance() const
Definition: feature.h:172
bool getFixedPosition()
Definition: feature.h:176
Optional additional info about label (for curved labels)
Definition: feature.h:47
double label_height
Definition: feature.h:68
Main class to handle feature.
Definition: feature.h:79
double getLabelAngle()
Definition: feature.h:175
double ANALYSIS_EXPORT angle(Point3D *p1, Point3D *p2, Point3D *p3, Point3D *p4)
Calculates the angle between two segments (in 2 dimension, z-values are ignored)
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
double max_char_angle_inside
Definition: feature.h:66
double obstacleFactor()
Definition: feature.h:179
FeaturePart * getSelfObstacle(int i)
Get hole (inner ring) - considered as obstacle.
Definition: feature.h:185
LabelPosition is a candidate feature label position.
Definition: labelposition.h:48
QgsLabelFeature * mLF
Definition: feature.h:206
qint64 QgsFeatureId
Definition: qgsfeature.h:31
Quadrant
Position of label candidate relative to feature.
Definition: labelposition.h:58
bool isObstacle()
Definition: feature.h:178
int char_num
Definition: feature.h:69