QGIS API Documentation  3.9.0-Master (224899f119)
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
pal::FeaturePart Class Reference

Main class to handle feature. More...

#include <feature.h>

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

Public Member Functions

 FeaturePart (QgsLabelFeature *lf, const GEOSGeometry *geom)
 Creates a new generic feature. More...
 
 FeaturePart (const FeaturePart &other)
 
 ~FeaturePart () override
 Delete the feature. More...
 
void addSizePenalty (int nbp, QList< LabelPosition *> &lPos, double bbx[4], double bby[4])
 
bool alwaysShow () const
 Returns true if the feature's label should always been shown, even when it collides with other labels. More...
 
double calculatePriority () const
 Calculates the priority for the feature. More...
 
std::unique_ptr< LabelPositioncreateCandidatePointOnSurface (PointSet *mapShape)
 Creates a single candidate using the "point on sruface" algorithm. More...
 
QList< LabelPosition * > createCandidates (const GEOSPreparedGeometry *mapBoundary, PointSet *mapShape, RTree< LabelPosition *, double, 2, double > *candidates)
 Generic method to generate label candidates for the feature. More...
 
int createCandidatesAlongLine (QList< LabelPosition *> &lPos, PointSet *mapShape, bool allowOverrun=false)
 Generate candidates for line feature. More...
 
int createCandidatesAlongLineNearMidpoint (QList< LabelPosition *> &lPos, PointSet *mapShape, double initialCost=0.0)
 Generate candidates for line feature, by trying to place candidates as close as possible to the line's midpoint. More...
 
int createCandidatesAlongLineNearStraightSegments (QList< LabelPosition *> &lPos, PointSet *mapShape)
 Generate candidates for line feature, by trying to place candidates towards the middle of the longest straightish segments of the line. More...
 
int createCandidatesAroundPoint (double x, double y, QList< LabelPosition *> &lPos, double angle)
 Generate candidates for point feature, located around a specified point. More...
 
int createCandidatesAtOrderedPositionsOverPoint (double x, double y, QList< LabelPosition *> &lPos, double angle)
 Generates candidates following a prioritized list of predefined positions around a point. More...
 
int createCandidatesForPolygon (QList< LabelPosition *> &lPos, PointSet *mapShape)
 Generate candidates for polygon features. More...
 
int createCandidatesOverPoint (double x, double y, QList< LabelPosition *> &lPos, double angle)
 Generate one candidate over or offset the specified point. More...
 
int createCurvedCandidatesAlongLine (QList< LabelPosition *> &lPos, PointSet *mapShape, bool allowOverrun=false)
 Generate curved candidates for line features. More...
 
LabelPositioncurvedPlacementAtOffset (PointSet *path_positions, double *path_distances, int &orientation, double distance, bool &reversed, bool &flip)
 Returns the label position for a curved label at a specific offset along a path. More...
 
QgsLabelFeaturefeature ()
 Returns the parent feature. More...
 
QgsFeatureId featureId () const
 Returns the unique ID of the feature. More...
 
double fixedAngle () const
 Returns the fixed angle for the feature's label. More...
 
double getLabelDistance () const
 Returns the distance from the anchor point to the label. More...
 
double getLabelHeight (double angle=0.0) const
 Returns the height of the label, optionally taking an angle into account. More...
 
double getLabelWidth (double angle=0.0) const
 Returns the width of the label, optionally taking an angle into account. More...
 
int getNumSelfObstacles () const
 Gets number of holes (inner rings) - they are considered as obstacles. More...
 
FeaturePartgetSelfObstacle (int i)
 Gets hole (inner ring) - considered as obstacle. More...
 
bool hasFixedPosition () const
 Returns true if the feature's label has a fixed position. More...
 
bool hasFixedRotation () const
 Returns true if the feature's label has a fixed rotation. More...
 
bool hasSameLabelFeatureAs (FeaturePart *part) const
 Tests whether this feature part belongs to the same QgsLabelFeature as another feature part. More...
 
bool isConnected (FeaturePart *p2)
 Check whether this part is connected with some other part. More...
 
bool isObstacle () const
 Returns true if the feature should act as an obstacle to labels. More...
 
Layerlayer ()
 Returns the layer that feature belongs to. More...
 
bool mergeWithFeaturePart (FeaturePart *other)
 Merge other (connected) part with this one and save the result in this part (other is unchanged). More...
 
