Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

EDIT: solved, see working code below

How can I set attribute values of a layer object with MapScript?

I'm using MapServer version 5.0.3, the lib is loaded in my app context

I have a simple mapfile:

    SIZE 500 500
    EXTENT -180 -90 180 90
    UNITS dd
    CONFIG      "MS_ERRORFILE" "/var/www/Data/Data/mapserver/mapserver.log"
    SYMBOLSET "/var/www/Data/Data/mapserver/symbols.sym"
    FONTSET "/var/www/Data/Data/mapserver/fontset.txt"

# load lines

        NAME "loadlines"
        DATA "/var/www/Data/Data/mapserver/data/loadlines/loadlines.shp"
        STATUS ON
        OPACITY 100
        DEBUG 5

        CLASS #default coloring
              COLOR 0 0 0
              WIDTH 6
              #PATTERN 40 10 END
            NAME "gust"
            OUTLINECOLOR 254 254 254
            COLOR 100 100 100
            #OPACITY 50

        TEMPLATE "blank.html"
        DUMP TRUE # allow GML export
            "wms_title"     "ffg_test"     
            "wms_srs"       "EPSG:54004 EPSG:4269 EPSG:4326" 

Which I want to view by calling this php script:


$map = ms_newMapObj($map_path."");
$layer = $map->getLayerByName('loadlines');
$layer->set('opacity', 10);


      <IMG SRC=<?php echo $image_url; ?> >

The script should alter the opacity value of the layer, but there is no effect.

How can I do this? Thank you.

share|improve this question
up vote 0 down vote accepted

Not sure about the old version of mapscript, the documentation is not available anymore. But for the latest version of PHP mapscript, the property of layer object is set via 'set' method.

int set(string property_name, new_value)
    Set object property to a new value.

So maybe you can try with:

$layer->set('opacity', 10);
share|improve this answer
allright, i'll have a try in the morning! – jorrebor Sep 17 '13 at 17:26
Great it works! – jorrebor Sep 18 '13 at 7:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.