Setting classindex of shape instances in MapScript

Sean Gillies sgillies at FRII.COM
Wed Dec 8 09:40:25 EST 2004


On Dec 8, 2004, at 2:55 AM, Holger Floerke wrote:

> Hi there,
>
> under which circumstances I can set the "classindex" attribute of a
> shape
> instance from MapScript?
>
> I tried to open an existing layer (from the mapfile definitions) with
> open,
> iterate over the shapes (getShape) and use the
> shape->set("classindex",x)
> method to dynamically assign a class (generated bythe script) to this
> shape. After closing the layer the assignments are lost. The shapes do
> not
> show the assigned styles and retrieving the shape again after the
> close-method shows the old value.
>
> After that dilemma I create a layer with MapScript, open the shape-file
> with ShapeFileObj, iterate over the shapes, assings the
> "classindex"-attribute and push the onto the layer with "addFeature".
> That
> works, but I can't retrieve the associated values of the shape without
> manually openign the dbf-file.
>
> The goal is the color the shapes with the result of a complex
> computation.
> I tried to add the results as a value to the shapes and let the
> expression
> of the ClassObj choose the class, but I couldn't dynamically add some
> values to the shapes of a layer with a datafile assigned.
>
> Any ideas?
>
> HolgeR
>

Holger,

Setting the classindex only has meaning for shapes that are subsequently
added to the layer with setFeature or that are drawn individually using
shapeObj::draw.  I recommend the second approach for your application.
There is at least one bug in shapeObj.draw -- it does not honor the
transparency of the specified layer, but it will work.

In the development version I have recently added a few default values to
newly created shapes and a shapeObj::setValue method that can be used to
allow labeling of inline features, but this feature won't be released
soon.

cheers,
Sean


--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies



More information about the mapserver-users mailing list