-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Comments
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) 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.
|
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. |
Author Name: Hugo Mercier (@mhugo) Thank you Nyall for your analysis ! |
Author Name: Alexey T (@Xeenych) Please add center alignment and justify alignment as in https://issues.qgis.org/issues/21499
|
This can be closed out as the North Road update to QGIS 3.16 adds this functionality. |
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)
The text was updated successfully, but these errors were encountered: