3

Following a few online tutorials I have seen, I am trying to create a mapfile from scratch using mapscript. However, when I try to create the layer object, I get an error in the init of mapscript.py; NameError: global name 'args' is not defined.

Does anyone see something obvious? When I use a mapfile that already exists on disk, everything works as expected.

 # create a new mapfile from scratch
 self.map = mapscript.mapObj()
 self.map.save('temp.map')
 self.map.setSize(256,256)
 self.map.setExtent(-180.0,-90.0,180.0,90.0)
 self.map.units= mapscript.MS_DD
 self.map.imagecolor.setRGB(255,255,255)
 # create a layer for the raster
 self.layer = mapscript.layerObj(self.map) ----> ERROR HAPPENS HERE
 self.layer.name= 'tilesource'
 self.layer.type= mapscript.MS_RASTER
 self.layer.status = mapscript.MS_ON
 self.layer.data= rasterpath
underdark
84.9k22 gold badges237 silver badges418 bronze badges
asked Apr 19, 2011 at 19:40
1
  • Was this resolved somehow? I'm getting the same error. Commented May 24, 2011 at 7:58

3 Answers 3

3

According to http://mapserver.org/mapscript/mapfile.html, creating a layer object works differently:

test_map = new mapscript.mapObj()
new_layer = new mapscript.layerObj()
li = test_map.insertLayer(new_layer)
answered Apr 19, 2011 at 20:17
6
  • Thanks for the suggestion, still get the same error with this approach. Commented Apr 20, 2011 at 11:52
  • Can you post the whole script? I can't see where it gets "global name 'args'" from. Commented Apr 20, 2011 at 11:53
  • The error is happening in mapscript.py, the SWIG generated wrapper. Its occurring in the init function at Line 1264. Do you want me to attach the mapscript.py file? Commented Apr 20, 2011 at 13:38
  • So "new mapscript.layerObj()" produces the same error like "mapscript.layerObj(self.map)"? (Notice keyword "new".) Which version of Mapserver are you running? Commented Apr 20, 2011 at 17:37
  • 1
    The new keyword isn't required for Python. These seem to be left over from the PHP examples. Commented Jul 4, 2011 at 20:54
3

I am a mapserver developer and I have just committed a patch that should solve this issue. See changeset r12309 for the details.

answered Aug 11, 2011 at 10:49
0
1

I've been having the same problem when trying to create a new CLASS object. I've logged it as a bug as the SWIG wrappers seem incorrect for both layerObj and classObj. The args variable is defined in neither:

def __init__(self, map = None): 
 this = _mapscript.new_layerObj(map)
 try: self.this.append(this)
 except: self.this = this
 if 1:
 if args and len(args)!=0:
 self.p_map=args[0]
 else:
 self.p_map=None

http://trac.osgeo.org/mapserver/ticket/3940

Using MapServer 6.0 and Python SWIG bindings version 1.3.39

answered Jul 4, 2011 at 20:52

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.