45 : mProvider( provider )
50 , mLabelLayer( toLabel )
51 , mDisplayAll( displayAll )
52 , mCentroidInside( false )
53 , mArrangement( arrangement )
54 , mMode( LabelPerFeature )
55 , mMergeLines( false )
56 , mUpsidedownLabels( Upright )
58 mFeatureIndex =
new RTree<FeaturePart *, double, 2, double>();
61 if ( defaultPriority < 0.0001 )
63 else if ( defaultPriority > 1.0 )
84 if ( priority >= 1.0 )
86 else if ( priority <= 0.0001 )
94 if ( lf->
size().width() < 0 || lf->
size().height() < 0 )
112 bool addedFeature =
false;
114 double geom_size = -1, biggest_size = -1;
119 if ( !simpleGeometries )
129 while ( !simpleGeometries->isEmpty() )
131 const GEOSGeometry *geom = simpleGeometries->takeFirst();
134 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
139 int type = GEOSGeomTypeId_r( geosctxt, geom );
141 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
150 if ( ( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
151 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
165 bool labelWellDefined = ( lf->
size().width() > 0.0000001 && lf->
size().height() > 0.0000001 );
167 if ( lf->
isObstacle() && featureGeomIsObstacleGeom )
192 if ( type == GEOS_LINESTRING )
193 GEOSLength_r( geosctxt, geom, &geom_size );
194 else if ( type == GEOS_POLYGON )
195 GEOSArea_r( geosctxt, geom, &geom_size );
197 if ( geom_size > biggest_size )
199 biggest_size = geom_size;
201 biggest_part = fpart;
214 delete simpleGeometries;
216 if ( lf->
isObstacle() && !featureGeomIsObstacleGeom )
220 if ( !simpleGeometries )
226 while ( !simpleGeometries->isEmpty() )
228 const GEOSGeometry *geom = simpleGeometries->takeFirst();
231 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
236 int type = GEOSGeomTypeId_r( geosctxt, geom );
238 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
247 if ( ( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
248 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
264 delete simpleGeometries;
318 static FeaturePart *_findConnectedPart(
FeaturePart *partCheck,
const QVector<FeaturePart *> &otherParts )
321 auto it = otherParts.constBegin();
322 while ( it != otherParts.constEnd() )
338 int connectedFeaturesId = 0;
341 const QString labelTExt = it.key();
342 QVector<FeaturePart *> parts = it.value();
343 connectedFeaturesId++;
349 return a->
length() > b->length();
353 while ( parts.count() > 1 )
358 FeaturePart *otherPart = _findConnectedPart( partCheck, parts );
362 double checkpartBMin[2], checkpartBMax[2];
365 double otherPartBMin[2], otherPartBMax[2];
372 mFeatureIndex->Remove( checkpartBMin, checkpartBMax, partCheck );
373 mFeatureIndex->Remove( otherPartBMin, otherPartBMax, otherPart );
377 mFeatureIndex->Insert( otherPartBMin, otherPartBMax, otherPart );
400 QLinkedList<FeaturePart *> newFeatureParts;
404 const GEOSGeometry *geom = fpart->
geos();
406 if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
410 double bmin[2], bmax[2];
414 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
418 GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
421 std::vector<Point> points( n );
422 for (
unsigned int i = 0; i < n; ++i )
424 GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
425 GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
429 std::vector<double> len( n, 0 );
430 for (
unsigned int i = 1; i < n; ++i )
432 double dx = points[i].x - points[i - 1].x;
433 double dy = points[i].y - points[i - 1].y;
434 len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
438 unsigned int cur = 0;
443 lambda += chopInterval;
444 for ( ; cur < n && lambda > len[cur]; ++cur )
446 part.push_back( points[cur] );
452 double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
454 p.
x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
455 p.
y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
457 GEOSCoordSequence *cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
458 for (
int i = 0; i < part.size(); ++i )
460 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
461 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
464 GEOSGeometry *newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
466 newFeatureParts.append( newfpart );
473 part.push_back( points[n - 1] );
474 GEOSCoordSequence *cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
475 for (
int i = 0; i < part.size(); ++i )
477 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
478 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
481 GEOSGeometry *newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
483 newFeatureParts.append( newfpart );
490 newFeatureParts.append( fpart );
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
QHash< QgsFeatureId, int > mConnectedFeaturesIds
QgsLabelFeature * feature()
Returns the parent feature.
QHash< QgsFeatureId, QgsLabelFeature * > mHashtable
Lookup table of label features (owned by the label feature provider that created them) ...
static QLinkedList< const GEOSGeometry * > * unmulti(const GEOSGeometry *the_geom)
void setPriority(double priority)
Sets the layer's priority.
const GEOSGeometry * geos() const
Returns the point set's GEOS geometry.
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance *.
double getLabelWidth() const
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.
static GEOSContextHandle_t getGEOSHandler()
GEOSGeometry * geometry() const
Gets access to the associated geometry.
QHash< QString, QVector< FeaturePart * > > mConnectedHashtable
QSizeF size() const
Size of the label (in map units)
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
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.
double length() const
Returns length of line geometry.
Main class to handle feature.
The QgsAbstractLabelProvider class is an interface class.
Thrown when a geometry type is not like expected.
void getBoundingBox(double min[2], double max[2]) const
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
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 ...
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
double repeatDistance() const
Returns the distance between repeating labels for this feature.
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.
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
QgsFeatureId featureId() const
Returns the unique ID of the feature.