QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected 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]

Classes

struct  CountContext
 
struct  PruneCtx
 

Public Types

enum  Quadrant {
  QuadrantAboveLeft, QuadrantAbove, QuadrantAboveRight, QuadrantLeft,
  QuadrantOver, QuadrantRight, QuadrantBelowLeft, QuadrantBelow,
  QuadrantBelowRight
}
 Position of label candidate relative to feature. More...
 

Public Member Functions

 LabelPosition (int id, double x1, double y1, double w, double h, double alpha, double cost, FeaturePart *feature, bool isReversed=false, Quadrant quadrant=QuadrantOver)
 create a new LabelPosition More...
 
 LabelPosition (const LabelPosition &other)
 Copy constructor. More...
 
 ~LabelPosition () override
 
bool conflictsWithObstacle () const
 Returns whether the position is marked as conflicting with an obstacle feature. More...
 
double cost () const
 Returns the candidate label position's geographical cost. More...
 
bool crossesBoundary (PointSet *polygon) const
 Returns true if this label crosses the boundary of the specified polygon. More...
 
bool crossesLine (PointSet *line) const
 Returns true if this label crosses the specified line. More...
 
double getAlpha () const
 Returns the angle to rotate text (in rad). More...
 
void getBoundingBox (double amin[2], double amax[2]) const
 Returns bounding box - amin: xmin,ymin - amax: xmax,ymax. More...
 
double getDistanceToPoint (double xp, double yp) const
 Gets distance from this label to a point. If point lies inside, returns negative number. More...
 
FeaturePartgetFeaturePart ()
 Returns the feature corresponding to this labelposition. More...
 
double getHeight () const
 
int getId () const
 Returns the id. More...
 
LabelPositiongetNextPart () const
 
int getNumOverlaps () const
 
int getPartId () const
 
int getProblemFeatureId () const
 
Quadrant getQuadrant () const
 
bool getReversed () const
 
bool getUpsideDown () const
 
double getWidth () const
 
double getX (int i=0) const
 Returns the down-left x coordinate. More...
 
double getY (int i=0) const
 Returns the down-left y coordinate. More...
 
int incrementUpsideDownCharCount ()
 Increases the count of upside down characters for this label position. More...
 
void insertIntoIndex (RTree< LabelPosition *, double, 2, double > *index)
 
bool intersects (const GEOSPreparedGeometry *geometry)
 Returns true if the label position intersects a geometry. More...
 
bool intersectsWithPolygon (PointSet *polygon) const
 Returns true if any intersection between polygon and position exists. More...
 
bool isIn (double *bbox)
 Is the labelposition in the bounding-box ? (intersect or inside????) More...
 
bool isInConflict (LabelPosition *ls)
 Check whether or not this overlap with another labelPosition. More...
 
bool isInside (double *bbox)
 Is the labelposition inside the bounding-box ? More...
 
bool isIntersect (double *bbox)
 Is the labelposition intersect the bounding-box ? More...
 
void offsetPosition (double xOffset, double yOffset)
 Shift the label by specified offset. More...
 
int polygonIntersectionCost (PointSet *polygon) const
 Returns cost of position intersection with polygon (testing area of intersection and center). More...
 
void removeFromIndex (RTree< LabelPosition *, double, 2, double > *index)
 
void resetNumOverlaps ()
 
void setConflictsWithObstacle (bool conflicts)
 Sets whether the position is marked as conflicting with an obstacle feature. More...
 
void setCost (double newCost)
 Sets the candidate label position's geographical cost. More...
 
void setNextPart (LabelPosition *next)
 
void setPartId (int id)
 
void setProblemIds (int probFid, int lpId)
 Set problem feature ID and assigned label candidate ID. More...
 
int upsideDownCharCount () const
 Returns the number of upside down characters for this label position. More...
 
void validateCost ()
 Make sure the cost is less than 1. More...
 
bool within (const GEOSPreparedGeometry *geometry)
 Returns true if the label position is within a geometry. More...
 
- Public Member Functions inherited from pal::PointSet
 PointSet ()
 
 PointSet (int nbPoints, double *x, double *y)
 
virtual ~PointSet ()
 
bool boundingBoxIntersects (const PointSet *other) const
 Returns true if the bounding box of this pointset intersects the bounding box of another pointset. More...
 
std::unique_ptr< PointSetclone () const
 Returns a copy of the point set. More...
 
CHullBoxcompute_chull_bbox ()
 
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. More...
 
bool containsPoint (double x, double y) const
 Tests whether point set contains a specified point. More...
 
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. More...
 
PointSetextractShape (int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty)
 
const GEOSGeometry * geos () const
 Returns the point set's GEOS geometry. More...
 
void getBoundingBox (double min[2], double max[2]) const
 
void getCentroid (double &px, double &py, bool forceInside=false) const
 
int getGeosType () const
 
PointSetgetHoleOf ()
 Returns nullptr if this isn't a hole. Otherwise returns pointer to parent pointset. More...
 
int getNumPoints () const
 
void getPointByDistance (double *d, double *ad, double dl, double *px, double *py)
 Gets a point a set distance along a line geometry. More...
 
bool isClosed () const
 Returns true if pointset is closed. More...
 
double length () const
 Returns length of line geometry. More...
 
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). More...
 

Static Public Member Functions

static bool countFullOverlapCallback (LabelPosition *lp, void *ctx)
 
static bool countOverlapCallback (LabelPosition *lp, void *ctx)
 
static bool polygonObstacleCallback (pal::FeaturePart *obstacle, void *ctx)
 
static bool pruneCallback (LabelPosition *candidatePosition, void *ctx)
 Check whether the candidate in ctx overlap with obstacle feat. More...
 
static bool removeOverlapCallback (LabelPosition *lp, void *ctx)
 
- Static Public Member Functions inherited from pal::PointSet
static void splitPolygons (QLinkedList< PointSet *> &shapes_toProcess, QLinkedList< PointSet *> &shapes_final, double xrm, double yrm)
 Split a concave shape into several convex shapes. More...
 

Protected Member Functions

bool isInConflictMultiPart (LabelPosition *lp)
 
bool isInConflictSinglePart (LabelPosition *lp)
 
- Protected Member Functions inherited from pal::PointSet
 PointSet (double x, double y)
 
 PointSet (const PointSet &ps)
 
void createGeosGeom () const
 
void deleteCoords ()
 
void invalidateGeos ()
 
const GEOSPreparedGeometry * preparedGeom () const
 

Protected Attributes

double alpha
 
FeaturePartfeature = nullptr
 
double h
 
int id
 
int nbOverlap
 
LabelPositionnextPart = nullptr
 
int partId
 
int probFeat
 
LabelPosition::Quadrant quadrant
 
bool reversed
 
bool upsideDown
 
double w
 
- Protected Attributes inherited from pal::PointSet
int * cHull = nullptr
 
int cHullSize = 0
 
PointSetholeOf = nullptr
 
GEOSGeometry * mGeos = nullptr
 
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

- Public Attributes inherited from pal::PointSet
int nbPoints
 
std::vector< double > x
 
std::vector< double > y
 

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

◆ Quadrant

Position of label candidate relative to feature.

Enumerator
QuadrantAboveLeft 
QuadrantAbove 
QuadrantAboveRight 
QuadrantLeft 
QuadrantOver 
QuadrantRight 
QuadrantBelowLeft 
QuadrantBelow 
QuadrantBelowRight 

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,
bool  isReversed = false,
Quadrant  quadrant = QuadrantOver 
)

create a new LabelPosition

Parameters
idid of this labelposition
x1down-left x coordinate
y1down-left y coordinate
wlabel width
hlabel height
alpharotation in rad
costgeographic cost
featurelabelpos owners
isReversedlabel is reversed
quadrantrelative position of label to feature

Definition at line 43 of file labelposition.cpp.

◆ LabelPosition() [2/2]

LabelPosition::LabelPosition ( const LabelPosition other)

Copy constructor.

