I'm creating a Google map mashup and am using SQL 2008.
I will have a large number of points on the earth and will want to perform various calculations on them in SQL - such as selecting all points contained within a particular polygone, or select all points within 10km of XY.
I have never used and SQL spatial features before. Should I use the geography
or the geometry
datatype for this?
Most likely you want the geography type since it accounts for the curvature of the earth. Geometry is more for a "flat" view of things. Check out this article for more info http://www.mssqltips.com/tip.asp?tip=1847
You can follow the answer given in PostGIS FAQ
I'm all confused. Which data store should I use geometry or geography?
The geometry and geography types in both databases, PostGIS and SQL Server, follow the same concept, so the answer given in the PostGIS FAQ is applicable to your problem.
Geography is the type that is intended for plotting points on the earth.
If you have a table that stores Google Maps points like this:
then you could fill points in it with this stored procedure:
Then if you want to query for the latitude, longitude and altitude, simply use the following query format: