QGIS API Documentation 3.36.0-Maidenhead (09951dc0acf)
|
LabelPosition is a candidate feature label position. More...
#include <labelposition.h>
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 (const LabelPosition &other) | |
Copy constructor. | |
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 | |
~LabelPosition () override | |
double | angleDifferential () |
Returns the angle differential of all LabelPosition parts. | |
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. | |
FeaturePart * | getFeaturePart () 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 |
Quadrant | getQuadrant () const |
bool | getReversed () 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. | |
LabelPosition * | nextPart () const |
Returns the next part of this label position (i.e. | |
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. | |
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< PointSet > | clone () const |
Returns a copy of the point set. | |
OrientedConvexHullBoundingBox | computeConvexHullOrientedBoundingBox (bool &ok) |
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< PointSet > | extractShape (int nbPtSh, int imin, int imax, int fps, int fpe, double fptx, double fpty) |
Does... something completely inscrutable. | |
const GEOSGeometry * | geos () const |
Returns the point set's GEOS geometry. | |
void | getCentroid (double &px, double &py, bool forceInside=false) const |
int | getGeosType () const |
PointSet * | getHoleOf () 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. | |
FeaturePart * | feature = nullptr |
double | h |
int | id |
int | nbOverlap |
int | partId |
int | probFeat |
LabelPosition::Quadrant | quadrant |
bool | reversed |
bool | upsideDown |
double | w |
Protected Attributes inherited from pal::PointSet | |
std::vector< int > | convexHull |
PointSet * | holeOf = nullptr |
double | mArea = -1 |
GEOSGeometry * | mGeos = nullptr |
double | mLength = -1 |
bool | mOwnsGeom = false |
PointSet * | parent = 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 |
LabelPosition is a candidate feature label position.
Definition at line 55 of file labelposition.h.
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.
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
id | id of this labelposition |
x1 | down-left x coordinate |
y1 | down-left y coordinate |
w | label width |
h | label height |
alpha | rotation in radians |
cost | geographic cost |
feature | labelpos owners |
isReversed | label is reversed |
quadrant | relative position of label to feature |
Definition at line 43 of file labelposition.cpp.
LabelPosition::LabelPosition | ( | const LabelPosition & | other | ) |
Copy constructor.
Definition at line 142 of file labelposition.cpp.
|
override |
Definition at line 168 of file labelposition.cpp.
double LabelPosition::angleDifferential | ( | ) |
Returns the angle differential of all LabelPosition parts.
Definition at line 813 of file labelposition.cpp.
|
inline |
Returns whether the position is marked as conflicting with an obstacle feature.
Definition at line 236 of file labelposition.h.
|
inline |
Returns the candidate label position's geographical cost.
Definition at line 215 of file labelposition.h.
bool LabelPosition::crossesBoundary | ( | PointSet * | polygon | ) | const |
Returns true
if this label crosses the boundary of the specified polygon.
Definition at line 680 of file labelposition.cpp.
bool LabelPosition::crossesLine | ( | PointSet * | line | ) | const |
Returns true
if this label crosses the specified line.
Definition at line 649 of file labelposition.cpp.
|
inline |
Decreases the number of overlaps recorded against this position by 1.
Definition at line 196 of file labelposition.h.
double LabelPosition::getAlpha | ( | ) | const |
Returns the angle to rotate text (in radians).
Definition at line 392 of file labelposition.cpp.
void LabelPosition::getBoundingBox | ( | double | amin[2], |
double | amax[2] | ||
) | const |
Returns bounding box - amin: xmin,ymin - amax: xmax,ymax.
Definition at line 410 of file labelposition.cpp.
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 548 of file labelposition.cpp.
FeaturePart * LabelPosition::getFeaturePart | ( | ) | const |
Returns the feature corresponding to this labelposition.
Definition at line 405 of file labelposition.cpp.
|
inline |
Definition at line 270 of file labelposition.h.
int LabelPosition::getId | ( | ) | const |
Returns the id.
Definition at line 377 of file labelposition.cpp.
|
inline |
Definition at line 185 of file labelposition.h.
|
inline |
Definition at line 297 of file labelposition.h.
|
inline |
Definition at line 198 of file labelposition.h.
|
inline |
Definition at line 280 of file labelposition.h.
|
inline |
Definition at line 277 of file labelposition.h.
|
inline |
Definition at line 278 of file labelposition.h.
|
inline |
Definition at line 269 of file labelposition.h.
double LabelPosition::getX | ( | int | i = 0 | ) | const |
Returns the down-left x coordinate.
Definition at line 382 of file labelposition.cpp.
double LabelPosition::getY | ( | int | i = 0 | ) | const |
Returns the down-left y coordinate.
Definition at line 387 of file labelposition.cpp.
|
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.
Definition at line 346 of file labelposition.h.
|
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.
Definition at line 252 of file labelposition.h.
|
inline |
Increases the number of overlaps recorded against this position by 1.
Definition at line 191 of file labelposition.h.
void LabelPosition::insertIntoIndex | ( | PalRtree< LabelPosition > & | index | ) |
Inserts the label position into the specified index.
Definition at line 497 of file labelposition.cpp.
bool LabelPosition::intersects | ( | const GEOSPreparedGeometry * | geometry | ) |
Returns true
if the label position intersects a geometry.
Definition at line 177 of file labelposition.cpp.
bool LabelPosition::intersectsWithPolygon | ( | PointSet * | polygon | ) | const |
Returns true
if any intersection between polygon and position exists.
Definition at line 720 of file labelposition.cpp.
bool LabelPosition::isInConflict | ( | const LabelPosition * | ls | ) | const |
Check whether or not this overlap with another labelPosition.
ls | other labelposition |
true
or false
Definition at line 231 of file labelposition.cpp.
|
inline |
Returns the next part of this label position (i.e.
the next character for a curved label).
Definition at line 287 of file labelposition.h.
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 451 of file labelposition.cpp.
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 712 of file labelposition.cpp.
const GEOSPreparedGeometry * LabelPosition::preparedMultiPartGeom | ( | ) | const |
Returns a prepared GEOS representation of all label parts as a multipolygon.
Definition at line 531 of file labelposition.cpp.
const GEOSPreparedGeometry * LabelPosition::preparedOuterBoundsGeom | ( | ) | const |
Returns the prepared outer boundary geometry.
Definition at line 543 of file labelposition.cpp.
void LabelPosition::removeFromIndex | ( | PalRtree< LabelPosition > & | index | ) |
Removes the label position from the specified index.
Definition at line 489 of file labelposition.cpp.
|
inline |
Definition at line 186 of file labelposition.h.
void LabelPosition::setConflictsWithObstacle | ( | bool | conflicts | ) |
Sets whether the position is marked as conflicting with an obstacle feature.
conflicts | set to true to mark candidate as being in conflict |
Definition at line 475 of file labelposition.cpp.
|
inline |
Sets the candidate label position's geographical cost.
newCost | new cost for position |
Definition at line 222 of file labelposition.h.
|
inline |
Sets the global id for the candidate, which is unique for a single run of the pal labelling engine.
Definition at line 354 of file labelposition.h.
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.
Definition at line 482 of file labelposition.cpp.
|
inline |
Sets the next part of this label position (i.e.
the next character for a curved label).
Definition at line 294 of file labelposition.h.
|
inline |
Definition at line 298 of file labelposition.h.
|
inline |
Set problem feature ID and assigned label candidate ID.
called from pal.cpp during extraction.
Definition at line 204 of file labelposition.h.
|
inline |
Sets the count of upside down characters for this label position.
Definition at line 305 of file labelposition.h.
|
inline |
Returns the number of upside down characters for this label position.
Definition at line 312 of file labelposition.h.
void LabelPosition::validateCost | ( | ) |
Make sure the cost is less than 1.
Definition at line 397 of file labelposition.cpp.
bool LabelPosition::within | ( | const GEOSPreparedGeometry * | geometry | ) |
Returns true
if the label position is within a geometry.
Definition at line 204 of file labelposition.cpp.
|
friend |
Definition at line 57 of file labelposition.h.
|
friend |
Definition at line 58 of file labelposition.h.
|
protected |
Rotation in radians.
Definition at line 373 of file labelposition.h.
|
protected |
Definition at line 365 of file labelposition.h.
|
protected |
Definition at line 376 of file labelposition.h.
|
protected |
Definition at line 363 of file labelposition.h.
|
protected |
Definition at line 370 of file labelposition.h.
|
protected |
Definition at line 378 of file labelposition.h.
|
protected |
Definition at line 368 of file labelposition.h.
|
protected |
Definition at line 387 of file labelposition.h.
|
protected |
Definition at line 383 of file labelposition.h.
|
protected |
Definition at line 385 of file labelposition.h.
|
protected |
Definition at line 375 of file labelposition.h.