9

I was wondering if anyone knew the math involved, or resources for learning the math involved, in finding the ideal position, scale, and rotation of a label for a line or polygon on a map?

The most I've got so far is finding the centroid for a polygon (though it's not ideal for concave polygons).

2

6 Answers 6

2

A research paper that addresses this hard issue: http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4015429

2

Maybe the documentation of the PAL labeling library is a good start for further research. I especially recommend "From Point Feature Label Placement to Map Labelling".

2

Centroid is never the answer but it is a good initial guess. The algorithms which are easiest to implement that solve similar problems usually operate by trying a few reproducible pseudo-random positions and scoring them somehow, keeping the best spots. For further reading I would start by reading up on bin packing algorithms and take it from there.

1

Labeling is a nasty endeavor.

At a small scale: you have label overlap problems, so which one do you remove or should all be shown.

At a large scale: if you have a large polygon, where do you display the label. Do you display it multiple times.

0

I've seen maps where they just calculate a bounding box for a complex polygon and place the label in the center of that.

For simple lines, usually it's just the middle of the two endpoints.

I guess it really just depends on what you expect your data to be and how important the location of the label is.

1
  • 3
    What's up with the downvote? A comment might be useful. Jul 29, 2010 at 23:46
0

You can inspect the code in GeoTools and GeoServer if you grok java - it is a constantly evolving problem as people keep coming up with new corner cases that need fixing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.