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).

Bob
  • 191
  • 3
  • I guess it is best to do this manually. – Jonas Jul 23 '10 at 16:12
  • Related resource: http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.54.8844 The Computational Complexity of Cartographic Label Placement. Citation includes other associated references. – glennon Jul 30 '10 at 00:11

6 Answers6

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.

Midavalo
  • 29,696
  • 10
  • 48
  • 104
Dandy
  • 939
  • 7
  • 14
2

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

julien
  • 10,186
  • 6
  • 55
  • 93
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".

underdark
  • 84,148
  • 21
  • 231
  • 413
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.

CrazyEnigma
  • 253
  • 2
  • 7
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.

Jon Bringhurst
  • 499
  • 5
  • 11
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.

Ian Turton
  • 81,417
  • 6
  • 84
  • 185