Mapscript - Sorting labels
gribol at FREE.FR
Thu Jun 9 15:55:26 EDT 2005
; > Hi,
; > I have a shapefile (points) which contains cities names. For
; each town, a
; > field contains the population number.
; > I would like to renderer my map with cities names. I use
; Mapserver's stuff
; > to avoid name collisions. I use the population field to do some
; > I use PHP-Mapscript.
; > Here is a pseudo algorithm:
; > IF map_extent > 180 THEN render shapes with population > 5000k
; > ELSE IF map_extent > 90 THEN render shapes with population > 2500k
; > ELSE IF map_extent > 45 THEN render shapes with population > 1000k
; > ...
; > When the current map extent fits the first condition, it's fine.
; > But for the others conditions, all matching shapes are rendered
; but without
; > any sort between them.
; > For the second condition, I would like to render first the
; shapes with pop
; > > 5000k, then next the shapes with 5000k > pop > 2500k.
; > If I use 2 classes in a same layer, it is not working. I can
; have names of
; > towns which are in the range [2500k-5000k] and no name in the
; range > 5000k
; > (I suppose that there are towns with pop > 5000k, but the Mapserver
; > collision treatment filters them).
; > So I cannot guarantee that cities with pop > 5000k are first
; displayed. And
; > next, cities with population in the range [2500k-5000k].
; > I get the same issue with 2 layers and a FILTER attribute on each layer.
; I'm sure there are lots of ways to implement this, but I recently did
; something similar using ogr2ogr to split the shapefile. It also has the
; side benefit of making the zoomed out layers much faster.
; You might get away with
; $ ogr2ogr -where "population > 1000000" cities10.shp cities.shp
; $ ogr2ogr -where "population > 2500000" cities25.shp cities.shp
; $ ogr2ogr -where "population > 5000000" cities50.shp cities.shp
; Then you just create three layers with different maxscales.
I don't think that your solution will work. If I use the cities25.shp, this
shape contains names of towns with a population higher than 2500k. But what
I want is to prioritize the rendering of towns labels : First, towns with a
population higher than 5000k and next towns with a population higher than
Juste a simple exemple :
"Label30" is the label of a town with a population of 3000k.
"Label55" is the label of a town with a population of 5500k.
These two labels are closest (in pixel coordinates) and cannot be displayed
both at the current map extent (because of names collision). These two
labels are matching the filter condition (higher than 2500k).
How to force Mapserver to draw the "Label55" and not "Label30" ? That is my
More information about the mapserver-users