I'm trying to make a C language equivalent to STDistance. Through research, I've narrowed down what STDistance uses, which apparently is the (inverse) Vincenty Formula. The problem is, I've tried comparing a few different pairs of lat-long points in STDistance and using the Vincenty Formula, on here and also using this Python code (with the lat/longs filled in):
import geopy
from geopy.distance import geodesic
point1 = ()
point2 = ()
print(geodesic(point1, point2).km)
And also, I converted STDistance meters to kilometers by dividing the result by 1000. The thing is, once the results get past the 4th decimal point they seem to be completely different. I understand this is relatively negligible, but I'd like to figure out why this is happening. Is the problem related to floating-point errors that happen in SQL Server? Rounding? Or perhaps something else, like a bug?
Here's an example:
Using the two random lat-long points, (35.22229, -119.02138) and (38.148205, -121.0777), here are the results I get.
SQL Server Code:
DECLARE @g geography;
DECLARE @h geography;
SET @g = geography::STGeomFromText('POINT(-119.02138 35.22229)', 4326);
SET @h = geography::STGeomFromText('POINT(-121.0777 38.148205)', 4326);
SELECT @g.STDistance(@h);
Python Code:
import geopy
from geopy.distance import geodesic
point1 = (35.22229, -119.02138)
point2 = (38.148205, -121.0777)
print(geodesic(point1, point2).km)
Now, from SQL Server I get the result, 373073.004092576 (in meters), or in kilometers, 373.073004093. On the other hand, from Python, I get 373.07302837349175 (in kilometers). And then finally, from here (the inverse calculator) I get 373073.028 (in meters), or in kilometers, 373.073028.
Any idea what's happening with this?