Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Polygon compression for Integer coordinates

I have polygon in raster with "signed int" 2D coordinates. Polygon has its vertices ordered in clockwise direction.

I want to store this polygon in some more "space friendly" way, that just store the sequence of int x, y coordinates. If I compress this file with rar, I got sizes about 3.5x smaller than uncompressed. Is there any better representation than simply storing x,y in a sequence?

The compression should be lossless.

like image 551
Martin Perry Avatar asked Aug 12 '26 23:08

Martin Perry


1 Answers

If your polygon is (x1, y1), (x2, y2) ... (xn, yn), you can write it as,

x1, x2-x1, x3-x2, xn-xn-1, y1, y2-y1 ..., yn-yn-1

Typically the differences between adjacent x,y values will be smaller than the absolute values, so you can store the deltas as variable length ints. By doing this, each x,y pair can typically be stored in 2 or 4 bytes rather than 8.

like image 50
sbridges Avatar answered Aug 15 '26 05:08

sbridges



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!