Definition at line 140 of file labelposition.cpp.

◆ ~LabelPosition()

pal::LabelPosition::~LabelPosition ( )
inlineoverride

Definition at line 100 of file labelposition.h.

Member Function Documentation

◆ 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 218 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 197 of file labelposition.h.

◆ countFullOverlapCallback()

bool LabelPosition::countFullOverlapCallback ( LabelPosition lp,
void *  ctx 
)
static

Definition at line 473 of file labelposition.cpp.

◆ countOverlapCallback()

bool LabelPosition::countOverlapCallback ( LabelPosition lp,
void *  ctx 
)
static

Definition at line 461 of file labelposition.cpp.

◆ crossesBoundary()

bool LabelPosition::crossesBoundary ( PointSet polygon) const

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

Definition at line 543 of file labelposition.cpp.

◆ crossesLine()

bool LabelPosition::crossesLine ( PointSet line) const

Returns true if this label crosses the specified line.

Definition at line 514 of file labelposition.cpp.

◆ getAlpha()

double LabelPosition::getAlpha ( ) const

Returns the angle to rotate text (in rad).

Definition at line 359 of file labelposition.cpp.

◆ getBoundingBox()

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

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

Definition at line 377 of file labelposition.cpp.

◆ getDistanceToPoint()

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

Gets distance from this label to a point. If point lies inside, returns negative number.

Definition at line 502 of file labelposition.cpp.

◆ getFeaturePart()

FeaturePart * LabelPosition::getFeaturePart ( )

Returns the feature corresponding to this labelposition.

Definition at line 372 of file labelposition.cpp.

◆ getHeight()

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

Definition at line 236 of file labelposition.h.

◆ getId()

int LabelPosition::getId ( ) const

Returns the id.

Definition at line 344 of file labelposition.cpp.

◆ getNextPart()

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

Definition at line 246 of file labelposition.h.

◆ getNumOverlaps()

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

Definition at line 178 of file labelposition.h.

◆ getPartId()

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

Definition at line 250 of file labelposition.h.

◆ getProblemFeatureId()

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

Definition at line 181 of file labelposition.h.

◆ getQuadrant()

Quadrant pal::LabelPosition::getQuadrant ( ) const
inline

Definition at line 245 of file labelposition.h.

◆ getReversed()

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

Definition at line 242 of file labelposition.h.

◆ getUpsideDown()

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

Definition at line 243 of file labelposition.h.

◆ getWidth()

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

Definition at line 235 of file labelposition.h.

◆ getX()

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

Returns the down-left x coordinate.

See also
getY()

Definition at line 349 of file labelposition.cpp.

◆ getY()

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

Returns the down-left y coordinate.

See also
getX()

Definition at line 354 of file labelposition.cpp.

◆ incrementUpsideDownCharCount()

int pal::LabelPosition::incrementUpsideDownCharCount ( )
inline

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

Definition at line 254 of file labelposition.h.

◆ insertIntoIndex()

void LabelPosition::insertIntoIndex ( RTree< LabelPosition *, double, 2, double > *  index)

Definition at line 433 of file labelposition.cpp.

◆ intersects()

bool LabelPosition::intersects ( const GEOSPreparedGeometry *  geometry)

Returns true if the label position intersects a geometry.

Definition at line 199 of file labelposition.cpp.

◆ intersectsWithPolygon()

bool LabelPosition::intersectsWithPolygon ( PointSet polygon) const

Returns true if any intersection between polygon and position exists.

Definition at line 581 of file labelposition.cpp.

◆ isIn()

bool LabelPosition::isIn ( double *  bbox)

Is the labelposition in the bounding-box ? (intersect or inside????)

Parameters
bboxthe bounding-box double[4] = {xmin, ymin, xmax, ymax}

Definition at line 165 of file labelposition.cpp.

◆ isInConflict()

bool LabelPosition::isInConflict ( LabelPosition ls)

Check whether or not this overlap with another labelPosition.

Parameters
lsother labelposition
Returns
true or false

Definition at line 264 of file labelposition.cpp.

