Bearing in mind that I'll be performing calculations on lat / long pairs, what datatype is best suited for use with a MySQL database?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
In a completely different and simpler perspective:
VARCHAR
), E.g.: "-0000.0000001,-0000.000000000000001" (35 length and if a number has more than 7 decimal digits then it gets rounded);google.maps.geometry.poly.containsLocation(latLng, bermudaTrianglePolygon))
This way you don't need to worry about indexing numbers and all the other problems associated with data types that may screw up your coordinates.
Use
DECIMAL(8,6)
for latitude (90 to -90 degrees) andDECIMAL(9,6)
for longitude (180 to -180 degrees). 6 decimal places is fine for most applications. Both should be "signed" to allow for negative values.Based on this wiki article http://en.wikipedia.org/wiki/Decimal_degrees#Accuracy the appropriate data type in MySQL is Decimal(9,6) for storing the longitude and latitude in separate fields.
A
FLOAT
should give you all of the precision you need, and be better for comparison functions than storing each co-ordinate as a string or the like.If your MySQL version is earlier than 5.0.3, you may need to take heed of certain floating point comparison errors however.
The spatial functions in PostGIS are much more functional (i.e. not constrained to BBOX operations) than those in the MySQL spatial functions. Check it out: link text
Depends on the precision that you require.
From: http://mysql.rjweb.org/doc.php/latlng
To summarise:
DOUBLE
.DECIMAL(8,6)/(9,6)
.As of MySQL 5.7, consider using Spatial Data Types (SDT), specifically
POINT
for storing a single coordinate. Prior to 5.7, SDT does not support indexes (with exception of 5.6 when table type is MyISAM).Note:
POINT
class, the order of the arguments for storing coordinates must bePOINT(latitude, longitude)
.ST_Distance
) and determining whether one point is contained within another area (ST_Contains
).