QGIS API Documentation 3.41.0-Master (45a0abf3bec)
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
pal::LabelPosition Class Reference

LabelPosition is a candidate feature label position. More...

#include <labelposition.h>

Inheritance diagram for pal::LabelPosition:
Inheritance graph
[legend]

Public Types

enum class  LabelDirectionToLine { SameDirection , Reversed }
 Label directions in relation to line or polygon ring directions. More...
 

Public Member Functions

 LabelPosition (const LabelPosition &other)
 
 LabelPosition (int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, LabelDirectionToLine directionToLine=LabelDirectionToLine::SameDirection, Qgis::LabelQuadrantPosition quadrant=Qgis::LabelQuadrantPosition::Over)
 create a new LabelPosition
 
 ~LabelPosition () override
 
double angleDifferential ()
 Returns the angle differential of all LabelPosition parts.
 
QgsRectangle boundingBoxForCandidateConflicts (Pal *pal) const
 Returns the bounding box to use for candidate conflicts.
 
bool conflictsWithObstacle () const
 Returns whether the position is marked as conflicting with an obstacle feature.
 
double cost () const
 Returns the candidate label position's geographical cost.
 
bool crossesBoundary (PointSet *polygon) const
 Returns true if this label crosses the boundary of the specified polygon.
 
bool crossesLine (PointSet *line) const
 Returns true if this label crosses the specified line.
 
void decrementNumOverlaps ()
 Decreases the number of overlaps recorded against this position by 1.
 
double getAlpha () const
 Returns the angle to rotate text (in radians).
 
void getBoundingBox (double amin[2], double amax[2]) const
 Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.
 
double getDistanceToPoint (double xp, double yp, bool useOuterBounds) const
 Gets distance from this label to a point.
 
FeaturePartgetFeaturePart () const
 Returns the feature corresponding to this labelposition.
 
double getHeight () const
 
int getId () const
 Returns the id.
 
int getNumOverlaps () const
 
int getPartId () const
 
int getProblemFeatureId () const
 
bool getUpsideDown () const
 
double getWidth () const
 
double getX (int i=0) const
 Returns the down-left x coordinate.
 
double getY (int i=0) const
 Returns the down-left y coordinate.
 
unsigned int globalId () const
 Returns the global ID for the candidate, which is unique for a single run of the pal labelling engine.
 
bool hasHardObstacleConflict () const
 Returns whether the position is marked as having a hard conflict with an obstacle feature.
 
void incrementNumOverlaps ()
 Increases the number of overlaps recorded against this position by 1.
 
void insertIntoIndex (PalRtree< LabelPosition > &index)
 Inserts the label position into the specified index.
 
bool intersects (const GEOSPreparedGeometry *geometry)
 Returns true if the label position intersects a geometry.
 
bool intersectsWithPolygon (PointSet *polygon) const
 Returns true if any intersection between polygon and position exists.
 
bool isInConflict (const LabelPosition *ls) const
 Check whether or not this overlap with another labelPosition.
 
bool isReversedFromLineDirection () const
 Returns true if the label direction is the reversed from the line or polygon ring direction.
 
const GEOSGeometrymultiPartGeom () const
 Returns a GEOS representation of all label parts as a multipolygon.
 