bool nextCharPosition (double charWidth, double segmentLength, PointSet *path_positions, int &index, double &currentDistanceAlongSegment, double &characterStartX, double &characterStartY, double &characterEndX, double &characterEndY) const
 Returns true if the next char position is found. The referenced parameters are updated. More...
 
double obstacleFactor () const
 Returns the feature's obstacle factor, which represents the penalty incurred for a label to overlap the feature. More...
 
double repeatDistance () const
 Returns the distance between repeating labels for this feature. More...
 
void setTotalRepeats (int repeats)
 Returns the total number of repeating labels associated with this label. More...
 
bool showUprightLabels () const
 Returns true if feature's label must be displayed upright. More...
 
int totalRepeats () const
 Returns the total number of repeating labels associated with this label. More...
 
- Public Member Functions inherited from pal::PointSet
 PointSet ()
 
 PointSet (int nbPoints, double *x, double *y)
 
virtual ~PointSet ()
 
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...
 

Protected Member Functions

void extractCoords (const GEOSGeometry *geom)
 read coordinates from a GEOS geom More...
 
- 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

QList< FeaturePart * > mHoles
 
QgsLabelFeaturemLF = nullptr
 
- 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()
 

Additional Inherited Members

- 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...
 
- Public Attributes inherited from pal::PointSet
int nbPoints
 
std::vector< double > x
 
std::vector< double > y
 

Detailed Description

Main class to handle feature.

Note
not available in Python bindings

Definition at line 96 of file feature.h.

Constructor & Destructor Documentation

◆ FeaturePart() [1/2]

FeaturePart::FeaturePart ( QgsLabelFeature lf,
const GEOSGeometry *  geom 
)

Creates a new generic feature.

Parameters
lfa pointer for a feature which contains the spatial entites
geoma pointer to a GEOS geometry

Definition at line 49 of file feature.cpp.

◆ FeaturePart() [2/2]

FeaturePart::FeaturePart ( const FeaturePart other)

Definition at line 66 of file feature.cpp.

◆ ~FeaturePart()

FeaturePart::~FeaturePart ( )
override

Delete the feature.

Definition at line 77 of file feature.cpp.

Member Function Documentation

◆ addSizePenalty()

void FeaturePart::addSizePenalty ( int  nbp,
QList< LabelPosition *> &  lPos,
double  bbx[4],
double  bby[4] 
)

Definition at line 1691 of file feature.cpp.

◆ alwaysShow()

bool pal::FeaturePart::alwaysShow ( ) const
inline

Returns true if the feature's label should always been shown, even when it collides with other labels.

Definition at line 284 of file feature.h.

◆ calculatePriority()

double FeaturePart::calculatePriority ( ) const

Calculates the priority for the feature.

This will be the feature's priority if set, otherwise the layer's default priority.

Definition at line 1804 of file feature.cpp.

◆ createCandidatePointOnSurface()

std::unique_ptr< LabelPosition > FeaturePart::createCandidatePointOnSurface ( PointSet mapShape)

Creates a single candidate using the "point on sruface" algorithm.

Note
Unlike the other create candidates methods, this method bypasses the usual candidate filtering steps and ALWAYS returns a single candidate.

Definition at line 313 of file feature.cpp.

◆ createCandidates()

QList< LabelPosition * > FeaturePart::createCandidates ( const GEOSPreparedGeometry *  mapBoundary,
PointSet mapShape,
RTree< LabelPosition *, double, 2, double > *  candidates 
)

Generic method to generate label candidates for the feature.

Parameters
mapBoundarymap boundary geometry
mapShapegenerate candidates for this spatial entity
candidatesindex for candidates
Returns
a list of generated candidates positions

Definition at line 1610 of file feature.cpp.

◆ createCandidatesAlongLine()

int FeaturePart::createCandidatesAlongLine ( QList< LabelPosition *> &  lPos,
PointSet mapShape,
bool  allowOverrun = false 
)

Generate candidates for line feature.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the line
allowOverrunset to true to allow labels to overrun features
Returns
the number of generated candidates

Definition at line 616 of file feature.cpp.

◆ createCandidatesAlongLineNearMidpoint()

int FeaturePart::createCandidatesAlongLineNearMidpoint ( QList< LabelPosition *> &  lPos,
PointSet mapShape,
double  initialCost = 0.0 
)

