November 12, 2012 at 1:40 pm
Hi All,
I am trying to get the distance between 2 points:
DECLARE @g geometry;
DECLARE @h geometry;
SET @g = geometry::STGeomFromText('POINT(-118.262449 34.149837)',4326);
SET @h = geometry::STGeomFromText('POINT(-118.291040 34.255522)',4326);
SELECT @h.STDistance(@g)
Result:0.109848...meter(SRID 4326 uses 'Meter' as a unit of mesurment),which is not correct.I picked these from area where i live and should be around 8-9miles(8.5*1600=13600).Any ideas why?
November 12, 2012 at 2:37 pm
Hi
The issue here is that you are using Geometry for your points rather than Geography. Geometry treats the uses a flat projection and essentially ignores the SRID information, whereas Geography use a spherical projection. So when you used the Geometry the distance is reported in the units defining the points (degrees) rather than meters defined in you projection.
Try
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POINT(-118.262449 34.149837)',4326);
SET @h = geography::STGeomFromText('POINT(-118.291040 34.255522)',4326);
SELECT @h.STDistance(@g)
This should give you a distance of 12015 metres
November 12, 2012 at 3:24 pm
Got it.
Thank you Micky
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply