mapbox / vector-tile-spec

Mapbox Vector Tile specification
https://www.mapbox.com/vector-tiles/specification/
Other
892 stars 210 forks source link

How to store negative deltas in feature.geometry? #14

Closed sgillies closed 10 years ago

sgillies commented 10 years ago

Consider this WKT geometry: LINESTRING (1 1, 0 0). The vector_tile encoding would be [9 1 1 17 -1 -1] (moveto 1,1; lineto 0,0), but negative deltas can't be stored in the geometry field as it's of uint32 type (repeated uint32 geometry = 4 [ packed = true ];).

@springmeyer @kkaefer by "zigzag" do we mean replace all deltas n by (n << 1) ^ (n >> 31) as described in https://developers.google.com/protocol-buffers/docs/encoding? That would give a vector_tile encoding of [9 2 2 17 1 1].

kkaefer commented 10 years ago

Yes, zigzag encoding allows us to store positive and negative values. The specification as uint32 is merely a hint to the decoder; we're putting our own decoding step on top of protobuf's decoding.