mapnik / mapnik-support

Use the issues queue here to ask questions and offer help on using Mapnik (maybe if this works well we can retire the mailing list at http://mapnik.org/contact/?)
6 stars 6 forks source link

Labels for mountain ranges #130

Open zdila opened 4 years ago

zdila commented 4 years ago

Hello,

How to generate curved labels of mountain ranges like you can see for example in the following maps?

I know, OTP map is opensource and I see how they do it but it seems very complext to me. Moreover it would be best not to do it with any pre-processing.

Any ideas?

talaj commented 4 years ago

Hi, there is horizontal-alignment="adjust" for that, see https://github.com/mapnik/mapnik/pull/2426.

But the version in upstream mapnik will not make the placement sometimes. I fixed it in downstream, but due to implementation difficulties did not get it to the upstream yet.

zdila commented 4 years ago

Thanks! I will actually find use of it for valleys where we currently use text symbolizer with multiple placements of different character spacing.

But AFAIK it works only on LINESTRINGs and mountain ranges are (MULTI)POLYGONs. Or am I missing something?

talaj commented 4 years ago

With polygons, it will probably do something you don't want - it will place the text on the polygon border. I would try to use ST_ApproximateMedialAxis (+ buffer + simplify) to get linestring out of it.

zdila commented 4 years ago

Thanks, I've already tried it that way but I thought it is not the right direction. See my question at https://gis.stackexchange.com/questions/312283/st-approximatemedialaxis-returns-multilinestring-instead-of-single-linestring.

But if you were successful then I will continue to play with it this direction. (And if you have and you can provide a complete solution or a sample I won't be angry ;-)).

But the version in upstream mapnik will not make the placement sometimes.

Will it happen often? And in such a case will it prevent rendering the text completely?

I fixed it in downstream, but due to implementation difficulties did not get it to the upstream yet.

Fingers crossed to make it there!

talaj commented 4 years ago

From what I could find we have mountain ranges manually defined as linestrings by cartographers.

But I think it should be doable with enough buffer used before ST_ApproximateMedialAxis. Then maybe ST_LineMerge and pick the longest linestring. I accidentally found this: https://github.com/der-stefan/OpenTopoMap/issues/134

Will it happen often? And in such a case will it prevent rendering the text completely?

It happens rarely. I described the problem in https://github.com/mapnik/mapnik/issues/3662#issuecomment-297688308 (but in the case of that issue, the questioner had problem with max-char-angle-delta finally).

My solution in downstream is to use https://github.com/mapnik/mapnik/pull/3512 to make lines always long enough. But it needed some ugly "ifs" in the upstream code when I was trying it.

zdila commented 4 years ago

Thank you very much for all the details! I will put here the solution once I find it :)

zdila commented 4 years ago

So far we (I) couldn't find any good solution and so we will probably define mountain ranges (and valleys etc) manually as mapy.cz did.

BTW opentopomap uses following script to do it: https://github.com/der-stefan/OpenTopoMap/blob/master/mapnik/tools/arealabel.sql