-
Notifications
You must be signed in to change notification settings - Fork 826
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
[WIP] Polylabel and improved interior algorithm #3780
Conversation
@talaj looks great! |
I'm thinking about another improvement - adding some degree of freedom with polygon label placement. Typical use case is that we have a capital of some administrative area and it's located in the middle of that area, so we have to choose which labels are more important - for example Madrid: http://www.openstreetmap.org/relation/5326784#map=5/41.935/3.889 It would be good to allow the label of the country to be moved around if possible (within some user defined radius) to show both names. |
Isn't this achieved with |
These are just part of styling. I mean something like text-label-position-tolerance, which allows to move labels a bit to fit them better if needed, if I understand it correctly. |
@yohanboniface is correct, placement-type parameter is for that. Some information about it can be also found in the wiki. |
I don't get the "X" option - could you describe it more clear? And will it work with the polygons? |
I've been consulting with Polish community and it looks like X just allows to shrink the text, which has nothing to do with moving labels. Madrid label would still be clashing with Spain on z4-z5. I was also trying to add
|
|
I know these options, but do you know if |
With
Then there is some other aspect. Maybe a bug, but I doubt, this is a widely used, well tested feature. Those labels must not have |
I'm not sure if it's clear what I mean. Static methods are just not the right tool for my issue. They are needed to make the style look in a certain way, but they are not meant to deal with fitting more labels - and this is a problem I want to solve.
What I'd like to have would be:
We could check if we're not totally outside the polygon line also in the first case (BR - Bound Range?), but that means additional code and is just an option for R. |
Yes, There is also an open pull request with I'm using this
I don't know what makes you think that |
But what do you think of flexible radius in general? Do you think it's not needed, that it could be tricky to implement or simply that there is nobody interested in coding it at the moment, for example? Of course I can try some other ways if I don't have this one, but I prefer to solve the problem this way if possible (SNEW or font size will not help with some typical cases, and a list means manual work, which is better suited for small scale map without big style changes). |
I've just read grid placement documentation. I initially thought it's for repeated labels, but now I feel it can be used also for a single label:
Sounds to me more or less like what I described as "anywhere inside the area", if I understand it correctly, which would be great to have.
What could be done to help you raise the motivation then? 😄 |
The I'm wondering why do you need this now, after so many years of development of OSM Mapnik styles. There has to be some standard way how to solve such collisions in OSM. It's so basic thing.
I don't know about any issue here in Mapnik where such feature is requested, except of that still open pull reqeust with Also placement type
Yes, if you set |
OK, I will try to offer it to the upstream. |
Back to the main topic. I've made some changes to the algorithm to improve filtering of possible placements. I've also set precision of polylabel algorithm to 10 instead of default 1. It has a negligible effect to visual output, but performance is now about the same as with the new interior algorithm. Here are some new tests I've added. I excluded some totally uninteresting cases with symmetric polygons where centroid, interior and polylabel have the same placement. 006, 007, 008, 011, 012, 013, 016, 017, 018, 020, 025, 026, 027, 028, 029, 031, 032, 033, 034, 035, 037, 040, 042, 043, 044, 045, 046, 049, 050, 052, 053, 055, 056, 058, 059, 060, 061, 062, 063, 064, 065, 066, 067, 068, 069, 071, 072, 073, 074, 076, 077, 079, 080, 081, 085, 086, 087, 088, 089, 090, 091, 093, 095, 096, 097, 099, 100 These are new results of old tests: 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
It looks like polylabel is kind of eccentric, at least in this set of tests - it tends to locate the label near the ends of the object. Improved interior works for me much better most of the time. |
It's because polylabel is "too precise". It's evident on this polygon: The polylabel placement is great as a pole of inaccessibility, but weak as a label placement.
I agree that this test set is not objective. It contains only polygons of buildings. I'm going to make another set with "natural" polygons. I'm also going to try to modify polylabel in such a way it will prefer positions closer to centroid. Something like mapbox/polylabel#33. I feel some potential there. |
It's nothing new and it's not only me, for example gravitystorm/openstreetmap-carto#1069 is already 3 years old. I guess it's a general OSM problem - lack of communication between the projects.
Which OSM project do you mean? In osm-carto we don't have the tools, so we just use suboptimal solutions. BTW: Are you from Czechia? We plan to hold a regional conference in Poznań, 13-14 April 2018 ( https://wiki.openstreetmap.org/wiki/State_of_the_Map_Poland_2018 ). It would be great if you could come so we could talk about map rendering more (at least one more osm-carto developer plans to attend there - @matkoniecz). |
To the main topic: I've managed to modify Polylabel to prefer placements closer to centroid. It now gives almost the same results as the improved Interior. Take a look on new versions of reference images: 006, 007, 008, 011, 012, 013, 016, 017, 018, 020, 025, 026, 027, 028, 029, 031, 032, 033, 034, 035, 037, 040, 042, 043, 044, 045, 046, 049, 050, 052, 053, 055, 056, 058, 059, 060, 061, 062, 063, 064, 065, 066, 067, 068, 069, 071, 072, 073, 074, 076, 077, 079, 080, 081, 085, 086, 087, 088, 089, 090, 091, 093, 095, 096, 097, 099, 100 01, 02, 03, 04, 05, 06, 07, 08, 09, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 |
Now it's a tie - I have spotted 3 cases where polylabel was worse than interior and 3 other where it won (especially 093). Otherwise they are similar and in some hard cases (like 099) they both are equally fooled. |
Closed in favor of #3811. |
Tak jest. I would really like to come. |
Hi, do you still plan to merge |
@kocio-pl - Yes, definitely, I plan to work on it, but there were also some other issues I had to solve. It may be a quite long process to get these features to OSM. The new interior algorithm is now merged to the master, which will be Mapnik 3.1 once. But when, who knows? Mapnik is being released from 3.0.x branch now. We can try to speed the process up by porting these changes to the 3.0.x branch. |
New interior algorithm is not that important to me - fixing labels outside the polygon was, because this was visible error, so 3.0.18 release is important, because it fixes also nasty SVG bug, but that's all we need for now. Once the |
OK, good to know. So I will try to focus on the |
Thanks! I guess releasing 3.0.18 is in the hands of @artemp? |
@kocio-pl - yes, we have 3.0.18-rc1 already, the plan is to release soon. |
@artemp - Yes, the new interior placement will work without that dependency on upstream polylabel. A bit more laborious can be to port all the visual tests, which basically all depend on polylabel placement. I can create a pull request with the new interior placement against 3.0.x branch with updated tests, if you want. |
@talaj - yes, please :) |
@artemp OK |
@talaj - ping, did you have a chance to work on this ? Would be great to get 3.0.18 released soon, cheers! |
@artemp - Yes, I will try to offer it this week. I'm self assigning the issue. |
👍 |
Which http://mapnik.org/mapnik-reference/#3.0.20/shield-repeat-distance I'm also not sure about which |
@kocio-pl There are |
Oh, thanks, great! I don't know why I haven't found |
An attempt to improve interior algorithm.
It's based on original interior algorithm, but instead of single horizontal bisector crossing centroid, arbitrary number of bisectors can be used. The number of bisectors controls precision of final placement and can be set as input parameter. Placements also gravitate toward centroid to avoid highly eccentric placements. Please, take a look at the code for details, the algorithm is very simple.
I've also added Polylabel algorithm. Here is a rough performance comparison. Values are milliseconds of overall rendering, when I left only single marker in the style.
For visual comparison, please, take a look at visual test results.
I'm going to add more tests and performance benchmarks.
Refs #3550, #3539.
cc @kocio-pl