LabelPositionnextPart () const
 Returns the next part of this label position (i.e.
 
QgsRectangle outerBoundingBox () const
 Returns bounding box.
 
bool outerBoundingBoxIntersects (const LabelPosition *other) const
 Returns true if the outer bounding box of this pointset intersects the outer bounding box of another label position.
 
int polygonIntersectionCost (PointSet *polygon) const
 Returns cost of position intersection with polygon (testing area of intersection and center).
 
const GEOSPreparedGeometry * preparedMultiPartGeom () const
 Returns a prepared GEOS representation of all label parts as a multipolygon.
 
const GEOSPreparedGeometry * preparedOuterBoundsGeom () const
 Returns the prepared outer boundary geometry.
 
Qgis::LabelQuadrantPosition quadrant () const
 Returns the quadrant associated with this label position.
 
void removeFromIndex (PalRtree< LabelPosition > &index)
 Removes the label position from the specified index.
 
void resetNumOverlaps ()
 
void setConflictsWithObstacle (bool conflicts)
 Sets whether the position is marked as conflicting with an obstacle feature.
 
void setCost (double newCost)
 Sets the candidate label position's geographical cost.
 
void setGlobalId (unsigned int id)
 Sets the global id for the candidate, which is unique for a single run of the pal labelling engine.
 
void setHasHardObstacleConflict (bool conflicts)
 Sets whether the position is marked as having a hard conflict with an obstacle feature.
 
void setNextPart (std::unique_ptr< LabelPosition > next)
 Sets the next part of this label position (i.e.
 
void setPartId (int id)
 
void setProblemIds (int probFid, int lpId)
 Set problem feature ID and assigned label candidate ID.
 
void setUpsideDownCharCount (int count)
 Sets the count of upside down characters for this label position.
 
int upsideDownCharCount () const
 Returns the number of upside down characters for this label position.
 
void validateCost ()
 Make sure the cost is less than 1.
 
bool within (const GEOSPreparedGeometry *geometry)
 Returns true if the label position is within a geometry.
 
- Public Member Functions inherited from pal::PointSet
 PointSet ()
 
 PointSet (int nbPoints, double *x, double *y)
 
virtual ~PointSet ()
 
double area () const
 Returns area of polygon geometry.
 
QgsRectangle boundingBox () const
 Returns the point set bounding box.
 
bool boundingBoxIntersects (const PointSet *other) const
 Returns true if the bounding box of this pointset intersects the bounding box of another pointset.
 
std::unique_ptr< PointSetclone () const
 Returns a copy of the point set.
 
OrientedConvexHullBoundingBox computeConvexHullOrientedBoundingBox (bool &ok) const
 Computes an oriented bounding box for the shape's convex hull.
 
bool containsLabelCandidate (double x, double y, double width, double height, double alpha=0) const
 Tests whether a possible label candidate will fit completely within the shape.
 
bool containsPoint (double x, double y) const
 Tests whether point set contains a specified point.
 
std::tuple< std::vector< double >, double > edgeDistances () const
 Returns a vector of edge distances as well as its total length.
 
void extendLineByDistance (double startDistance, double endDistance, double smoothDistance)
 Extends linestrings by the specified amount at the start and end of the line, by extending the existing lines following the same direction as the original line start or end.
 
std::unique_ptr< PointSetextractShape (int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty)
 Does... something completely inscrutable.
 
const GEOSGeometrygeos () const
 Returns the point set's GEOS geometry.
 
void getCentroid (double &px, double &py, bool forceInside=false) const
 
int getGeosType () const
 
PointSetgetHoleOf () const
 Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset.
 
int getNumPoints () const
 
void getPointByDistance (double *d, double *ad, double dl, double *px, double *py) const
 Gets a point a set distance along a line geometry.
 
geos::unique_ptr interpolatePoint (double distance) const
 Returns a GEOS geometry representing the point interpolated on the shape by distance.
 
bool isClosed () const
 Returns true if pointset is closed.
 
double length () const
 Returns length of line geometry.
 
double lineLocatePoint (const GEOSGeometry *point) const
 Returns the distance along the geometry closest to the specified GEOS point.
 
double minDistanceToPoint (double px, double py, double *rx=nullptr, double *ry=nullptr) const
 Returns the squared minimum distance between the point set geometry and the point (px,py) Optionally, the nearest point is stored in (rx,ry).
 
void offsetCurveByDistance (double distance)
 Offsets linestrings by the specified distance.
 
QString toWkt () const
 Returns a WKT representation of the point set.
 

Protected Attributes

double alpha
 Rotation in radians.
 
FeaturePartfeature = nullptr
 
double h
 
int id
 
int nbOverlap
 
int partId
 
int probFeat
 
bool upsideDown
 
double w
 
- Protected Attributes inherited from pal::PointSet
std::vector< int > convexHull
 
PointSetholeOf = nullptr
 
double mArea = -1
 
GEOSGeometrymGeos = nullptr
 
double mLength = -1
 
bool mOwnsGeom = false
 
PointSetparent = nullptr
 
int type
 
double xmax = std::numeric_limits<double>::lowest()
 
double xmin = std::numeric_limits<double>::max()
 
double ymax = std::numeric_limits<double>::lowest()
 
double ymin = std::numeric_limits<double>::max()
 

Friends

class CostCalculator
 
class PolygonCostCalculator
 

Additional Inherited Members

- Static Public Member Functions inherited from pal::PointSet
static QLinkedList< PointSet * > splitPolygons (PointSet *inputShape, double labelWidth, double labelHeight)
 Split a polygon using some random logic into some other polygons.
 
- Public Attributes inherited from pal::PointSet
int nbPoints
 
std::vector< double > x
 
std::vector< double > y
 
- Protected Member Functions inherited from pal::PointSet
 PointSet (const PointSet &ps)
 
 PointSet (double x, double y)
 
void createGeosGeom () const
 
void deleteCoords ()
 
void invalidateGeos () const
 
const GEOSPreparedGeometry * preparedGeom () const
 

Detailed Description

LabelPosition is a candidate feature label position.

Note
not available in Python bindings

Definition at line 55 of file labelposition.h.

Member Enumeration Documentation

◆ LabelDirectionToLine

Label directions in relation to line or polygon ring directions.

Enumerator
SameDirection 
Reversed 

Definition at line 65 of file labelposition.h.

Constructor & Destructor Documentation

◆ LabelPosition() [1/2]

LabelPosition::LabelPosition ( int  id,
double  x1,
double  y1,
double  w,
double  h,
double  alpha,
double  cost,
FeaturePart feature,
LabelDirectionToLine  directionToLine = LabelDirectionToLine::SameDirection,
Qgis::LabelQuadrantPosition  quadrant = Qgis::LabelQuadrantPosition::Over 
)

create a new LabelPosition

Parameters
idid of this labelposition
x1down-left x coordinate
y1down-left y coordinate
wlabel width
hlabel height
alpharotation in radians
costgeographic cost
featurelabelpos owners
directionToLinewhether the label direction is reversed from the line or polygon ring direction
quadrantrelative position of label to feature

Definition at line 44 of file labelposition.cpp.

◆ LabelPosition() [2/2]

LabelPosition::LabelPosition ( const LabelPosition other)

Definition at line 143 of file labelposition.cpp.

◆ ~LabelPosition()

LabelPosition::~LabelPosition ( )
override

Definition at line 169 of file labelposition.cpp.

Member Function Documentation

◆ angleDifferential()

double LabelPosition::angleDifferential ( )

Returns the angle differential of all LabelPosition parts.

Definition at line 836 of file labelposition.cpp.

◆ boundingBoxForCandidateConflicts()

QgsRectangle LabelPosition::boundingBoxForCandidateConflicts ( Pal pal) const

Returns the bounding box to use for candidate conflicts.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 460 of file labelposition.cpp.

◆ conflictsWithObstacle()

bool pal::LabelPosition::conflictsWithObstacle ( ) const
inline

Returns whether the position is marked as conflicting with an obstacle feature.

See also
setConflictsWithObstacle

Definition at line 245 of file labelposition.h.

◆ cost()

double pal::LabelPosition::cost ( ) const
inline

Returns the candidate label position's geographical cost.

See also
setCost

Definition at line 224 of file labelposition.h.

◆ crossesBoundary()

bool LabelPosition::crossesBoundary ( PointSet polygon) const

Returns true if this label crosses the boundary of the specified polygon.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 703 of file labelposition.cpp.

◆ crossesLine()

bool LabelPosition::crossesLine ( PointSet line) const

Returns true if this label crosses the specified line.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 672 of file labelposition.cpp.

◆ decrementNumOverlaps()

void pal::LabelPosition::decrementNumOverlaps ( )
inline

Decreases the number of overlaps recorded against this position by 1.

Definition at line 205 of file labelposition.h.

◆ getAlpha()

double LabelPosition::getAlpha ( ) const

Returns the angle to rotate text (in radians).

Definition at line 393 of file labelposition.cpp.

◆ getBoundingBox()

void LabelPosition::getBoundingBox ( double  amin[2],
double  amax[2] 
) const

Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())
See also
boundingBox()

Definition at line 411 of file labelposition.cpp.

◆ getDistanceToPoint()

double LabelPosition::getDistanceToPoint ( double  xp,
double  yp,
bool  useOuterBounds 
) const

Gets distance from this label to a point.

If point lies inside, returns negative number.

If useOuterBounds is true then the distance will be calculated to the outer bounds of the label (see QgsLabelFeature::outerBounds()), otherwise it will be calculated to the label's actual rectangle.

Definition at line 571 of file labelposition.cpp.

◆ getFeaturePart()

FeaturePart * LabelPosition::getFeaturePart ( ) const

Returns the feature corresponding to this labelposition.

Definition at line 406 of file labelposition.cpp.

◆ getHeight()

double pal::LabelPosition::getHeight ( ) const
inline

Definition at line 279 of file labelposition.h.

◆ getId()

int LabelPosition::getId ( ) const

Returns the id.

Definition at line 378 of file labelposition.cpp.

◆ getNumOverlaps()

int pal::LabelPosition::getNumOverlaps ( ) const
inline

Definition at line 194 of file labelposition.h.

◆ getPartId()

int pal::LabelPosition::getPartId ( ) const
inline

Definition at line 313 of file labelposition.h.

◆ getProblemFeatureId()

int pal::LabelPosition::getProblemFeatureId ( ) const
inline

Definition at line 207 of file labelposition.h.

◆ getUpsideDown()

bool pal::LabelPosition::getUpsideDown ( ) const
inline

Definition at line 291 of file labelposition.h.

◆ getWidth()

double pal::LabelPosition::getWidth ( ) const
inline

Definition at line 278 of file labelposition.h.

◆ getX()

double LabelPosition::getX ( int  i = 0) const

Returns the down-left x coordinate.

See also
getY()

Definition at line 383 of file labelposition.cpp.

◆ getY()

double LabelPosition::getY ( int  i = 0) const

Returns the down-left y coordinate.

See also
getX()

Definition at line 388 of file labelposition.cpp.

◆ globalId()

unsigned int pal::LabelPosition::globalId ( ) const
inline

Returns the global ID for the candidate, which is unique for a single run of the pal labelling engine.

A return value of 0 means that the ID has not been assigned.

See also
setGlobalId()

Definition at line 369 of file labelposition.h.

◆ hasHardObstacleConflict()

bool pal::LabelPosition::hasHardObstacleConflict ( ) const
inline

Returns whether the position is marked as having a hard conflict with an obstacle feature.

A hard conflict means that the placement should (usually) not be considered, because the candidate conflicts with a obstacle of sufficient weight.

See also
setHasHardObstacleConflict()

Definition at line 261 of file labelposition.h.

◆ incrementNumOverlaps()

void pal::LabelPosition::incrementNumOverlaps ( )
inline

Increases the number of overlaps recorded against this position by 1.

Definition at line 200 of file labelposition.h.

◆ insertIntoIndex()

void LabelPosition::insertIntoIndex ( PalRtree< LabelPosition > &  index)

Inserts the label position into the specified index.

Definition at line 516 of file labelposition.cpp.

◆ intersects()

bool LabelPosition::intersects ( const GEOSPreparedGeometry *  geometry)

Returns true if the label position intersects a geometry.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 178 of file labelposition.cpp.

◆ intersectsWithPolygon()

bool LabelPosition::intersectsWithPolygon ( PointSet polygon) const

Returns true if any intersection between polygon and position exists.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 743 of file labelposition.cpp.

◆ isInConflict()

bool LabelPosition::isInConflict ( const LabelPosition ls) const

Check whether or not this overlap with another labelPosition.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())
Parameters
lsother labelposition
Returns
true or false

Definition at line 232 of file labelposition.cpp.

◆ isReversedFromLineDirection()

bool pal::LabelPosition::isReversedFromLineDirection ( ) const
inline

Returns true if the label direction is the reversed from the line or polygon ring direction.

Definition at line 289 of file labelposition.h.

◆ multiPartGeom()

const GEOSGeometry * LabelPosition::multiPartGeom ( ) const

Returns a GEOS representation of all label parts as a multipolygon.

Since
QGIS 3.40

Definition at line 521 of file labelposition.cpp.

◆ nextPart()

LabelPosition * pal::LabelPosition::nextPart ( ) const
inline

Returns the next part of this label position (i.e.

the next character for a curved label).

See also
setNextPart()

Definition at line 303 of file labelposition.h.

◆ outerBoundingBox()

QgsRectangle LabelPosition::outerBoundingBox ( ) const

Returns bounding box.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 452 of file labelposition.cpp.

◆ outerBoundingBoxIntersects()

bool LabelPosition::outerBoundingBoxIntersects ( const LabelPosition other) const

Returns true if the outer bounding box of this pointset intersects the outer bounding box of another label position.

Definition at line 473 of file labelposition.cpp.

◆ polygonIntersectionCost()

int LabelPosition::polygonIntersectionCost ( PointSet polygon) const

Returns cost of position intersection with polygon (testing area of intersection and center).

Cost ranges between 0 and 12, with extra cost if center of label position is covered.

Definition at line 735 of file labelposition.cpp.

◆ preparedMultiPartGeom()

const GEOSPreparedGeometry * LabelPosition::preparedMultiPartGeom ( ) const

Returns a prepared GEOS representation of all label parts as a multipolygon.

Since
QGIS 3.20

Definition at line 554 of file labelposition.cpp.

◆ preparedOuterBoundsGeom()

const GEOSPreparedGeometry * LabelPosition::preparedOuterBoundsGeom ( ) const

Returns the prepared outer boundary geometry.

Since
QGIS 3.30

Definition at line 566 of file labelposition.cpp.

◆ quadrant()

Qgis::LabelQuadrantPosition pal::LabelPosition::quadrant ( ) const
inline

Returns the quadrant associated with this label position.

Definition at line 296 of file labelposition.h.

◆ removeFromIndex()

void LabelPosition::removeFromIndex ( PalRtree< LabelPosition > &  index)

Removes the label position from the specified index.

Definition at line 511 of file labelposition.cpp.

◆ resetNumOverlaps()

void pal::LabelPosition::resetNumOverlaps ( )
inline

Definition at line 195 of file labelposition.h.

