适合/最佳类型用于存储纬度和经度 [英] proper/best type for storing latitude and longitude

查看:168
本文介绍了适合/最佳类型用于存储纬度和经度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在C,C ++或D等系统级编程语言中,存储纬度和经度的最佳类型/编码是什么?




  • IEEE-754 FP作为度数或弧度

  • 度或弧度存储为固定值在整数范围的32或64位int

  • 映射到度数范围: - > deg =(360/2 ^ 32)* val

  • 在int

  • 某种结构中存储的位字段的度数,分钟,秒和小数秒。 >


简单的解决方案(FP)具有高度非均匀分辨率的主要缺点(英国某处可以以微米为单位测量,日本,不行)。此外,这还有FP比较的所有问题。其他选项在数据的生命周期的不同部分需要额外的努力。 (生成,演示,计算等)



一个有趣的选项是一种浮动精度类型,其中,纬度增加时,它会获得更多的位,经度越小(因为它们



相关问题不太明确:








BTW:32位给您赤道的E / W分辨率约为0.3英寸。这接近于高级GPS设置的尺度可以在(IIRC他们可以在一些模式下降到约0.5)。



如果32位均匀分布在地球表面上,OTOH可以索引正方形在一侧约344m,5字节给予21m,6B - > 1.3m和8B-> 5mm。



我现在没有一个具体的用法,但是以前一直在使用这种事情,并期望再次

解决方案

最简单的方法就是把它保存为一个浮点数/双倍的度数。对于N和E而言,对于S和W是负的。只要记住,分钟和秒是60(因此31 45'N是31.75)。它很容易理解价值观是什么,通过查看它们,并在必要时转换为弧度是微不足道的。



计算纬度和经度,如美妙的圈子两个坐标之间的距离很大程度上依赖于三角函数,通常使用双精度函数。任何其他格式将至少依赖于正弦,余弦,atan2和平方根的另一个实现。任意精度数字(例如Java中的BigDecimal)将无法正常工作。像2 ^ 32一样传播的东西就会有类似的问题。



几个评论中出现了一致的观点。在这一点上,我只会注意到地球在经度方面是不统一的。在北极圈的一个弧度经度距离比赤道距离更短。双精度浮球在地球上的任何地方都能提供亚毫米精度。这还不够吗?如果没有,为什么不这样做?



同样值得注意的是,您需要对该信息做什么,因为您需要的计算类型将会影响到什么存储您使用的格式。


In a system level programming language like C, C++ or D, what is the best type/encoding for storing latitude and longitude?

The options I see are:

  • IEEE-754 FP as degrees or radians
  • degrees or radians stored as a fixed point value in an 32 or 64 bit int
  • mapping of an integer range to the degree range: -> deg = (360/2^32)*val
  • degrees, minutes, seconds and fractional seconds stored as bit fields in an int
  • a struct of some kind.

The easy solution (FP) has the major down side that it has highly non uniform resolution (somewhere in England it can measure in microns, over in Japan, it can't). Also this has all the issues of FP comparison and whatnot. The other options require extra effort in different parts of the data's life cycle. (generation, presentation, calculations etc.)

One interesting option is a floating precision type that where as the Latitude increase it gets more bits and the Longitude gets less (as they get closer together towards the poles).

Related questions that don't quite cover this:


BTW: 32 bits gives you an E/W resolution at the equator of about 0.3 in. This is close to the scale that high grade GPS setups can work at (IIRC they can get down to about 0.5 in in some modes).

OTOH if the 32 bits is uniformly distributed over the earth's surface, you can index squares of about 344m on a side, 5 Bytes give 21m, 6B->1.3m and 8B->5mm.

I don't have a specific use in mind right now but have worked with this kind of thing before and expect to again, at some point.

解决方案

The easiest way is just to store it as a float/double in degrees. Positive for N and E, negative for S and W. Just remember that minutes and seconds are out of 60 (so 31 45'N is 31.75). Its easy to understand what the values are by looking at them and, where necessary, conversion to radians is trivial.

Calculations on latitudes and longitudes such as the Great Circle distance between two coordinates rely heavily on trigonometric functions, which typically use doubles. Any other format is going to rely on another implementation of sine, cosine, atan2 and square root, at a minimum. Arbitrary precision numbers (eg BigDecimal in Java) won't work for this. Something like the int where 2^32 is spread uniformly is going to have similar issues.

The point of uniformity has come up in several comments. On this I shall simply note that the Earth, with respect to longitude, isn't uniform. One arc-second longitude at the Arctic Circle is a shorter distance than at the Equator. Double precision floats give sub-millimetre precision anywhere on Earth. Is this not sufficient? If not, why not?

It'd also be worth noting what you want to do with that information as the types of calculations you require will have an impact on what storage format you use.

这篇关于适合/最佳类型用于存储纬度和经度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