Generate candidates for line feature, by trying to place candidates as close as possible to the line's midpoint.

Candidates can "cut corners" if it helps them place near this mid point.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the line
initialCostinitial cost for candidates generated using this method. If set, cost can be increased by a preset amount.
Returns
the number of generated candidates

Definition at line 865 of file feature.cpp.

◆ createCandidatesAlongLineNearStraightSegments()

int FeaturePart::createCandidatesAlongLineNearStraightSegments ( QList< LabelPosition *> &  lPos,
PointSet mapShape 
)

Generate candidates for line feature, by trying to place candidates towards the middle of the longest straightish segments of the line.

Segments closer to horizontal are preferred over vertical segments.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the line
Returns
the number of generated candidates

Definition at line 641 of file feature.cpp.

◆ createCandidatesAroundPoint()

int FeaturePart::createCandidatesAroundPoint ( double  x,
double  y,
QList< LabelPosition *> &  lPos,
double  angle 
)

Generate candidates for point feature, located around a specified point.

Parameters
xx coordinate of the point
yy coordinate of the point
lPospointer to an array of candidates, will be filled by generated candidates
angleorientation of the label
Returns
the number of generated candidates

Definition at line 463 of file feature.cpp.

◆ createCandidatesAtOrderedPositionsOverPoint()

int FeaturePart::createCandidatesAtOrderedPositionsOverPoint ( double  x,
double  y,
QList< LabelPosition *> &  lPos,
double  angle 
)

Generates candidates following a prioritized list of predefined positions around a point.

Parameters
xx coordinate of the point
yy coordinate of the point
lPospointer to an array of candidates, will be filled by generated candidate
angleorientation of the label
Returns
the number of generated candidates

Definition at line 336 of file feature.cpp.

◆ createCandidatesForPolygon()

int FeaturePart::createCandidatesForPolygon ( QList< LabelPosition *> &  lPos,
PointSet mapShape 
)

Generate candidates for polygon features.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the polygon
Returns
the number of generated candidates

Definition at line 1404 of file feature.cpp.

◆ createCandidatesOverPoint()

int FeaturePart::createCandidatesOverPoint ( double  x,
double  y,
QList< LabelPosition *> &  lPos,
double  angle 
)

Generate one candidate over or offset the specified point.

Parameters
xx coordinate of the point
yy coordinate of the point
lPospointer to an array of candidates, will be filled by generated candidate
angleorientation of the label
Returns
the number of generated candidates (always 1)

Definition at line 234 of file feature.cpp.

◆ createCurvedCandidatesAlongLine()

int FeaturePart::createCurvedCandidatesAlongLine ( QList< LabelPosition *> &  lPos,
PointSet mapShape,
bool  allowOverrun = false 
)

Generate curved candidates for line features.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the line
allowOverrunset to true to allow labels to overrun features
Returns
the number of generated candidates

Definition at line 1204 of file feature.cpp.

◆ curvedPlacementAtOffset()

LabelPosition * FeaturePart::curvedPlacementAtOffset ( PointSet path_positions,
double *  path_distances,
int &  orientation,
double  distance,
bool &  reversed,
bool &  flip 
)

Returns the label position for a curved label at a specific offset along a path.

Parameters
path_positionsline path to place label on
path_distancesarray of distances to each segment on path
orientationcan be 0 for automatic calculation of orientation, or -1/+1 for a specific label orientation
distancedistance to offset label along curve by
reversedif true label is reversed from lefttoright to righttoleft
flipif true label is placed on the other side of the line
Returns
calculated label position

Definition at line 1028 of file feature.cpp.

◆ extractCoords()

void FeaturePart::extractCoords ( const GEOSGeometry *  geom)
protected

read coordinates from a GEOS geom

Definition at line 85 of file feature.cpp.

◆ feature()

QgsLabelFeature* pal::FeaturePart::feature ( )
inline

Returns the parent feature.

Definition at line 118 of file feature.h.

◆ featureId()

QgsFeatureId FeaturePart::featureId ( ) const

Returns the unique ID of the feature.

Definition at line 151 of file feature.cpp.

◆ fixedAngle()

double pal::FeaturePart::fixedAngle ( ) const
inline

Returns the fixed angle for the feature's label.

Definition at line 275 of file feature.h.

◆ getLabelDistance()

