Label cache and potting in 4.8.1

Steve Lime Steve.Lime at DNR.STATE.MN.US
Wed Jun 13 15:46:45 EDT 2007


Hi Peter: (comments inline)

>>> On 6/13/2007 at 10:16 AM, in message
<LISTSERV%200706131016026324.48E6 at LISTS.UMN.EDU>, Peter Bruton
<peter.bruton at NRCAN.GC.CA> wrote:
> Hello;
> 
> I am using MapServer 4.8.1 and would like to control the order in which
> labels are plotted on a map.  Lets say I have 2 annotation layers.  One
> layer has capital city labels and the second has populated place labels. 
> How would I ensure that all capital city labels are plotted first and then
> populated place labels are plotted?

That's easy, draw the capital labels last and they will be given priority.

> Besides the general question I have outlined in the previous paragraph I
> would like to know how MapServer assembles the labelcache and then orders
> labels in the cache.  As I understand it MapServer 4.8.1 uses the last in
> first out (LIFO) mechanism to plot labels on a map.  To use the previous
> paragraphs example, would I position the populated place layer second from
> the bottom of my mapfile and the capital city layer at the bottom of my
> mapfile so that the capital city layer is read into the cache last and thus
> plotted first?  I presume that once all of the capital city labels are
> removed from the cache, the populated place layers are plotted.

This is correct, LIFO...

> If that is the case, how does Mapserver determine the order in which the
> labels in that capital city layer are ordered in the cache and then plotted?
>  As I understand it, I can use the "sortshp" utility to oder the records in
> a shapefile to control plotting order of labels.  However, not all
> shapefiles have an attribute that can be used to sort the shapefile records.
>  If a data set does not have an attribute that allows for the sorting of
> shapefile records, how does MapServer order labels in the cache?

The labels are always LIFO. So, if you do an ascending sort on population (biggest
city last) then the biggest cities will take priority. If you don't sort MapServer
renders based on the order features are placed in the cache. For a shapefile that
means the order they appear in the file.

(I should note that ver. 5.0 will feature a new label priority parameter for
more fine tuning in this respect.)

> I am interested in understanding how MapServer's label plots labels on a
> map.  Suppose the LABEL object's POSITION parameter is set to AUTO.   One
> way that labels can be positioned is for the first label in the cache
> plotted in an absolute position and never moved?  Then the the second label
> position is determined by any LABEL object parameters (such as BUFFER,
> OFFSET, etc.) and the location of the first label.  The second label now has
> an absolute position and is never moved.  The rest of the labels in the
> cache (third, fourth, etc.) are plotted in a similar manner.  Is this how
> MapServer positions labels or is some other strategy used?

Labels are plotted with AUTO until they fit with no overlap, they are not adjusted
once placed. I believe the UL position is first. If that won't work then we work 
around the positions counter clockwise until one works. If one doesn't then the
label is skipped. It's not optimal but works reasonably well and is reasonably fast.

Parameters like buffer, offset and angle are applied to a labels minimum bounding 
rectangle before collision computations are handled.

> Any insight on how MapServer's label cache and plotting is appreciated.
> 
> Peter Bruton

Steve



More information about the mapserver-users mailing list