loicgasser / quantized-mesh-tile

Quantized-Mesh encoder/decoder and topology builder
MIT License
90 stars 20 forks source link

unpack requires a string argument of length 2? #15

Closed bertt closed 7 years ago

bertt commented 7 years ago

when I run the following code, an error about the unpack method is returned. Any ideas how to fix this?

from quantized_mesh_tile.global_geodetic import GlobalGeodetic
from quantized_mesh_tile.terrain import TerrainTile
geodetic = GlobalGeodetic(True)
[z, x, y] = [9, 533, 383]
[minx, miny, maxx, maxy] = geodetic.TileBounds(x, y, z)
ter = TerrainTile(west=minx, south=miny, east=maxx, north=maxy)
ter.fromFile('9_533_383.terrain')

Error:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    ter.fromFile('9_533_383.terrain')
  File "C:\Python27\lib\site-packages\quantized_mesh_tile\terrain.py", line 433, in fromFile
    self.fromStringIO(f, hasLighting=hasLighting, hasWatermask=hasWatermask)
  File "C:\Python27\lib\site-packages\quantized_mesh_tile\terrain.py", line 334, in fromStringIO
    unpackEntry(f, TerrainTile.vertexData['uVertexCount'])
  File "C:\Python27\lib\site-packages\quantized_mesh_tile\utils.py", line 19, in unpackEntry
    return unpack('<%s' % entry, f.read(calcsize(entry)))[0]
struct.error: unpack requires a string argument of length 2
loicgasser commented 7 years ago

What version of python are you running ?

bertt commented 7 years ago

2.7.13rc1, need to install other version?

loicgasser commented 7 years ago

ok, it should work, did you unzip the file? If you did please attach the file I'll give it a go when I have time.

loicgasser commented 7 years ago

https://quantized-mesh-tile.readthedocs.io/en/latest/terraintile.html#quantized_mesh_tile.terrain.TerrainTile.fromFile also there is an option to do it for you.

bertt commented 7 years ago

I use the file from the testcases (https://github.com/loicgasser/quantized-mesh-tile/blob/master/tests/data/9_533_383.terrain) I think it's not gzipped?

loicgasser commented 7 years ago

Then it's not, probably os related then, I never tried on Windows. :D I'll see what I can do

bertt commented 7 years ago

ok shall it check on other OS too

loicgasser commented 7 years ago

If you can yes would be great.

bertt commented 7 years ago

works allright on my mac (python 2.7.12) :-)

loicgasser commented 7 years ago

if you can find out what causes the issue I'd be glad, I'd like to know as well.

loicgasser commented 7 years ago

great :D

bertt commented 7 years ago

installed python 2.7.12 on windows too but got same error

bertt commented 7 years ago

found it! turns out something was wrong with my testfile... very confusing error message though :-)