double pal::FeaturePart::getLabelDistance ( ) const
inline

Returns the distance from the anchor point to the label.

Returns
the distance to the label

Definition at line 269 of file feature.h.

◆ getLabelHeight()

double pal::FeaturePart::getLabelHeight ( double  angle = 0.0) const
inline

Returns the height of the label, optionally taking an angle into account.

Returns
the hieght of the label

Definition at line 263 of file feature.h.

◆ getLabelWidth()

double pal::FeaturePart::getLabelWidth ( double  angle = 0.0) const
inline

Returns the width of the label, optionally taking an angle into account.

Returns
the width of the label

Definition at line 257 of file feature.h.

◆ getNumSelfObstacles()

int pal::FeaturePart::getNumSelfObstacles ( ) const
inline

Gets number of holes (inner rings) - they are considered as obstacles.

Definition at line 299 of file feature.h.

◆ getSelfObstacle()

FeaturePart* pal::FeaturePart::getSelfObstacle ( int  i)
inline

Gets hole (inner ring) - considered as obstacle.

Definition at line 301 of file feature.h.

◆ hasFixedPosition()

bool pal::FeaturePart::hasFixedPosition ( ) const
inline

Returns true if the feature's label has a fixed position.

Definition at line 278 of file feature.h.

◆ hasFixedRotation()

bool pal::FeaturePart::hasFixedRotation ( ) const
inline

Returns true if the feature's label has a fixed rotation.

Definition at line 272 of file feature.h.

◆ hasSameLabelFeatureAs()

bool FeaturePart::hasSameLabelFeatureAs ( FeaturePart part) const

Tests whether this feature part belongs to the same QgsLabelFeature as another feature part.

Parameters
partpart to compare to
Returns
true if both parts belong to same QgsLabelFeature

Definition at line 156 of file feature.cpp.

◆ isConnected()

bool FeaturePart::isConnected ( FeaturePart p2)

Check whether this part is connected with some other part.

Definition at line 1748 of file feature.cpp.

◆ isObstacle()

bool pal::FeaturePart::isObstacle ( ) const
inline

Returns true if the feature should act as an obstacle to labels.

Definition at line 287 of file feature.h.

◆ layer()

Layer * FeaturePart::layer ( )

Returns the layer that feature belongs to.

Definition at line 146 of file feature.cpp.

◆ mergeWithFeaturePart()

bool FeaturePart::mergeWithFeaturePart ( FeaturePart other)

Merge other (connected) part with this one and save the result in this part (other is unchanged).

Returns true on success, false if the feature wasn't modified

Definition at line 1764 of file feature.cpp.

◆ nextCharPosition()

bool FeaturePart::nextCharPosition ( double  charWidth,
double  segmentLength,
PointSet path_positions,
int &  index,
double &  currentDistanceAlongSegment,
double &  characterStartX,
double &  characterStartY,
double &  characterEndX,
double &  characterEndY 
) const

Returns true if the next char position is found. The referenced parameters are updated.

Definition at line 1841 of file feature.cpp.

◆ obstacleFactor()

double pal::FeaturePart::obstacleFactor ( ) const
inline

Returns the feature's obstacle factor, which represents the penalty incurred for a label to overlap the feature.

Definition at line 293 of file feature.h.

◆ repeatDistance()

double pal::FeaturePart::repeatDistance ( ) const
inline

Returns the distance between repeating labels for this feature.

Definition at line 296 of file feature.h.

◆ setTotalRepeats()

void FeaturePart::setTotalRepeats ( int  repeats)

Returns the total number of repeating labels associated with this label.

See also
totalRepeats()

Definition at line 229 of file feature.cpp.

◆ showUprightLabels()

bool FeaturePart::showUprightLabels ( ) const

Returns true if feature's label must be displayed upright.

Definition at line 1817 of file feature.cpp.

◆ totalRepeats()

int FeaturePart::totalRepeats ( ) const

Returns the total number of repeating labels associated with this label.

See also
setTotalRepeats()

Definition at line 224 of file feature.cpp.

Member Data Documentation

◆ mHoles

QList<FeaturePart *> pal::FeaturePart::mHoles
protected

Definition at line 341 of file feature.h.

◆ mLF

QgsLabelFeature* pal::FeaturePart::mLF = nullptr
protected

Definition at line 340 of file feature.h.


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