◆ setConflictsWithObstacle()

void LabelPosition::setConflictsWithObstacle ( bool  conflicts)

Sets whether the position is marked as conflicting with an obstacle feature.

Parameters
conflictsset to true to mark candidate as being in conflict
Note
This method applies to all label parts for the candidate position.
See also
conflictsWithObstacle

Definition at line 497 of file labelposition.cpp.

◆ setCost()

void pal::LabelPosition::setCost ( double  newCost)
inline

Sets the candidate label position's geographical cost.

Parameters
newCostnew cost for position
See also
cost

Definition at line 231 of file labelposition.h.

◆ setGlobalId()

void pal::LabelPosition::setGlobalId ( unsigned int  id)
inline

Sets the global id for the candidate, which is unique for a single run of the pal labelling engine.

See also
globalId()

Definition at line 377 of file labelposition.h.

◆ setHasHardObstacleConflict()

void LabelPosition::setHasHardObstacleConflict ( bool  conflicts)

Sets whether the position is marked as having a hard conflict with an obstacle feature.

A hard conflict means that the placement should (usually) not be considered, because the candidate conflicts with a obstacle of sufficient weight.

See also
hasHardObstacleConflict()

Definition at line 504 of file labelposition.cpp.

◆ setNextPart()

void pal::LabelPosition::setNextPart ( std::unique_ptr< LabelPosition next)
inline

Sets the next part of this label position (i.e.

the next character for a curved label).

See also
nextPart()

Definition at line 310 of file labelposition.h.

◆ setPartId()

void pal::LabelPosition::setPartId ( int  id)
inline

Definition at line 314 of file labelposition.h.

◆ setProblemIds()

void pal::LabelPosition::setProblemIds ( int  probFid,
int  lpId 
)
inline

Set problem feature ID and assigned label candidate ID.

called from pal.cpp during extraction.

Definition at line 213 of file labelposition.h.

◆ setUpsideDownCharCount()

void pal::LabelPosition::setUpsideDownCharCount ( int  count)
inline

Sets the count of upside down characters for this label position.

See also
upsideDownCharCount()

Definition at line 321 of file labelposition.h.

◆ upsideDownCharCount()

int pal::LabelPosition::upsideDownCharCount ( ) const
inline

Returns the number of upside down characters for this label position.

See also
setUpsideDownCharCount()

Definition at line 328 of file labelposition.h.

◆ validateCost()

void LabelPosition::validateCost ( )

Make sure the cost is less than 1.

Definition at line 398 of file labelposition.cpp.

◆ within()

bool LabelPosition::within ( const GEOSPreparedGeometry *  geometry)

Returns true if the label position is within a geometry.

Note
This method considers the label's outer bounds (see QgsLabelFeature::outerBounds())

Definition at line 205 of file labelposition.cpp.

Friends And Related Symbol Documentation

◆ CostCalculator

friend class CostCalculator
friend

Definition at line 57 of file labelposition.h.

◆ PolygonCostCalculator

friend class PolygonCostCalculator
friend

Definition at line 58 of file labelposition.h.

Member Data Documentation

◆ alpha

double pal::LabelPosition::alpha
protected

Rotation in radians.

Definition at line 396 of file labelposition.h.

◆ feature

FeaturePart* pal::LabelPosition::feature = nullptr
protected

Definition at line 388 of file labelposition.h.

◆ h

double pal::LabelPosition::h
protected

Definition at line 399 of file labelposition.h.

◆ id

int pal::LabelPosition::id
protected

Definition at line 386 of file labelposition.h.

◆ nbOverlap

int pal::LabelPosition::nbOverlap
protected

Definition at line 393 of file labelposition.h.

◆ partId

int pal::LabelPosition::partId
protected

Definition at line 401 of file labelposition.h.

◆ probFeat

int pal::LabelPosition::probFeat
protected

Definition at line 391 of file labelposition.h.

◆ upsideDown

bool pal::LabelPosition::upsideDown
protected

Definition at line 404 of file labelposition.h.

◆ w

double pal::LabelPosition::w
protected

Definition at line 398 of file labelposition.h.


The documentation for this class was generated from the following files: