[mapserver-users] PHP/MapScript : Retrieving the centroid of a shape

LACROIX Gilles lacroix at boston.bertin.fr
Tue Jun 4 11:48:25 EDT 2002


I am trying to use PHP/MapScript to display (dynamic) labels on selected
shapes from a layer. To do so, I need to retrieve the "centroid" of
these shapes (a basic "middle of the bounding box" algorithm doesn't
help because the centroid must fall into the shape, whatever the shape
looks like). Is it possible with MapScript ?

I've tried to define a 'point' layer based on my 'polygon' data as well
as an associated class object with a 'label' definition inside. But,
when I use 'setexpression()' (to select the shapes) and then
'drawQueryMap()' to render the selected labels, I get the same labels on
all vertices of every shape (even if I use a "COLOR" line in the map
file to declare "filled" polygons and set TEMPLATE to "" to make the
query possible). 

Any idea, or example of something similar ?



More information about the mapserver-users mailing list