mapbox / geobuf

A compact binary encoding for geographic data.
ISC License
967 stars 84 forks source link

Can't encode large integer attributes #87

Open e-n-f opened 6 years ago

e-n-f commented 6 years ago

json2geobuf exits with this error:

/usr/local/lib/node_modules/geobuf/node_modules/pbf/index.js:429
        throw new Error('Given varint doesn\'t fit into 10 bytes');

when given this input (the overflow test from Tippecanoe):

{"type":"FeatureCollection","features":[
{"type":"Feature","properties":{"excess":2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":22e291},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":2.5},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":2147483648},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-2147483648},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":2147483647},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-2147483647},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":18446744073709551616},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-18446744073709551616},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":18446744073709551615},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-18446744073709551615},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":9223372036854775808},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-9223372036854775808},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":9223372036854775807},"geometry":{"type":"Point","coordinates":[0,0]}}
,
{"type":"Feature","properties":{"excess":-9223372036854775807},"geometry":{"type":"Point","coordinates":[0,0]}}
]}
mourner commented 6 years ago

Is geobuf expected to support numbers like this? It's at least 3 orders of magnitude bigger than Number.MAX_SAFE_INTEGER.

e-n-f commented 6 years ago

I don't know. It works with the vector tile format, which supports 64-bit signed and unsigned integers, which is what I was trying to test here, but isn't going to be comfortable for anything like JavaScript that wants everything to be doubles. I would have expected it to get rounded to the nearest double instead of giving an error.