cschwarz / wkx

A WKT/WKB/EWKT/EWKB/TWKB/GeoJSON parser and serializer.
MIT License
316 stars 62 forks source link

Error with WKB parsing #13

Closed YonatanKra closed 8 years ago

YonatanKra commented 8 years ago

Hi, I'm trying to convert geoJson to wkb. It doesn't really work (or I don't know what to do with it...). I do the following: 1) Get GeoJson. 2) Parse it into geometry. 3) Do wkbBuffer = geometry.toWkb(); 4) try to parse the buffer - wkx.Geometry.parse(wkbBuffer); It gives me an error:

jQuery.Deferred exception: Trying to access beyond buffer length RangeError: Trying to access beyond buffer length

Here's the plnkr: https://plnkr.co/edit/4EyqlbUPDyS81sTHMWWt?p=preview

cschwarz commented 8 years ago

Instead of

var wkbBuffer = new Buffer(geometry.toWkb().join(''));

you can either reuse the buffer directly

var wkbBuffer = geometry.toWkb();

or create a copy - but without using join

var wkbBuffer = new Buffer(geometry.toWkb());
YonatanKra commented 8 years ago

Works, thanks :)