请记住,我将在lat / long对上执行计算,什么数据类型最适合与MySQL数据库一起使用?
当前回答
虽然它并不是所有操作的最佳选择,但如果你正在制作地图瓷砖或使用只有一个投影的大量标记(点)(例如Mercator,像谷歌Maps和许多其他滑头地图框架),我发现我所谓的“巨大坐标系”真的非常非常方便。基本上,你将x和y像素坐标存储在一些放大的地方——我使用缩放级别23。这有几个好处:
You do the expensive lat/lng to mercator pixel transformation once instead of every time you handle the point Getting the tile coordinate from a record given a zoom level takes one right shift. Getting the pixel coordinate from a record takes one right shift and one bitwise AND. The shifts are so lightweight that it is practical to do them in SQL, which means you can do a DISTINCT to return only one record per pixel location, which will cut down on the number records returned by the backend, which means less processing on the front end.
我在最近的一篇博客文章中谈到了这些: http://blog.webfoot.com/2013/03/12/optimizing-map-tile-generation/
其他回答
MySQL使用double为所有浮点数… 所以使用double类型。在大多数情况下,使用float会导致不可预测的四舍五入值
PostGIS中的空间函数比MySQL中的空间函数更具功能性(即不局限于BBOX操作)。看看:链接文本
FLOAT应该能给你所需的所有精度,并且比将每个坐标存储为字符串或类似的东西更好地用于比较函数。
如果你的MySQL版本低于5.0.3,你可能需要注意某些浮点比较错误。
在MySQL 5.0.3之前,DECIMAL列以精确的精度存储值,因为它们是用字符串表示的,但DECIMAL值的计算是使用浮点操作完成的。从5.0.3开始,MySQL执行DECIMAL操作的精度为64位十进制数字,这应该可以解决DECIMAL列最常见的不准确问题
不需要走太远,根据谷歌地图,最好是FLOAT(10,6)的纬度和液化天然气。
在GIS中使用MySQL的空间扩展。