Python struct and mapscript saveQuery

Ryan, Adam ARyan at CO.LINN.OR.US
Wed Nov 17 20:54:01 EST 2004


Dear List,

This is a picky little question concerning Python struct.pack and unpack
methods, and mapscript saveQuery and loadQuery methods.

I'm using Python Mapscript 4.4.0_beta2 on Windows XP and saving query files
using map.saveQuery().  I subsequently manipulate the saved query file.
When I read the shape, tile and class index values using struct.unpack, the
only format that seems to work is "iib0i", which means two integers and a
signed char aligned at the end to the requirements of three integers, I
think.  The issue is the class index value.  Using "iii" or any other 12
byte format gives me bad class index values.

The byte order is not declared in my format string, so it defaults to native
byte order, size and alignment.  Any declaration of byte order doesn't work
with this format.

Here's the snippet that reads the indexes:
    ...
    for r in range(nr):
        tup = struct.unpack("iib0i",f.read(struct.calcsize("iib0i")))
        print str(tup[0]) + "," + str(tup[1]) + "," + str(tup[2])
    ...

Can anyone tell me why I can't just use "iii"?  I can write query files
using struct.pack("iii",... and mapserver will load them without a problem.
Am I doing something wrong or is there something a little freaky in how
mapserver writes class indexes out to file?

Cheers,

Adam



More information about the mapserver-users mailing list