Python Mapscript :: NameError: global name 'rectObj' is not defined
Sean Gillies
sgillies at FRII.COM
Mon Aug 23 12:05:45 PDT 2004
On Aug 23, 2004, at 12:52 PM, Bill Hudspeth wrote:
> Sean Gillies wrote:
>
>> Bill, I'm cc'ing to the list. More at the bottom ...
>>
>> On Aug 23, 2004, at 12:03 PM, Bill Hudspeth wrote:
>>
>>> Sean Gillies wrote:
>>>
>>>> On Aug 23, 2004, at 10:42 AM, Bill Hudspeth wrote:
>>>>
>>>>> I am trying to create a rectangle object using Python Mapscript as
>>>>> such:
>>>>>
>>>>> prevExtent = rectObj(self.prev_minx, self.prev_miny,
>>>>> self.prev_maxx,
>>>>> self.prev_maxy)
>>>>>
>>>>> and get the following error message:
>>>>>
>>>>> NameError: global name 'rectObj' is not defined
>>>>>
>>>>>
>>>>> I have imported the mapscript module - other mapscript objects are
>>>>> recognized in different calls throughout my code, so that is not
>>>>> the
>>>>> problem.
>>>>>
>>>>> Any other ideas would be greatly appreciated.
>>>>>
>>>>> Thanks, Bill
>>>>>
>>>>
>>>> Bill,
>>>>
>>>> There's two different styles of using mapscript classes
>>>>
>>>> 1. keep mapscript class names inside the 'mapscript' namespace:
>>>>
>>>> import mapscript
>>>> r = mapscript.rectObj()
>>>>
>>>> 2. import names into the global namespace:
>>>>
>>>> from mapscript import rectObj
>>>> r = rectObj()
>>>>
>>>> I don't recommend 'from mapscript import *'.
>>>>
>>>> cheers,
>>>> Sean
>>>>
>>>> --
>>>> Sean Gillies
>>>> sgillies at frii dot com
>>>> http://users.frii.com/sgillies
>>>
>>>
>>> Hi Sean,
>>> Your suggestion above worked, but I am getting a new error message
>>> from the following line of code:
>>>
>>> prevExtent = mapscript.rectObj(self.prev_minx, self.prev_miny,
>>> self.prev_maxx, self.prev_maxy)
>>>
>>> The error message is:
>>>
>>> General error message: invalid bounds
>>>
>>> The variables I pass in for minx, miny, maxx, and maxy do evaluate to
>>> floating point utm boundaries (e.g. 580000.0 3400000.0 250799.0
>>> 4153198.0) - I can print them out to screen.
>>>
>>> Thanks again, Bill
>>>
>>
>> I see in your example values that minx (580000.0) > maxx (250799.0).
>> This is invalid.
>> Did you get them switched up?
>>
>> If you think the error message is unclear, lemme know. I'm always
>> open
>> to suggestions.
>> What version of MapServer are you using?
>>
>> cheers,
>> Sean
>>
>> --
>> Sean Gillies
>> sgillies at frii dot com
>> http://users.frii.com/sgillies
>
> Hi Sean,
>
> I believe that I am deriving the extents attributes from the map file,
> like this:
>
> self.nmMap = mapscript.mapObj(self.data)
> self.default_extent = self.nmMap.extent
>
> self.prev_minx=self.default_extent.minx
> self.prev_maxx=self.default_extent.maxx
> self.prev_miny=self.default_extent.miny
> self.prev_maxy=self.default_extent.maxy
>
> prevExtent = mapscript.rectObj(self.prev_minx, self.prev_miny,
> self.prev_maxx, self.prev_maxy)
>
> Shouldn't the "self.default_extent.minx" entries pull out the correct
> values from the map file?
>
> my map file listing ---> EXTENT 580000 3400000 250799 4153198
>
> Are my attributes in the call to rectObj in the correct order? Am I
> missing something else?
>
> Again, thanks. Bill
>
You are welcome, Bill.
Your map file is incorrect, it should be
EXTENT MINX MINY MAXX MAXY
and satisfy MAXX > MINX and MAXY > MINY
In MapServer 4.3 (CVS), map extents are checked for validity when the
mapfile is loaded. In versions 4.2.2 and previous, there is no checking
and you only get an error once you try to draw or query.
cheers,
Sean
--
Sean Gillies
sgillies at frii dot com
http://users.frii.com/sgillies
More information about the MapServer-users
mailing list