loicgasser / quantized-mesh-tile

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

Tile parsing error uVertexCount #18

Closed bertt closed 7 years ago

bertt commented 7 years ago

I'm trying to parse a terrain tile with the following code but got an error about uVertexCount. Tile 1608.zip I've checked the Gzip compression. Tile is rendered well in the Cesium viewer.

Code:

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

Stacktrace:

Traceback (most recent call last):
  File "test.py", line 24, in <module>
    ter.fromFile('1608.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

Any idea whats going on?

loicgasser commented 7 years ago

Hi this seems a very similar error to ; https://github.com/loicgasser/quantized-mesh-tile/issues/15

bertt commented 7 years ago

yes looks very similar :-) but in this case got the same error on other OS (Ubuntu) so I suspect its something else.

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/quantized_mesh_tile/terrain.py", line 433, in fromFile
    self.fromStringIO(f, hasLighting=hasLighting, hasWatermask=hasWatermask)
  File "/usr/local/lib/python2.7/dist-packages/quantized_mesh_tile/terrain.py", line 334, in fromStringIO
    unpackEntry(f, TerrainTile.vertexData['uVertexCount'])
  File "/usr/local/lib/python2.7/dist-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

in the attached file the tile coordinates are not the same as in the code sample. 739397 seems to be the value for x.

Are you sure about z,x,y tile coordinates?

bertt commented 7 years ago

yes should be 11,2107,1608. Where did you get the value x=739397 from? I don't see it in the header.

loicgasser commented 7 years ago

I got it from the filename, are those Cesium tile? Where did you get it from? I'll try it out on my machine.

bertt commented 7 years ago

Tiles are produced by running ctb-tile on a tif file, for example http://www.rijkswaterstaat.nl/apps/geoservices/geodata/dmc/ahn2_05_int/geogegevens/raster/01_09/i09bz1.tif

loicgasser commented 7 years ago

That's a heightmap terrain format not quantized mesh (regular triangles)

See: https://github.com/AnalyticalGraphicsInc/cesium/wiki/heightmap-1.0-terrain-format and https://cesiumjs.org/data-and-assets/terrain/formats/quantized-mesh-1.0.html