[mapserver-users] Piechart Symbols
Hankley, Chip
Chip.Hankley at GASAI.Com
Mon May 13 11:32:37 PDT 2002
Hmmm.... I can think of a couple of ways to do that.
1) (easiest, least flexible). Use the SYMBOL feature under CLASS in a
mapfile to specify a symbol (an image file for a point location). For
example, the following class definition will use 'microwave.gif' to
symbolize all points where the value is 'Microwave.'
CLASSITEM FEAT_TYPE
CLASS
EXPRESSION 'Microwave'
COLOR 255 255 255
SYMBOL 'symbols/microwave.gif'
END # CLASS
Without knowing all of the details of your situation, I can't go much
further, but this is certainly a possibility... just make sure that the
output of your graphics program names the files so that they match that
specified by SYMBOL.
You should be able to manipulate the class definition through mapscript on
the fly as well.
2) (more difficult, maybe more flexible)... You can embed images into the
image that mapserver returns. The following PHP / MapScript function does
this. Play with the code a little bit, but the bottom line is that if you
KNOW the XY coordinates of the point you want to put the pie chart at, you
can embed the image before it goes out to the client.
This function is really made for putting an image at the same spot on a map
(like a north arrow, or a "this map made by Chip" statement, or the like.
So, I have to "back calculate" real coordinates from a fixed spot on the
image (pixel 20, 18, for instance). You wouldn't really need to do that part
of it b/c you would, presumably, be putting the image at the real coordinate
position of a point.
function embed_picture($map, $Cur_Extent, $img, $img_name, $img_x, $img_y) {
//$map - the map object
//$Cur_Extent - an array of xmin, ymin, xmax, ymax for the current extent
//$img - an image object created by $map->draw();
//$img_name - the file name and location of the image you want to embed
//$img_x, $img_y - the x y location in pixels of the location you want the
// embeded image to be.
//Create a new Point Layer
$layer = ms_newLayerObj($map);
$layer->set("name", "legend");
$layer->set("type", MS_LAYER_POINT);
$layer->set("status", 1);
//Create a new Class for the Layer
$class = ms_newClassObj($layer);
$class->set("name", "legendclass");
$symb = $map->getSymbolByName($img_name);
$class->set("symbol", $symb);
//symbols/legend.gif
//Place the point so that it is $Pixel_X pixels IN and $Pixel_Y
// pixels UP from the lower left hand conrner of
// the image.
$ImgWidth = $map->width;
$ImgHeight = $map->height;
$Pixel_X = ($Cur_Extent[2] - $Cur_Extent[0]) / $ImgWidth;
$Pixel_Y = ($Cur_Extent[3] - $Cur_Extent[1]) / $ImgHeight;
$Spot_X = $Cur_Extent[0] + $img_x * $Pixel_X;
$Spot_Y = $Cur_Extent[1] + $img_y * $Pixel_Y;
$point = ms_newpointObj();
$point->setXY($Spot_X, $Spot_Y);
$point->draw($map,$layer,$img,'legendclass',undef);
$layer->draw($img);
}
Hope that helps!
Chip Hankley
More information about the MapServer-users
mailing list