Question

As I it is shown here the value(how many km is) of one degree of longitude decrease as we move to the poles. I need a algorithm for calculating the current km that one degree of longitude is for given point (longitude and latitude).

Thank in advance.

Was it helpful?

Solution

In order to calculate how many meters is the length of longitude and latitude for a specific geographic point, I use the following algorithm:

-- Geograpic Point Cordinates
DECLARE @LATTIDUDE REAL=45
DECLARE @LONGITUDE REAL=45
DECLARE @Distance REAL=10

-- Constants
DECLARE @ConvertionConstant AS FLOAT=2*PI()/360
DECLARE @MetersPerDegree AS FLOAT

DECLARE @LattidueInRadians AS FLOAT=@ConvertionConstant*@LATTIDUDE

DECLARE @LongitudeParameter1 AS FLOAT=111412.84
DECLARE @LongitudeParameter2 AS FLOAT=-93.5 
DECLARE @LongitudeParameter3 AS FLOAT=0.118

SET @MetersPerDegree=(@LongitudeParameter1*COS(@LattidueInRadians))+(@LongitudeParameter2*(COS(3*@LattidueInRadians)))+(@LongitudeParameter3*COS(5*@LattidueInRadians))
DECLARE @LongitudeRangeTemp AS FLOAT=@Distance/(@MetersPerDegree/1000)

-- Results for longitude
SELECT @LongitudeRangeTemp AS DegreesForGivenKM
SELECT @MetersPerDegree    AS MetersPerDegreeOfLongitude

-- Constants
DECLARE @LatitudeParameter1 AS FLOAT=111132.92
DECLARE @LatitudeParameter2 AS FLOAT=-559.82
DECLARE @LatitudeParameter3 AS FLOAT=1.175
DECLARE @LatitudeParameter4 AS FLOAT=-0.0023

-- Results for longitude
SET @MetersPerDegree=(@LatitudeParameter1+(@LatitudeParameter2*COS(2*@LattidueInRadians))+(@LatitudeParameter3*COS(4*@LattidueInRadians))+(@LatitudeParameter4*COS(6*@LattidueInRadians)))
DECLARE @LatitudeRangeTemp AS FLOAT=@Distance/(@MetersPerDegree/1000)
SELECT @LatitudeRangeTemp AS  DegreesForGivenKM
SELECT @MetersPerDegree   AS  MetersPerDegreeOfLatitude

An additional parameter is added for kilometers - the code will calculate how many degrees are are equal to the given kilometers.

You are free to implement the code in function.

OTHER TIPS

This is actually harder than you think, but Google would help with the tricky bits.

However, basically you could use some variation of this:

declare @radius as float;
declare @latitude as float;
declare @circumference float;

set @radius = 6378 -- in km
set @latitude = 0 -- 0 = equator : 90 = pole

set @circumference = 2 * pi() * @radius * cos(radians(@latitude))

select @circumference
select (@circumference / 360) as km
select (@circumference / 360) / 1.609344 as miles

The tricky bits I alluded to are the facts that the Earth is not a geometric sphere, and isn't perfectly flat - but the above is very roughly right, given that you could use much more accurate radius for example.

Edit:

Alternatively, if you have SQL 2008 (or more), you could use the "geography" datatype and the STDistance() function.

declare @p1 geography = geography::STPointFromText('POINT(1 ' + cast(@latitude as varchar(10))+')', 4326)
declare @p2 geography = geography::STPointFromText('POINT(2 ' + cast(@latitude as varchar(10))+')', 4326)

SELECT @p1.STDistance(@p2); -- this is in metres

In the above example, it finds the distance between two points at the same latitude, but at a longitude of 1° and a longitude of 2°.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top