I have two points and I have to calculate difference between them.
I using below query in SQL Server.
SELECT geography::Point(27.185425, 88.124582, 4326)
.STDistance(geography::Point(27.1854258, 88.124500, 4326));
Its running fine and result is :
8.12599260290125
Now with same point when I am running below query in PostgreSQL.
SELECT ST_Distance(ST_GeomFromText('POINT(27.185425 88.124582)',4326),
ST_GeomFromText('POINT(27.1854258 88.124500)', 4326));
and Now result is :
8.20039023523232
Can anyone tell me why there is difference in results when calculating distance between two points?
Best Answer
A couple of things that have caught you out here.
In the SQL Server version using the Point, the order of the coordinate is Lat Lon, eg Y X. The OGC Point construct is X Y or Lon Lat.
The next is that the PostGIS query you've posted actually returns
8.20039023523232e-005
which while appearing similar to the SQL Server result, is quite a lot smaller.The last issue is that the PostGIS query is treating the objects as Geometries and doing a cartesian distance on them. You need to explicitly make them Geographies.
Here's a few ways to do the PostGIS query. I've swapped the coordinate order