[mapserver-users] Using classes to set the color of a shape

Vinko Vrsalovic B. v at w.cl
Tue Aug 21 06:16:34 PDT 2001


Hello all. 

	Briefly: How do I set dynamically a shape crated from a shapefile
to be part of one class on a layer?

	Not so briefly: I have a set of shapefiles with one line each, and based
on user's input I display a subset of them on the map. I render them all
on the same layer. The layer has 7 classes and the subset is always smaller
than 7 (each class has a different color, and that's what I'm pursuing here).
The problem is all the shapes created from the shapefiles have a classindex 0,
and I don't know how to change it to be part of a specific class of the layer.

I'm doing that this way:

$layer_lines is the layer created from the map file.

for ($i=0;$i<7;$i++) {
	if (user said yes to i)
		$shape[i] = create_shape_from_shapefile($shapefile[i]);
}

$image=$map->draw();

for ($i=0; $i<7 && (user said yes to i); $i++) {
	$shape[i]->draw($map,$layer_lines,$image,$i,"");
}

I was hoping for the $i parameter of the draw shape method to set
the class on $layer_lines, but they all are drawn on class 0.

What can I do to make this work? or what's the correct method for setting
colors dynamically for a set of shapes? (hopefully not involving creating
layers because of the infamous invalid maphandle).

Ah, and create_shape_from_shapefile is:

 	$shapefile = ms_newShapefileObj($file.".shp",-1);
        $shapeobj = ms_newShapeObj(MS_SHAPE_LINE);

        $shp = $shapefile->getShape(0);
        $line = $shp->line(0);
        $shapefile->free();

        $shapeobj->add($line);
        $shp->free();

        return $shapeobj;           

(As I said, the shapefiles only have one line)

Yes, I'm using PHP4.0.6 and PHP MS 3.5 latest build. :)

Thanks for the help.
-- 
V. <v at w.cl>



More information about the MapServer-users mailing list