[mapserver-dev] Ok, one more labeling sample...

Steve Lime Steve.Lime at dnr.state.mn.us
Wed Sep 17 18:43:21 EDT 2008


Here are world countries before and after. Note we can cram on more labels with better placement, imagine that...

Steve

>>> "Steve Lime" <Steve.Lime at dnr.state.mn.us> 09/17/08 5:37 PM >>>
As I putzed with the polygon label point code I realized that the line intersection and centering was screwing up some optimal placements based solely on the center of gravity computation. You really only want to go to that extreme if 1) the CoG is outside the polygon or 2) it's near the edge of the polygon. So, I've accounted for those and added a switch that centers the label on the either a vertical or horizontal line depending on the CoG departure from the bbox center point.

Anyway the algorithm looks like so:

1) compute CoG of largest (in terms of area) outer ring
2) if that point falls within the polygon
  a) compute shortest distance to polygon
  b) if distance is greater than 10% of largest bbox dimension then quit, your done
  c) if not, then point is near an edge go to step 3)
3) intersect a vertical or horizontal line with the polygon and the CoG and find the longest segment, using the mid-point of that segment as the label point

With the U.S. states shapefile 9 polygons (e.g. FL, LA) are close to the edge and fall through to step 3. Not sure what the right value is there. The results are quite nice however. I've attached images from this method and the current 5.2 output. Again, I can supply a patch if anyone would like to try it. I'll supply before and after for a few of the test datasets folks sent in separate messages.

Steve

-------------- next part --------------
A non-text attachment was scrubbed...
Name: country.png
Type: image/png
Size: 25970 bytes
Desc: Portable Network Graphics Format
Url : http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20080917/2ee006f6/country-0001.png
-------------- next part --------------
A non-text attachment was scrubbed...
Name: country_52.png
Type: image/png
Size: 25891 bytes
Desc: Portable Network Graphics Format
Url : http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20080917/2ee006f6/country_52-0001.png


More information about the mapserver-dev mailing list