44 : mProvider( provider )
49 , mLabelLayer( toLabel )
50 , mDisplayAll( displayAll )
51 , mCentroidInside( false )
52 , mFitInPolygon( false )
53 , mArrangement( arrangement )
54 , mArrangementFlags( nullptr )
55 , mMode( LabelPerFeature )
56 , mMergeLines( false )
57 , mUpsidedownLabels( Upright )
62 if ( defaultPriority < 0.0001 )
64 else if ( defaultPriority > 1.0 )
88 if ( priority >= 1.0 )
90 else if ( priority <= 0.0001 )
116 bool addedFeature =
false;
118 double geom_size = -1, biggest_size = -1;
123 if ( !simpleGeometries )
133 while ( !simpleGeometries->
isEmpty() )
135 const GEOSGeometry* geom = simpleGeometries->
takeFirst();
138 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
143 int type = GEOSGeomTypeId_r( geosctxt, geom );
145 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
154 if (( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
155 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
169 bool labelWellDefined = ( lf->
size().
width() > 0.0000001 && lf->
size().
height() > 0.0000001 );
171 if ( lf->
isObstacle() && featureGeomIsObstacleGeom )
196 if ( type == GEOS_LINESTRING )
197 GEOSLength_r( geosctxt, geom, &geom_size );
198 else if ( type == GEOS_POLYGON )
199 GEOSArea_r( geosctxt, geom, &geom_size );
201 if ( geom_size > biggest_size )
203 biggest_size = geom_size;
205 biggest_part = fpart;
218 delete simpleGeometries;
220 if ( !featureGeomIsObstacleGeom )
224 if ( !simpleGeometries )
230 while ( !simpleGeometries->
isEmpty() )
232 const GEOSGeometry* geom = simpleGeometries->
takeFirst();
235 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
240 int type = GEOSGeomTypeId_r( geosctxt, geom );
242 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
251 if (( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
252 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
268 delete simpleGeometries;
338 while ( p != otherParts->
constEnd() )
354 int connectedFeaturesId = 0;
360 connectedFeaturesId++;
374 double bmin[2], bmax[2];
421 const GEOSGeometry* geom = fpart->
geos();
423 if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
426 double bmin[2], bmax[2];
430 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
434 GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
437 std::vector<Point> points( n );
438 for (
unsigned int i = 0; i < n; ++i )
440 GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
441 GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
445 std::vector<double> len( n, 0 );
446 for (
unsigned int i = 1; i < n; ++i )
448 double dx = points[i].x - points[i - 1].x;
449 double dy = points[i].y - points[i - 1].y;
450 len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
454 unsigned int cur = 0;
459 lambda += chopInterval;
460 for ( ; cur < n && lambda > len[cur]; ++cur )
468 double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
470 p.
x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
471 p.
y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
473 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.
size(), 2 );
474 for (
int i = 0; i < part.
size(); ++i )
476 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
477 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
480 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
482 newFeatureParts.
append( newfpart );
490 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.
size(), 2 );
491 for (
int i = 0; i < part.
size(); ++i )
493 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
494 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
497 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
499 newFeatureParts.
append( newfpart );
506 newFeatureParts.
append( fpart );
QHash< QgsFeatureId, int > mConnectedFeaturesIds
iterator insert(const Key &key, const T &value)
QgsLabelFeature * feature()
Returns the parent feature.
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
QStringList mConnectedTexts
static QLinkedList< const GEOSGeometry * > * unmulti(const GEOSGeometry *the_geom)
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
void setPriority(double priority)
Sets the layer's priority.
const GEOSGeometry * geos() const
Returns the point set's GEOS geometry.
Main Pal labelling class.
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance.
double priority() const
Returns the layer's priority, between 0 and 1.
bool mergeWithFeaturePart(FeaturePart *other)
Merge other (connected) part with this one and save the result in this part (other is unchanged)...
bool isConnected(FeaturePart *p2)
Check whether this part is connected with some other part.
bool isObstacle() const
Returns whether the feature will act as an obstacle for labels.
GEOSGeometry * geometry() const
Get access to the associated geometry.
QSizeF size() const
Size of the label (in map units)
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
void joinConnectedFeatures()
Join connected features with the same label text.
void addObstaclePart(FeaturePart *fpart)
Add newly created obstacle part into r tree and to the list.
GEOSGeometry * obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
void setLayer(pal::Layer *layer)
Assign PAL layer to the label feature. Should be only used internally in PAL.
Layer(QgsAbstractLabelProvider *provider, const QString &name, QgsPalLayerSettings::Placement arrangement, double defaultPriority, bool active, bool toLabel, Pal *pal, bool displayAll=false)
Create a new layer.
GEOSContextHandle_t geosContext()
Get GEOS context handle to be used in all GEOS library calls with reentrant API.
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
Main class to handle feature.
The QgsAbstractLabelProvider class is an interface class.
Thrown when a geometry type is not like expected.
const T value(const Key &key) const
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
void getBoundingBox(double min[2], double max[2]) const
const_iterator constBegin() const
const_iterator constEnd() const
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
QHash< QString, QLinkedList< FeaturePart * > * > mConnectedHashtable
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
int connectedFeatureId(QgsFeatureId featureId) const
Returns the connected feature ID for a label feature ID, which is unique for all features which have ...
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
static FeaturePart * _findConnectedPart(FeaturePart *partCheck, QLinkedList< FeaturePart * > *otherParts)
void push_back(const T &value)
bool contains(const Key &key) const
static int reorderPolygon(int nbPoints, double *x, double *y)
Reorder points to have cross prod ((x,y)[i], (x,y)[i+1), point) > 0 when point is outside...
QString labelText() const
Text of the label.
void addFeaturePart(FeaturePart *fpart, const QString &labelText=QString())
Add newly created feature part into r tree and to the list.
void append(const T &value)
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
QgsFeatureId featureId() const
Returns the unique ID of the feature.