Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options to draw label on the beginning or the end of a line #28666

Closed
qgib opened this issue Dec 19, 2018 · 5 comments
Closed

Add options to draw label on the beginning or the end of a line #28666

qgib opened this issue Dec 19, 2018 · 5 comments
Labels
Feature Request Labeling Related to QGIS map labeling

Comments

@qgib
Copy link
Contributor

qgib commented Dec 19, 2018

Author Name: Regis Haubourg (@haubourg)
Original Redmine Issue: 20847

Redmine category:labelling


I encountered this need for the first time today.
It matches this question. https://gis.stackexchange.com/questions/207736/how-to-label-the-start-end-of-the-line-in-qgis
It show a list of options that would make a lot of sense for us in QGIS.

(note: looking for supporters to do that)


@qgib
Copy link
Contributor Author

qgib commented Dec 20, 2018

Author Name: Nyall Dawson (@nyalldawson)


Hey Regis,

I've actually investigated this in the past, and it's not a huge change required.

The bulk of the changes come down to 3 places:

https://github.com/qgis/QGIS/blob/master/src/core/pal/feature.cpp#L746 (straight line labels, when being labeled on "straight" segments)
https://github.com/qgis/QGIS/blob/master/src/core/pal/feature.cpp#L901 (straight line labels, when being labeled over "curved" parts of a line (this is used when the above case fails))
and
https://github.com/qgis/QGIS/blob/master/src/core/pal/feature.cpp#L1240 (curved line labels)

These 3 places calculate a cost for the label candidate based on its distance from the center of the line.

What's needed is to add similar logic for other placements.

What I would suggest is that we add an "lineAnchorPointFraction" setting Pal::Layer. This would default to 0.5 - indicating that labels should be around the midpoint of the line. But it could then be set to any fraction - e.g. 0 to anchor them to the start of the line, 1 for the end, 0.25 for 1/4 of the way from the start, etc. The 3 cost calculation places in feature.cpp would then use this fraction instead of the hardcoded mid point of the line when calculating the costs.

That would allow the labeling engine to respect a "% along line" type setting (which could be exposed to users as mid/start/end/custom %, along with data-defined per-feature custom %).

Ideally we'd also want to allow a custom placement from start/end of line which is set in absolute units, e.g. mm/pixels/map units. This would add a bit to the complexity, but it comes down to adding a second lineAnchorPointOffset setting to Pal::Layer and also handling this in the 3 places in feature.cpp.

That was my earlier findings -- you can easily test these by altering the 3 places in feature.cpp and changing the hardcoded midpoint to something like 0, to force all labels to gravitate to the start of lines. See attached patch/screenshot.

nyalldawson@59d80fb


  • 14011 was configured as lines.png

@qgib
Copy link
Contributor Author

qgib commented Jan 14, 2019

Author Name: Regis Haubourg (@haubourg)


Thanks Nyall! I didn't see your answer before today. I'm adding Hugo in the loop, he has been involved in labeling related QEPs.

@qgib
Copy link
Contributor Author

qgib commented Jan 14, 2019

Author Name: Hugo Mercier (@mhugo)


Thank you Nyall for your analysis !

@qgib
Copy link
Contributor Author

qgib commented Mar 6, 2019

Author Name: Alexey T (@Xeenych)


Please add center alignment and justify alignment as in https://issues.qgis.org/issues/21499


  • 14533 was configured as example.jpg

@pjshelton
Copy link

This can be closed out as the North Road update to QGIS 3.16 adds this functionality.
https://north-road.com/2020/09/03/line-label-placement-our-gift-to-the-qgis-community/

@gioman gioman closed this as completed Dec 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Labeling Related to QGIS map labeling
Projects
None yet
Development

No branches or pull requests

3 participants