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

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

问题描述

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

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

我看到的选项是:

  • IEEE-754 FP 以度或弧度表示
  • 在 32 或 64 位整数中存储为定点值的度数或弧度
  • 将整数范围映射到度数范围:-> deg = (360/2^32)*val
  • 度、分、秒和小数秒以位字段形式存储在 int 中
  • 某种结构.

简单的解决方案 (FP) 的主要缺点是它的分辨率非常不均匀(在英国的某个地方可以以微米为单位进行测量,而在日本则不能).这也有 FP 比较和诸如此类的所有问题.其他选项需要在数据生命周期的不同部分付出额外的努力.(生成、展示、计算等)

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:

顺便说一句:32 位在赤道上为您提供大约 0.3 英寸的 E/W 分辨率.这接近于高级 GPS 设置可以工作的比例(IIRC 在某些模式下它们可以降低到大约 0.5 英寸).

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 如果 32 位均匀分布在地球表面,您可以在一边索引大约 344m 的正方形,5 字节给出 21m,6B->1.3m 和 8B->5mm.

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.

推荐答案

最简单的方法就是将其存储为浮点数/双精度数(以度为单位).N 和 E 为正,S 和 W 为负.请记住,分钟和秒是 60(因此 31 45'N 是 31.75).通过查看它们很容易理解这些值是什么,并且在必要时转换为弧度是微不足道的.

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.

纬度和经度的计算,例如两个之间的大圆距离坐标严重依赖三角函数,通常使用双精度.任何其他格式都将至少依赖于正弦、余弦、atan2 和平方根的另一种实现.任意精度数字(例如 Java 中的 BigDecimal)对此不起作用.像 2^32 均匀分布的 int 之类的东西也会有类似的问题.

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天全站免登陆