digidem / osm-p2p-db

Peer-to-peer database for OpenStreetMap data
BSD 2-Clause "Simplified" License
235 stars 25 forks source link

Quantization of lon/lat coordinates #50

Open gmaclennan opened 7 years ago

gmaclennan commented 7 years ago

We should quantize the coordinates to a fixed precision to avoid database bloat and potential floating point rounding errors at the spatial index. Decimal degrees precision:

decimal degree @ 0° Lat @ 30° Lat @ 60° Lat
2 0.01° ~ 1 km ~ 0.9 km ~ 0.5 km
3 0.001° ~ 100 m ~ 90 m ~ 50 m
4 0.0001° ~ 10 m ~ 9 m ~ 5 m
5 0.00001° ~ 1 m ~ 0.9 m ~ 0.5 m
6 0.000001° ~ 0.1 m ~ 0.09 m ~ 0.05 m
7 0.0000001° ~ 0.01 m ~ 0.009 m ~ 0.005 m
8 0.00000001° ~ 0.001 m ~ 0.0009 m ~ 0.0005 m

8 decimal places would get us 1mm precision, I think that's more than enough. The GeoJSON Spec recommends 6 decimal places for <10cm precision. There may be use-cases for greater precision, e.g. drawing precise building footprints. I think 8 decimal places (1mm precision) would be more than enough. Perhaps configurable at a DB level? Would it need to be kept consistent across the whole db?

hackergrrl commented 7 years ago

I think as long as all levels of quantization fit into the chosen datatype in kdb-tree-store it will be fine.