[mapserver-dev] Re: MS4W Beta 7 -- Python-Mapscript -- queryByRect strange behavior

Christian Jauvin cjauvin at gmail.com
Sun Nov 8 18:21:32 EST 2009


Following the problem description I posted last week, I have created a
very simple test case: the attached Python script creates first a map
by reading the attached mapfile, and then add five distinct point
features to its only layer. It then performs a queryByRect that
encompasses the whole layer (certain to retrieve the five features)
and prints the results. On a Linux box running Python-MS 5.0, the
results are:

<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x8cf600> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x8d28a0> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x8d2a30> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x8d2c00> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x8d2dd0> >

Five distinct objects, which is what is expected, whereas the same
script running on Windows with the latest version of MS4W (3b7, thus
running Python-MS 5.4), I get:

<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x00B6DB40> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x00B6DAE0> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x00B6DB40> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x00B6DAE0> >
<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at 0x00B6DB40> >

The problem I was describing is apparent here: the five features seem
to be sharing in fact only two different objects (based on their
pointer values).

I am not familiar enough with the bowels of MapServer to be able to
debug this problem by myself, so again, any help would be greatly


On Fri, Nov 6, 2009 at 11:20 AM, Christian Jauvin <cjauvin at gmail.com> wrote:
> Hi everyone,
> I am currently developing a Python-Mapscript based web-mapping
> framework (http://dracones.surveillance.mcgill.ca) that worked very
> well with earlier versions of MS (MS4W < 3 on Windows, and MS ~ 5.2 on
> Linux). This week I started playing with Python 2.6, and so it lead me
> to the latest beta of MS4W, which I read has a version of Python-MS
> built for it. I am currently using the Beta 7.
> I have noticed a strange behavior with the queryByRect function,
> different than what was before: when I programmatically add features
> to a point layer and then try to retrieve a subset of them with
> queryByRect, getNumResults gives the correct number of retrieved
> features, but then the set of shapes returned by
> layer.getFeature(layer.getResult(i).shapeindex) is not right. The best
> way to explain in what way is isn't right is this example: when I
> query for three very distinct features, what I get is this:
>  [<mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at
> 0x01EC71E0> >,
>  <mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at
> 0x01EC71C0> >,
>  <mapscript.shapeObj; proxy of <Swig Object of type 'shapeObj *' at
> 0x01EC71E0> >]
> The first and third objects seem to be the same, according to their
> pointers. No matter what query I try to perform, there is always a
> similar problem occurring: some pointers seem to be pointing to shared
> objects, whereas they shouldn't (at least from what I understand).
> I understand that this problem description may not be terribly helpful
> since it may be hard to reproduce, but since it would take time to
> abstract away the suspicious code in my framework, I thought that I
> would go for the high-level first, in case I am missing something
> obvious.
> Thanks in advance for any help,
> Christian
-------------- next part --------------
from mapscript import *

m = mapObj('querybyrect_problem.map')
layer = m.getLayerByName('point_layer')

def addPoint(layer, x, y):
    pt_shape = shapeObj(MS_SHAPE_POINT)
    pt_shape.index = 0
    line = lineObj()
    line.add(pointObj(x, y))

addPoint(layer, 270000.0, 5030000.0)
addPoint(layer, 270001.0, 5030001.0)
addPoint(layer, 270002.0, 5030002.0)
addPoint(layer, 270003.0, 5030003.0)
addPoint(layer, 270004.0, 5030004.0)

rect = rectObj(200000.0, 5000000.0, 400000.0, 5500000.0)
succ = layer.queryByRect(m, rect)
features = []
if succ == MS_SUCCESS:
    n_res = layer.getNumResults()
    for j in range(n_res):
        res = layer.getResult(j)
        shp = layer.getFeature(res.shapeindex)

for f in features: print f
-------------- next part --------------
A non-text attachment was scrubbed...
Name: querybyrect_problem.map
Type: application/octet-stream
Size: 173 bytes
Desc: not available
Url : http://lists.osgeo.org/pipermail/mapserver-dev/attachments/20091108/dac53431/querybyrect_problem.obj

More information about the mapserver-dev mailing list