Oslandia / py3dtiles

:warning: Project migrated to : https://gitlab.com/py3dtiles/py3dtiles :warning:
https://py3dtiles.org
Other
215 stars 76 forks source link

Error at exporting from postgis: struct.error: unpack requires a buffer of 16 bytes #42

Closed tomvantilburg closed 6 years ago

tomvantilburg commented 6 years ago

Wanted to test how it works with getting data from postgis but I receive a struct.error: unpack requires a buffer of 16 bytes

Offence happens here:

    166             for k in range(0, pointNb-1):
    167                 pt = np.array(struct.unpack(bo + pntUnpack, wkb[offset:offset
--> 168                               + pntOffset]), dtype=np.float32)
    169                 offset += pntOffset
    170                 line.append(pt)

As far as I can see psycopg2 returns a memoryview for the ST_AsBinary object from postgres. I've tried to convert this to bytes by using bytes(wkb) but that wouldn't help.

Testing it on the building.wkb file runs without error.

tomvantilburg commented 6 years ago

After a bit more digging I understood that the problem was with the geometry not being a Polyhedral but a PolygonZ (which has a different byte length). Apparently only Polyhedrals are supported. Not sure if this is intentional, but it makes sense. Issue closed.

Jeremy-Gaillard commented 6 years ago

Hi,

We unfortunately support only a small amount of geometry types. However, both polyhedral surfaces and multipolygonsZ are supported. You can easily convert from polygonZ to multipolygonZ using the postgis ST_Multi function.

tomvantilburg commented 6 years ago

Good to know! I saw you are already checking the geometry type in the code. https://github.com/Oslandia/py3dtiles/blob/f55669b2003def0eb699e5fa6e543c579ce1ce82/py3dtiles/wkb_utils.py#L145

You might like to add a small if statement to throw an error message when it's not a polyhedral or multipolyz. Now I was kind of in the dark....