◆ isInConflictMultiPart()

bool LabelPosition::isInConflictMultiPart ( LabelPosition lp)
protected

Definition at line 302 of file labelposition.cpp.

◆ isInConflictSinglePart()

bool LabelPosition::isInConflictSinglePart ( LabelPosition lp)
protected

Definition at line 275 of file labelposition.cpp.

◆ isInside()

bool LabelPosition::isInside ( double *  bbox)

Is the labelposition inside the bounding-box ?

Parameters
bboxthe bounding-box double[4] = {xmin, ymin, xmax, ymax}

Definition at line 249 of file labelposition.cpp.

◆ isIntersect()

bool LabelPosition::isIntersect ( double *  bbox)

Is the labelposition intersect the bounding-box ?

Parameters
bboxthe bounding-box double[4] = {xmin, ymin, xmax, ymax}

Definition at line 182 of file labelposition.cpp.

◆ offsetPosition()

void LabelPosition::offsetPosition ( double  xOffset,
double  yOffset 
)

Shift the label by specified offset.

Definition at line 330 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 573 of file labelposition.cpp.

◆ polygonObstacleCallback()

bool LabelPosition::polygonObstacleCallback ( pal::FeaturePart obstacle,
void *  ctx 
)
static

Definition at line 410 of file labelposition.cpp.

◆ pruneCallback()

bool LabelPosition::pruneCallback ( LabelPosition candidatePosition,
void *  ctx 
)
static

Check whether the candidate in ctx overlap with obstacle feat.

Definition at line 441 of file labelposition.cpp.

◆ removeFromIndex()

void LabelPosition::removeFromIndex ( RTree< LabelPosition *, double, 2, double > *  index)

Definition at line 425 of file labelposition.cpp.

◆ removeOverlapCallback()

bool LabelPosition::removeOverlapCallback ( LabelPosition lp,
void *  ctx 
)
static

Definition at line 489 of file labelposition.cpp.

◆ resetNumOverlaps()

void pal::LabelPosition::resetNumOverlaps ( )
inline

Definition at line 179 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 403 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 204 of file labelposition.h.

◆ setNextPart()

void pal::LabelPosition::setNextPart ( LabelPosition next)
inline

Definition at line 247 of file labelposition.h.

◆ setPartId()

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

Definition at line 251 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 186 of file labelposition.h.

◆ upsideDownCharCount()

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

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

Definition at line 257 of file labelposition.h.

◆ validateCost()

void LabelPosition::validateCost ( )

Make sure the cost is less than 1.

Definition at line 364 of file labelposition.cpp.

◆ within()

bool LabelPosition::within ( const GEOSPreparedGeometry *  geometry)

Returns true if the label position is within a geometry.

Definition at line 224 of file labelposition.cpp.

Friends And Related Function 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

Definition at line 304 of file labelposition.h.

◆ feature

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

Definition at line 297 of file labelposition.h.

◆ h

double pal::LabelPosition::h
protected

Definition at line 306 of file labelposition.h.

◆ id

int pal::LabelPosition::id
protected

Definition at line 295 of file labelposition.h.

◆ nbOverlap

int pal::LabelPosition::nbOverlap
protected

Definition at line 302 of file labelposition.h.

◆ nextPart

LabelPosition* pal::LabelPosition::nextPart = nullptr
protected

Definition at line 308 of file labelposition.h.

◆ partId

int pal::LabelPosition::partId
protected

Definition at line 309 of file labelposition.h.

◆ probFeat

int pal::LabelPosition::probFeat
protected

Definition at line 300 of file labelposition.h.

◆ quadrant

LabelPosition::Quadrant pal::LabelPosition::quadrant
protected

Definition at line 318 of file labelposition.h.

◆ reversed

bool pal::LabelPosition::reversed
protected

Definition at line 314 of file labelposition.h.

◆ upsideDown

bool pal::LabelPosition::upsideDown
protected

Definition at line 316 of file labelposition.h.

◆ w

double pal::LabelPosition::w
protected

Definition at line 305 of file labelposition.h.


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