0

I'm manipulating mapfiles through mapscript. Setting layer attribute values like the opacity works like this:

$layer = $map->getLayer('layername');
//set an attribute value
$layer->set('opacity', 80);

But now I want to set the data attribute as well, I assumed it functions like this:

$layer = $map->getLayer('layername');
//set an attribute value
$layer->set('data', '/path/to/my/shape/file.shp');

But nothing happens, i.e. an image is constructed but it's empty because no data was inserted.

How can I set the data string?

Thank you

PS: I'm using Mapserver 5.0.3 + Mapscript 4.10

EDIT: I used the map.getLayer() method instead of the getLayerByName method. While testing on the opacity attribute, I had a mapfile with only one layer, so the getLayer('loadlines') did return a (but in this case the last and correct) layer.

1
$layer = $map->getLayerByName('layername');
//set an attribute value
$layer->set('data', '/path/to/my/shape/file.shp');

or

$layer = $map->getLayer('layer_index'); //integer!
//set an attribute value
$layer->set('data', '/path/to/my/shape/file.shp');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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