[mapserver-users] Getting introduced to MapScript

Luís de Sousa luis.a.de.sousa at gmail.com
Tue Aug 7 07:33:44 PDT 2012


On 3 August 2012 13:34, Cristiano Sumariva <sumariva at gmail.com> wrote:
> You can set the type and data attributes directly, in fact you need do that
> for the layerobj works properly.
> After you create the layerobj you need set those attributes directly.
>
> How to set them depends on language you use.
> With PHP Mapscript you can do this ( that would be similar to other
> languages ):
> $layer = ms_newLayerObj( mapOwner );
> // here the weird thing the layerObj constructor did not set the layer type
> not even required it to initialize the layerobj.
> $layer->set( 'type', MS_LAYER_POLYGON );
> $layer->set( 'data', '/absolute/or/../relative/toyourfile.gml' );
>

Dear Cristiano, thank you for the reply. As you can see below, the set
method is raising exceptions when I invoke it the way you suggest.
Apparently, attributes like NAME or SHAPEPATH are unknown to
MapScript. This was run directly in the Python console.

Any other suggestions are welcome. Thank you,

Luís

>>> from mapscript import *
>>> mapObj = mapObj()
>>> mapObj.setExtent(91979,436326,92617,437659.5)
0
>>> mapObj.setProjection("epsg:28992")
0
>>> newLayer = layerObj(mapObj)
>>> newLayer.setMetaData("DESCRIPTION", "MyLayer")
0
>>> newLayer.setMetaData("ows_title", "MyLayer")
0
>>> newLayer.set("NAME", "MyLayer")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/MapScript-6.0.1-py2.7-linux-x86_64.egg/mapscript.py",
line 1192, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, layerObj, name)
  File "/usr/local/lib/python2.7/dist-packages/MapScript-6.0.1-py2.7-linux-x86_64.egg/mapscript.py",
line 34, in _swig_getattr
    raise AttributeError,name
AttributeError: set
NameError: name 'self' is not defined
>>> mapObj.set("SHAPEPATH", "/tmp/shapes")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/MapScript-6.0.1-py2.7-linux-x86_64.egg/mapscript.py",
line 1434, in <lambda>
    __getattr__ = lambda self, name: _swig_getattr(self, mapObj, name)
  File "/usr/local/lib/python2.7/dist-packages/MapScript-6.0.1-py2.7-linux-x86_64.egg/mapscript.py",
line 34, in _swig_getattr
    raise AttributeError,name
AttributeError: set
>>>



More information about the MapServer-users mailing list