纬度和经度数据类型和存储格式
我看到使用了两种格式,例如: 41.45063 N 和 (N 40°48'27.34")。
我假设: 如果我使用第一种格式,那么我只需要 2 列:十进制、方向
如果我使用第二种格式,那么我需要 4 列:度、分、秒、方向
使用哪种格式存储在数据库中以及如何从一种格式转换为另一种格式。另外,我们是否只存储坐标,甚至是 N、S、E、W 等方向?
我在 MySQL 中使用本地坐标。
I see two formats being used like:
41.45063 N and (N 40°48'27.34").
I assume:
If i use first format then i need only 2 colums: Decimal, Direction
If i use the second format then i need 4 colums: Degree, Minute, Second, Direction
Which format is used to store in the database and how to convert from 1 format to the other. Also are we storing only the cordinates or even the direction like N,S,E,W?
I am using cordinates for local places in MySQL.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以轻松地将第二种格式转换为第一种格式。度有六十分钟,一分钟有六十秒。在您的 40°48′27.34″ 示例中,它是 40 + (48 ∙ 60 + 27.34) / 3600 ≈ 40.807594°。
因此,您需要两列,一列用于经度,一列用于纬度(您知道,您可以将方向编码为数字的符号)。
You can convert the second format into the first trivially. There are sixty minutes in a degree, and sixty seconds in a minute. In your example of 40°48′27.34″ it's 40 + (48 ∙ 60 + 27.34) / 3600 ≈ 40.807594°.
So you need two columns, one for longitude, one for latitude (you know, you can just encode direction into the sign of the number).
40°48'27.34
只是一个浮点数,经过格式化以方便人类使用。除非您的数据表包含“度”、“分”和“秒”字段,否则您无法直接存储“人类”格式。但是,将其存储为单个浮点值41.45063
可以让您根据需要将其重新格式化为人类友好的格式。不需要方向场。您可以假设正数表示北和西,负数表示南/东。
40°48'27.34
is simply a floating point number that's been formatted for easier human consumption. Unless your data table had fields for "degrees", "minutes", and "seconds", you can't store that "human" format directly. However, storing it as a single floating point value of41.45063
lets you reformat it into the human-friendly format on-demand.There's no need for a direction field. You can assume that positive numbers indicate North and West, and negative numbers indicate South/East.
RayHT
您所指的格式称为十进制格式和 DMS(度、分、秒)。有一个直接的函数可以来回转换。只需在 google 中搜索“度数到十进制转换”即可找到您使用的语言(PHP、Javascript 等)。
存储十进制格式时,值的符号指示方向。对于纬度,正值表示北,负值表示南。对于经度,正值是东,负值是西。
这里有一个在线转换器的链接以及对基础知识的描述,您可能会发现它们对于理解其工作原理很有用。
http://www.csgnetwork.com/gpscoordconv.html
安德鲁
“OpenGeoCode.Org”团队的一部分
RayHT
The formats you are are referring to are known as decimal format and DMS (Degrees, Minutes, Seconds). There is a straight forward function for converting back-n-forth. Just google 'Degrees to Decimal conversion' for the language your using (PHP, Javascript, etc).
When storing decimal format, the sign of the value indicates direction. For latitude, positive values are North and negative are South. For Longitude, positive values are East and negative values are West.
Here's a link to an online converter and a description of the basics that you might find useful in undertstanding how this works.
http://www.csgnetwork.com/gpscoordconv.html
Andrew
Part of the "OpenGeoCode.Org" Team