44 : mProvider( provider )
49 , mLabelLayer( toLabel )
50 , mDisplayAll( displayAll )
51 , mCentroidInside( false )
52 , mArrangement( arrangement )
53 , mArrangementFlags( nullptr )
54 , mMode( LabelPerFeature )
55 , mMergeLines( false )
56 , mUpsidedownLabels( Upright )
61 if ( defaultPriority < 0.0001 )
63 else if ( defaultPriority > 1.0 )
87 if ( priority >= 1.0 )
89 else if ( priority <= 0.0001 )
115 bool addedFeature =
false;
117 double geom_size = -1, biggest_size = -1;
122 if ( !simpleGeometries )
132 while ( !simpleGeometries->
isEmpty() )
134 const GEOSGeometry* geom = simpleGeometries->
takeFirst();
137 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
142 int type = GEOSGeomTypeId_r( geosctxt, geom );
144 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
153 if (( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
154 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
168 bool labelWellDefined = ( lf->
size().
width() > 0.0000001 && lf->
size().
height() > 0.0000001 );
170 if ( lf->
isObstacle() && featureGeomIsObstacleGeom )
195 if ( type == GEOS_LINESTRING )
196 GEOSLength_r( geosctxt, geom, &geom_size );
197 else if ( type == GEOS_POLYGON )
198 GEOSArea_r( geosctxt, geom, &geom_size );
200 if ( geom_size > biggest_size )
202 biggest_size = geom_size;
204 biggest_part = fpart;
217 delete simpleGeometries;
219 if ( !featureGeomIsObstacleGeom )
223 if ( !simpleGeometries )
229 while ( !simpleGeometries->
isEmpty() )
231 const GEOSGeometry* geom = simpleGeometries->
takeFirst();
234 if ( GEOSisValid_r( geosctxt, geom ) != 1 )
239 int type = GEOSGeomTypeId_r( geosctxt, geom );
241 if ( type != GEOS_POINT && type != GEOS_LINESTRING && type != GEOS_POLYGON )
250 if (( type == GEOS_LINESTRING && fpart->
nbPoints < 2 ) ||
251 ( type == GEOS_POLYGON && fpart->
nbPoints < 3 ) )
267 delete simpleGeometries;
337 while ( p != otherParts->
constEnd() )
353 int connectedFeaturesId = 0;
359 connectedFeaturesId++;
373 double checkpartBMin[2], checkpartBMax[2];
376 double otherPartBMin[2], otherPartBMax[2];
383 mFeatureIndex->Remove( checkpartBMin, checkpartBMax, partCheck );
384 mFeatureIndex->Remove( otherPartBMin, otherPartBMax, otherPart );
388 mFeatureIndex->Insert( otherPartBMin, otherPartBMax, otherPart );
425 const GEOSGeometry* geom = fpart->
geos();
427 if ( chopInterval != 0. && GEOSGeomTypeId_r( geosctxt, geom ) == GEOS_LINESTRING )
431 double bmin[2], bmax[2];
435 const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq_r( geosctxt, geom );
439 GEOSCoordSeq_getSize_r( geosctxt, cs, &n );
442 std::vector<Point> points( n );
443 for (
unsigned int i = 0; i < n; ++i )
445 GEOSCoordSeq_getX_r( geosctxt, cs, i, &points[i].x );
446 GEOSCoordSeq_getY_r( geosctxt, cs, i, &points[i].y );
450 std::vector<double> len( n, 0 );
451 for (
unsigned int i = 1; i < n; ++i )
453 double dx = points[i].x - points[i - 1].x;
454 double dy = points[i].y - points[i - 1].y;
455 len[i] = len[i - 1] + std::sqrt( dx * dx + dy * dy );
459 unsigned int cur = 0;
464 lambda += chopInterval;
465 for ( ; cur < n && lambda > len[cur]; ++cur )
473 double c = ( lambda - len[cur - 1] ) / ( len[cur] - len[cur - 1] );
475 p.
x = points[cur - 1].x + c * ( points[cur].x - points[cur - 1].x );
476 p.
y = points[cur - 1].y + c * ( points[cur].y - points[cur - 1].y );
478 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.
size(), 2 );
479 for (
int i = 0; i < part.
size(); ++i )
481 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
482 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
485 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
487 newFeatureParts.
append( newfpart );
495 GEOSCoordSequence* cooSeq = GEOSCoordSeq_create_r( geosctxt, part.
size(), 2 );
496 for (
int i = 0; i < part.
size(); ++i )
498 GEOSCoordSeq_setX_r( geosctxt, cooSeq, i, part[i].x );
499 GEOSCoordSeq_setY_r( geosctxt, cooSeq, i, part[i].y );
502 GEOSGeometry* newgeom = GEOSGeom_createLineString_r( geosctxt, cooSeq );
504 newFeatureParts.
append( newfpart );
511 newFeatureParts.
append( fpart );
QHash< QgsFeatureId, int > mConnectedFeaturesIds
QString labelText() const
Text of the label.
iterator insert(const Key &key, const T &value)
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.
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.
Main Pal labelling class.
void chopFeaturesAtRepeatDistance()
Chop layer features at the repeat distance.
GEOSGeometry * geometry() const
Get 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 isObstacle() const
Returns whether the feature will act as an obstacle for labels.
bool isConnected(FeaturePart *p2)
Check whether this part is connected with some other part.
int count(const T &value) const
double priority() const
Returns the layer's priority, between 0 and 1.
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.
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.
static FeaturePart * _findConnectedPart(FeaturePart *partCheck, QLinkedList< FeaturePart *> *otherParts)
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)
const T value(const Key &key) const
RTree< FeaturePart *, double, 2, double, 8, 4 > * mObstacleIndex
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
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...
GEOSGeometry * obstacleGeometry() const
Returns the label's obstacle geometry, if different to the feature geometry.
RTree< FeaturePart *, double, 2, double, 8, 4 > * mFeatureIndex
double getLabelWidth() const
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...
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.
void append(const T &value)
int connectedFeatureId(QgsFeatureId featureId) const
Returns the connected feature ID for a label feature ID, which is unique for all features which have ...