Mapscript - Sorting labels

Gribol gribol at FREE.FR
Thu Jun 9 22:54:42 PDT 2005


; > 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
; > issue.
; >
;
; I think you may be able to do that with the sortshp utility, see:
; http://mapserver.gis.umn.edu/utils.html
;
; Daniel
; --
; ------------------------------------------------------------
;   Daniel Morissette               dmorissette at dmsolutions.ca
;   DM Solutions Group              http://www.dmsolutions.ca/
; ------------------------------------------------------------

Thank you Daniel for your answer.
But it's not working. In fact, the shapefile is already sorted with a
descending order on the population field.
When I display the whole earth, all is fine. I do some zoom in, again it's
fine. But at a specific scale, when I display all towsn with a population
number higher than 100000, there is an error, because 2 smalls towns (with
150000 citizens) are displayed and not a major town with 800000 citizens.

Here is the layer description in the map file :

	LAYER
		NAME "villes"
		TYPE ANNOTATION
		DATA "../data/WorldCities.shp"
		STATUS OFF
		LABELITEM "name"
		LABELCACHE ON

		CLASS
			COLOR 200 10 10
			SYMBOL 'circle'
			SIZE 5
			OUTLINECOLOR 255 255 255
			LABEL
				ANGLE 0.0
				POSITION AUTO
				ANTIALIAS TRUE
				TYPE TRUETYPE
				FONT arial-bold
				SIZE 10
				MINDISTANCE 190
				OFFSET 0 0
				BUFFER 10
				COLOR 200 0 0
				OUTLINECOLOR 255 255 255
				PARTIALS FALSE
			END
  		END

		PROJECTION
			"proj=latlong" "ellps=WGS84" # Geographic
		END
	END

and here is the php-mapscript code I use :

function DrawCities($Map)
{
	// Get the layer
	$LayerName = $Map->getLayerByName("villes");
	if($LayerName == NULL) return;
	$LayerName->set("status", MS_ON);

	// Get the class
	$ClassVille = $LayerName->getClass(0);

	// Compute "step" value according to the current map extent
	$nPas = nCalculPas($Map);

	$strFilter = "";
	if($nPas >= 30)
	{
		$strFilter = "([POPULATION] >= 2000000)";
	}
	else
	if($nPas >= 15)
	{
		$strFilter = "([POPULATION] >= 1000000)";
	}
	else
	if($nPas >= 5)
	{
		$strFilter = "([POPULATION] >= 500000)";
	}
	else
	if($nPas >= 2)
	{
		$strFilter = "([POPULATION] >= 100000)";
	}
	else
	{
		$strFilter = "([POPULATION] >= 0)";
	}

	$LayerName->setFilter($strFilter);
}

the function "nCalculPas" returns a value according to the current map
extent. High value means a large map extent. When I zoom in, the map extent
decreases and this function returns a smallest value.

Marc.



More information about the MapServer-users mailing list