在Python中存储纬度和经度值的理想数据类型是什么?

2024-04-25 05:29:18 发布

您现在位置:Python中文网/ 问答频道 /正文

在Python中存储纬度和经度值的理想数据类型是什么?以GTFS中的stops.txt为例

stop_lat,stop_lon
48.82694828196076,2.367038433387592
48.82694828196076,2.367038433387592
48.829830695271106,2.376120009344837
48.829830695271106,2.376120009344837
48.83331371557845,2.387299704383512
48.83331371557845,2.387299704383512
48.840542782965464,2.3794094631230687
48.840542782965464,2.3794094631230687
48.844652150982945,2.37310814754528

What is the ideal data type to use when storing latitude / longitudes in a MySQL database?相对应的是:

Use MySQL's spatial extensions with GIS.


Tags: thetxtismysqlwhat数据类型stoplon
3条回答

我假设你需要6个小数位。所以,float会保存你的数据。还是精度设置为6的十进制?在

小数点的小数位数(包括小数点后的2位)可以定义为小数点后两位数(包括小数点)。在

我认为namedtuple是一种方法,很容易通过名称进行访问,并且像tuple一样使用(对于精度使用float):

In[4]: from collections import namedtuple
In[5]: coords = namedtuple("Coords", ['x', 'y'])
In[6]: coords
Out[6]: __main__.Coords
In[7]: coords(1,2)
Out[7]: Coords(x=1, y=2)
In[8]: coords(1.235445,2.2345345)
Out[8]: Coords(x=1.235445, y=2.2345345)
In[9]: coords(1.2354451241234214,2.234534512412414134)
Out[9]: Coords(x=1.2354451241234214, y=2.2345345124124143)

相关问题 更多 >