A friend recently emailed me after trying out the new
spatial stuff in Katmai asking why the distance from Beaverton to Boston was 51,
and any way 51 what.
On looking at his code I realised he had used the Geometry type and not the
Geography type. The former is used to work on a single planar surface measured
in x and y. The latter is for doing spatial stuff on spheres i.e. the earth.
He had passed the longitude and latitude to the geometry type and done a
STDistance call to find the distance. Even though he had speciifed a spatial
reference for WGS84 the answer came back as 51. Which was simply the hypotenuse
of the triangle using straight forward pythagorus.
The Spatial reference only applies when using the Geography data type which
deals with the elipitcal word. So why do we need spatial references anyway. Well
they define the world in which you are working, i.e. what is 0, how big is the
world etc, and what unit of measure is to be used.
If you want a nice explanation of spatial references have a read of the
Mortens post here http://www.sharpgis.net/2007/05/05/SpatialReferencesCoordinateSystemsProjectionsDatumsEllipsoidsConfusing.aspx
This might be confusing and you may ask why do we need it for the Geometry
type. The key is the unit of measure, If I take some spatial data describing a
house from the UK over to building site in America and combine the data if I
don't have the data stamped with a spatial reference I will end up in all sorts
of mess. Why?
Units of measure.
If I measure something in feet and inches and then cobine with measurements
in metres. Without knowing they are using different measurements I will end up
with the wrong result. Thats why in SQL if you compare or perform an
operation on two geometry (or geography) values with different spatial
references (SRID) you will end up with a NULL answer.
It would have been nice for the types have been able to convert between
the Spatial References for at least the geometry types.