2016-05-30 436 views
1

我在我的數據庫中有EPSG 3857格式的座標列表。 我需要將它們轉換爲EPSG 4326 我試圖使用DotSpatial,但我的代碼總是重新編譯一個雙無限數組。將座標從EPSG 3857轉換爲4326 DotSpatial

public double[] ConvertCoodinates() 
    { 
     double[] xy = new double[2]; 
     xy[0] = 5085240.8300000000; 
     xy[1] = 1530088.9600000000; 
    //An array for the z coordinate 
     double[] z = new double[1]; 
     z[0] = 0; 
     ProjectionInfo pStart = KnownCoordinateSystems.Geographic.World.WGS1984; 
     pStart.AuthorityCode = 3857; 
     ProjectionInfo pEnd = KnownCoordinateSystems.Geographic.World.WGS1984; 
     pEnd.AuthorityCode = 4326; 
     Reproject.ReprojectPoints(xy, z, pStart, pEnd, 0, 1); 
     return xy; 
    } 

xy數組總是合計無窮大; 有人可以幫我嗎?

回答

1

最後我找到了一個數學公式來轉換座標。

我在存儲過程中實現它,因爲我有一個點列表,並且此存儲過程計算距離。

DECLARE @e FLOAT=2.7182818284 
DECLARE @X DECIMAL(18,2) =20037508.34 

SET @StartLat3857 =(SELECT TOP 1 Latitude FROM Coordinates WHERE [email protected] ORDER By IdTDFPath ASC) 
SET @StartLng3857=(SELECT TOP 1 Longitude FROM Coordinates WHERE [email protected] ORDER By IdTDFPath ASC) 

--converting the logitute from epsg 3857 to 4326 
      SET @StartLng=(@StartLng3857*180)/@X 

--converting the latitude from epsg 3857 to 4326 
      SET @StartLat = @StartLat3857/(@X/180) 
      SET @StartLat = ((ATAN(POWER(@e,((PI()/180)*@StartLat))))/(PI()/360))-90 
+0

你能幫助我從4326轉換回3857嗎? – ABH

+0

@ABH您需要使用反轉公式來計算座標。 在c#中將會是 'private double [] ConvertCoordinate(double lat,double lng) { double x = lng * 20037508.34/180; (Math.Tan((90 + lat)* Math.PI/360))/(Math.PI/180); y = y * 20037508.34/180; 返回新的double [] {x,y}; }' –