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 )
97 QMutexLocker locker( &
mMutex );
111 bool addedFeature =
false;
113 double geom_size = -1, biggest_size = -1;
114 std::unique_ptr<FeaturePart> biggest_part;
117 std::unique_ptr<QLinkedList<const GEOSGeometry *>> simpleGeometries(
Util::unmulti( lf->
geometry() ) );
118 if ( !simpleGeometries )
127 while ( !simpleGeometries->isEmpty() )
129 const GEOSGeometry *geom = simpleGeometries->takeFirst();
132 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
137 int type = GEOSGeomTypeId_r( geosctxt, geom );
139 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
144 std::unique_ptr<FeaturePart> fpart = qgis::make_unique<FeaturePart>( lf, geom );
147 if ( ( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
148 ( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
160 bool labelWellDefined = ( lf->size().width() > 0.0000001 && lf->size().height() > 0.0000001 );
162 if ( lf->isObstacle() && featureGeomIsObstacleGeom )
185 if ( type == GEOS_LINESTRING )
186 GEOSLength_r( geosctxt, geom, &geom_size );
187 else if ( type == GEOS_POLYGON )
188 GEOSArea_r( geosctxt, geom, &geom_size );
190 if ( geom_size > biggest_size )
192 biggest_size = geom_size;
193 biggest_part.reset( fpart.release() );
203 if ( !featureGeomIsObstacleGeom )
207 if ( !simpleGeometries )
212 while ( !simpleGeometries->isEmpty() )
214 const GEOSGeometry *geom = simpleGeometries->takeFirst();
217 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
222 int type = GEOSGeomTypeId_r( geosctxt, geom );
224 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
229 std::unique_ptr<FeaturePart> fpart = qgis::make_unique<FeaturePart>( lf, geom );
232 if ( ( type == GEOS_LINESTRING && fpart->nbPoints < 2 ) ||
233 ( type == GEOS_POLYGON && fpart->nbPoints < 3 ) )
300 static FeaturePart *_findConnectedPart(
FeaturePart *partCheck,
const QVector<FeaturePart *> &otherParts )
303 auto it = otherParts.constBegin();
304 while ( it != otherParts.constEnd() )
320 int connectedFeaturesId = 0;
323 QVector<FeaturePart *> parts = it.value();
324 connectedFeaturesId++;
330 return a->
length() > b->length();
334 while ( parts.count() > 1 )
339 FeaturePart *otherPart = _findConnectedPart( partCheck, parts );
343 double checkpartBMin[2], checkpartBMax[2];
346 double otherPartBMin[2], otherPartBMax[2];
353 mFeatureIndex->Remove( checkpartBMin, checkpartBMax, partCheck );
354 mFeatureIndex->Remove( otherPartBMin, otherPartBMax, otherPart );
358 mFeatureIndex->Insert( otherPartBMin, otherPartBMax, otherPart );
380 QLinkedList<FeaturePart *> newFeatureParts;
384 const GEOSGeometry *geom = fpart->
geos();
386 if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
390 double bmin[2], bmax[2];
394 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
398 GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
401 std::vector<Point> points( n );
402 for (
unsigned int i = 0; i < n; ++i )
404 GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
405 GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
409 std::vector<double> len( n, 0 );
410 for (
unsigned int i = 1; i < n; ++i )
412 double dx = points[i].x - points[i - 1].x;
413 double dy = points[i].y - points[i - 1].y;
414 len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
418 unsigned int cur = 0;
423 lambda += chopInterval;
424 for ( ; cur < n && lambda > len[cur]; ++cur )
426 part.push_back( points[cur] );
432 double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
434 p.
x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
435 p.
y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
437 GEOSCoordSequence *cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
438 for (
int i = 0; i < part.size(); ++i )
440 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
441 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
444 GEOSGeometry *newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
446 newFeatureParts.append( newfpart );
453 part.push_back( points[n - 1] );
454 GEOSCoordSequence *cooSeq = GEOSCoordSeq_create_r( geosctxt, part.size(), 2 );
455 for (
int i = 0; i < part.size(); ++i )
457 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
458 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
461 GEOSGeometry *newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
463 newFeatureParts.append( newfpart );
470 newFeatureParts.append( fpart );
QList< FeaturePart * > mObstacleParts
List of obstacle parts.
QHash< QgsFeatureId, int > mConnectedFeaturesIds
QString labelText() const
Text of the label.
QgsFeatureId featureId() const
Returns the unique ID of the feature.
QgsFeatureId id() const
Identifier of the label (unique within the parent label provider)
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.
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance *.
GEOSGeometry * geometry() const
Gets access to the associated geometry.
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.
static GEOSContextHandle_t getGEOSHandler()
double repeatDistance() const
Returns the distance between repeating labels for this feature.
QHash< QString, QVector< FeaturePart * > > mConnectedHashtable
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
double priority() const
Returns the layer's priority, between 0 and 1.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
void joinConnectedFeatures()
Join connected features with the same label text.
void getBoundingBox(double min[2], double max[2]) const
void addObstaclePart(FeaturePart *fpart)
Add newly created obstacle part into r tree and to the list.
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.
Main class to handle feature.
The QgsAbstractLabelProvider class is an interface class.
Thrown when a geometry type is not like expected.
QSizeF size() const
Size of the label (in map units)
bool registerFeature(QgsLabelFeature *label)
Register a feature in the layer.
Placement
Placement modes which determine how label candidates are generated for a feature. ...
bool hasFixedPosition() const
Whether the label should use a fixed position instead of being automatically placed.
The QgsLabelFeature class describes a feature that should be used within the labeling engine...
double length() const
Returns length of line geometry.
GEOSGeometry * obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
QLinkedList< FeaturePart * > mFeatureParts
List of feature parts.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
double getLabelWidth() 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...
const GEOSGeometry * geos() const
Returns the point set's GEOS geometry.
void addFeaturePart(FeaturePart *fpart, const QString &labelText=QString())
Add newly created feature part into r tree and to the list.
int connectedFeatureId(QgsFeatureId featureId) const
Returns the connected feature ID for a label feature ID, which is unique for all features which have ...