Mapscript - Sorting labels

Bill Binko bill at BINKO.NET
Wed Jun 8 18:17:59 EDT 2005


On Wed, 8 Jun 2005, marc wrote:

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

Bill



More information about the mapserver-users mailing list