QGIS API Documentation 3.41.0-Master (3c143d501a8)
Loading...
Searching...
No Matches
Public Types | 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 Types

enum  PathOffset { NoOffset , PositiveOffset , NegativeOffset }
 Path offset variances used in curved placement. More...
 

Public Member Functions

 FeaturePart (const FeaturePart &other)
 
 FeaturePart (QgsLabelFeature *lf, const GEOSGeometry *geom)
 Creates a new generic feature.
 
 ~FeaturePart () override
 Deletes the feature.
 
void addSizePenalty (std::vector< std::unique_ptr< LabelPosition > > &lPos, double bbx[4], double bby[4]) const
 Increases the cost of the label candidates for this feature, based on the size of the feature.
 
bool alwaysShow () const
 Returns true if the feature's label should always been shown, even when it collides with other labels.
 
double calculatePriority () const
 Calculates the priority for the feature.
 
std::size_t createCandidateCenteredOverPoint (double x, double y, std::vector< std::unique_ptr< LabelPosition > > &lPos, double angle)
 Generate one candidate centered over the specified point.
 
std::unique_ptr< LabelPositioncreateCandidatePointOnSurface (PointSet *mapShape)
 Creates a single candidate using the "point on sruface" algorithm.
 
std::vector< std::unique_ptr< LabelPosition > > createCandidates (Pal *pal)
 Generates a list of candidate positions for labels for this feature.
 
std::size_t createCandidatesAlongLine (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, bool allowOverrun, Pal *pal)
 Generate candidates for line feature.
 
std::size_t createCandidatesAlongLineNearMidpoint (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, double initialCost=0.0, Pal *pal=nullptr)
 Generate candidates for line feature, by trying to place candidates as close as possible to the line's midpoint.
 
std::size_t createCandidatesAlongLineNearStraightSegments (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, Pal *pal)
 Generate candidates for line feature, by trying to place candidates towards the middle of the longest straightish segments of the line.
 
std::size_t createCandidatesAroundPoint (double x, double y, std::vector< std::unique_ptr< LabelPosition > > &lPos, double angle)
 Generate candidates for point feature, located around a specified point.
 
std::size_t createCandidatesAtOrderedPositionsOverPoint (double x, double y, std::vector< std::unique_ptr< LabelPosition > > &lPos, double angle)
 Generates candidates following a prioritized list of predefined positions around a point.
 
std::size_t createCandidatesForPolygon (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, Pal *pal)
 Generate candidates for polygon features.
 
std::size_t createCandidatesOutsidePolygon (std::vector< std::unique_ptr< LabelPosition > > &lPos, Pal *pal)
 Generate candidates outside of polygon features.
 
std::size_t createCandidatesOverPoint (double x, double y, std::vector< std::unique_ptr< LabelPosition > > &lPos, double angle)
 Generate one candidate over or offset the specified point.
 
std::size_t createCurvedCandidatesAlongLine (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, bool allowOverrun, Pal *pal)
 Generate curved candidates for line features.
 
std::size_t createHorizontalCandidatesAlongLine (std::vector< std::unique_ptr< LabelPosition > > &lPos, PointSet *mapShape, Pal *pal)
 Generate horizontal candidates for line feature.
 
std::unique_ptr< LabelPositioncurvedPlacementAtOffset (PointSet *mapShape, const std::vector< double > &pathDistances, QgsTextRendererUtils::LabelLineDirection direction, double distance, bool &labeledLineSegmentIsRightToLeft, bool applyAngleConstraints, QgsTextRendererUtils::CurvedTextFlags flags)
 Returns the label position for a curved label at a specific offset along a path.
 
QgsLabelFeaturefeature ()
 Returns the parent feature.
 
QgsFeatureId featureId () const
 Returns the unique ID of the feature.
 
double fixedAngle () const
 Returns the fixed angle for the feature's label.
 
double getLabelDistance () const
 Returns the distance from the anchor point to the label.
 
double getLabelHeight (double angle=0.0) const
 Returns the height of the label, optionally taking an angle (in radians) into account.
 
double getLabelWidth (double angle=0.0) const
 Returns the width of the label, optionally taking an angle (in radians) into account.
 
int getNumSelfObstacles () const
 Gets number of holes (inner rings) - they are considered as obstacles.
 
FeaturePartgetSelfObstacle (int i)
 Gets hole (inner ring) - considered as obstacle.
 
bool hasFixedPosition () const
 Returns true if the feature's label has a fixed position.
 
bool hasFixedRotation () const
 Returns true if the feature's label has a fixed rotation.
 
bool hasSameLabelFeatureAs (FeaturePart *part) const
 Tests whether this feature part belongs to the same QgsLabelFeature as another feature part.
 
bool isConnected (FeaturePart *p2)
 Check whether this part is connected with some other part.
 
Layerlayer ()
 Returns the layer that feature belongs to.
 
std::size_t maximumLineCandidates () const
 Returns the maximum number of line candidates to generate for this feature.
 
std::size_t maximumPointCandidates () const
 Returns the maximum number of point candidates to generate for this feature.
 
std::size_t maximumPolygonCandidates () const
 Returns the maximum number of polygon candidates to generate for this feature.
 
bool mergeWithFeaturePart (FeaturePart *other)
 Merge other (connected) part with this one and save the result in this part (other is unchanged).
 
const QgsLabelObstacleSettingsobstacleSettings () const
 Returns the feature's obstacle settings.
 
bool onlyShowUprightLabels () const
 Returns true if feature's label must be displayed upright.
 
double repeatDistance () const
 Returns the distance between repeating labels for this feature.
 
void setTotalRepeats (int repeats)
 Returns the total number of repeating labels associated with this label.
 
int totalRepeats () const
 Returns the total number of repeating labels associated with this label.
 
- 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 Member Functions

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

Protected Attributes

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

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
 

Detailed Description

Main class to handle feature.

Note
not available in Python bindings

Definition at line 64 of file feature.h.

Member Enumeration Documentation

◆ PathOffset

Path offset variances used in curved placement.

Enumerator
NoOffset 
PositiveOffset 
NegativeOffset 

Definition at line 70 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 entities
geoma pointer to a GEOS geometry

Definition at line 52 of file feature.cpp.

◆ FeaturePart() [2/2]

FeaturePart::FeaturePart ( const FeaturePart other)

Definition at line 69 of file feature.cpp.

◆ ~FeaturePart()

FeaturePart::~FeaturePart ( )
override

Deletes the feature.

Definition at line 83 of file feature.cpp.

Member Function Documentation

◆ addSizePenalty()

void FeaturePart::addSizePenalty ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
double  bbx[4],
double  bby[4] 
) const

Increases the cost of the label candidates for this feature, based on the size of the feature.

E.g. small lines or polygons get higher cost so that larger features are more likely to be labeled.

Definition at line 2342 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 294 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 2476 of file feature.cpp.

◆ createCandidateCenteredOverPoint()

std::size_t FeaturePart::createCandidateCenteredOverPoint ( double  x,
double  y,
std::vector< std::unique_ptr< LabelPosition > > &  lPos,
double  angle 
)

Generate one candidate centered over 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 298 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 406 of file feature.cpp.

◆ createCandidates()

std::vector< std::unique_ptr< LabelPosition > > FeaturePart::createCandidates ( Pal pal)

Generates a list of candidate positions for labels for this feature.

Definition at line 2237 of file feature.cpp.

◆ createCandidatesAlongLine()

std::size_t FeaturePart::createCandidatesAlongLine ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
bool  allowOverrun,
Pal pal 
)

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
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 846 of file feature.cpp.

◆ createCandidatesAlongLineNearMidpoint()

std::size_t FeaturePart::createCandidatesAlongLineNearMidpoint ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
double  initialCost = 0.0,
Pal pal = nullptr 
)

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.
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 1215 of file feature.cpp.

◆ createCandidatesAlongLineNearStraightSegments()

std::size_t FeaturePart::createCandidatesAlongLineNearStraightSegments ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
Pal pal 
)

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
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 964 of file feature.cpp.

◆ createCandidatesAroundPoint()

std::size_t FeaturePart::createCandidatesAroundPoint ( double  x,
double  y,
std::vector< std::unique_ptr< 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 653 of file feature.cpp.

◆ createCandidatesAtOrderedPositionsOverPoint()

std::size_t FeaturePart::createCandidatesAtOrderedPositionsOverPoint ( double  x,
double  y,
std::vector< std::unique_ptr< 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 548 of file feature.cpp.

◆ createCandidatesForPolygon()

std::size_t FeaturePart::createCandidatesForPolygon ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
Pal pal 
)

Generate candidates for polygon features.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the polygon
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 1791 of file feature.cpp.

◆ createCandidatesOutsidePolygon()

std::size_t FeaturePart::createCandidatesOutsidePolygon ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
Pal pal 
)

Generate candidates outside of polygon features.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 2034 of file feature.cpp.

◆ createCandidatesOverPoint()

std::size_t FeaturePart::createCandidatesOverPoint ( double  x,
double  y,
std::vector< std::unique_ptr< 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 327 of file feature.cpp.

◆ createCurvedCandidatesAlongLine()

std::size_t FeaturePart::createCurvedCandidatesAlongLine ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
bool  allowOverrun,
Pal pal 
)

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
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 1457 of file feature.cpp.

◆ createHorizontalCandidatesAlongLine()

std::size_t FeaturePart::createHorizontalCandidatesAlongLine ( std::vector< std::unique_ptr< LabelPosition > > &  lPos,
PointSet mapShape,
Pal pal 
)

Generate horizontal candidates for line feature.

Parameters
lPospointer to an array of candidates, will be filled by generated candidates
mapShapea pointer to the line
palpoint to pal settings object, for cancellation support
Returns
the number of generated candidates

Definition at line 875 of file feature.cpp.

◆ curvedPlacementAtOffset()

std::unique_ptr< LabelPosition > FeaturePart::curvedPlacementAtOffset ( PointSet mapShape,
const std::vector< double > &  pathDistances,
QgsTextRendererUtils::LabelLineDirection  direction,
double  distance,
bool &  labeledLineSegmentIsRightToLeft,
bool  applyAngleConstraints,
QgsTextRendererUtils::CurvedTextFlags  flags 
)

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

Parameters
mapShapeline path to place label on
pathDistancesarray of distances to each segment on path
directioneither RespectPainterOrientation or FollowLineDirection
distancedistance to offset label along curve by
labeledLineSegmentIsRightToLeftif true label is reversed from lefttoright to righttoleft
applyAngleConstraintstrue if label feature character angle constraints should be applied
flagscurved text behavior flags
Returns
calculated label position

Definition at line 1420 of file feature.cpp.

◆ extractCoords()

void FeaturePart::extractCoords ( const GEOSGeometry geom)
protected

read coordinates from a GEOS geom

Definition at line 91 of file feature.cpp.

◆ feature()

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

Returns the parent feature.

Definition at line 94 of file feature.h.

◆ featureId()

QgsFeatureId FeaturePart::featureId ( ) const

Returns the unique ID of the feature.

Definition at line 166 of file feature.cpp.

◆ fixedAngle()

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

Returns the fixed angle for the feature's label.

Definition at line 285 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 279 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 (in radians) into account.

Definition at line 273 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 (in radians) into account.

Definition at line 268 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 305 of file feature.h.

◆ getSelfObstacle()

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

Gets hole (inner ring) - considered as obstacle.

Definition at line 307 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 288 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 282 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 220 of file feature.cpp.

◆ isConnected()

bool FeaturePart::isConnected ( FeaturePart p2)

Check whether this part is connected with some other part.

Definition at line 2383 of file feature.cpp.

◆ layer()

Layer * FeaturePart::layer ( )

Returns the layer that feature belongs to.

Definition at line 161 of file feature.cpp.

◆ maximumLineCandidates()

std::size_t FeaturePart::maximumLineCandidates ( ) const

Returns the maximum number of line candidates to generate for this feature.

Definition at line 176 of file feature.cpp.

◆ maximumPointCandidates()

std::size_t FeaturePart::maximumPointCandidates ( ) const

Returns the maximum number of point candidates to generate for this feature.

Definition at line 171 of file feature.cpp.

◆ maximumPolygonCandidates()

std::size_t FeaturePart::maximumPolygonCandidates ( ) const

Returns the maximum number of polygon candidates to generate for this feature.

Definition at line 198 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 2435 of file feature.cpp.

◆ obstacleSettings()

const QgsLabelObstacleSettings & pal::FeaturePart::obstacleSettings ( ) const
inline

Returns the feature's obstacle settings.

Definition at line 299 of file feature.h.

◆ onlyShowUprightLabels()

bool FeaturePart::onlyShowUprightLabels ( ) const

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

Definition at line 2489 of file feature.cpp.

◆ repeatDistance()

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

Returns the distance between repeating labels for this feature.

Definition at line 302 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 293 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 288 of file feature.cpp.

Member Data Documentation

◆ mHoles

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

Definition at line 349 of file feature.h.

◆ mLF

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

Definition at line 348 of file feature.h.


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