将坐标从EPSG 3857转换为4326 DotSpatial

Mat*_*one 3 c# epsg dotspatial

我在我的数据库中有EPSG 3857格式的坐标列表.我需要在EPSG 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;
    }
Run Code Online (Sandbox Code Playgroud)

xy数组总是无穷大; 有人能帮我吗?

E-t*_*ier 9

所选答案的 Javascript 版本似乎有一个错误...它总是给我一个比实际应该大 2 倍的答案,所以我最终潜水了 360 而不是 180 (但我承认这里的数学超出了我的专业领域)。

这是工作代码:

  coord3857To4326(coord) {
    
    const e_value = 2.7182818284;
    const X = 20037508.34;
    
    const lat3857 = coord.lat
    const long3857 = coord.lng;
    
    //converting the longitute from epsg 3857 to 4326
    const long4326 = (long3857*180)/X;
    
    //converting the latitude from epsg 3857 to 4326 split in multiple lines for readability        
    let lat4326 = lat3857/(X / 180);
    const exponent = (Math.PI / 180) * lat4326;
    
    lat4326 = Math.atan(Math.pow(e_value, exponent));
    lat4326 = lat4326 / (Math.PI / 360); // Here is the fixed line
    lat4326 = lat4326 - 90;

    return {lat:lat4326, lng:long4326};
    
}
Run Code Online (Sandbox Code Playgroud)

我也成功扭转了它:

  coord4326To3857(coord) {

    const X = 20037508.34;

    let long3857 = (coord.lng * X) / 180;

    let lat3857 = parseFloat(coord.lat) + 90;
    lat3857 = lat3857 * (Math.PI/360);
    lat3857 = Math.tan(lat3857);
    lat3857 = Math.log(lat3857);
    lat3857 = lat3857 / (Math.PI / 180);
    
    lat3857 = (lat3857 * X) / 180;

    return {lat:lat3857, lng:long3857};
}
Run Code Online (Sandbox Code Playgroud)

希望这会帮助其他人!


Mat*_*one 5

最后我找到了一个转换坐标的数学公式.

我在存储过程中实现它,因为我有一个点列表,这个存储过程计算距离.

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

SET @StartLat3857 =(SELECT TOP 1 Latitude FROM Coordinates WHERE IdCoord=@IdCoord ORDER By IdTDFPath ASC)
SET @StartLng3857=(SELECT TOP 1 Longitude FROM Coordinates WHERE IdCoord=@IdCoord 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
Run Code Online (Sandbox Code Playgroud)

  • 你能帮我从 4326 转换回 3857 吗? (2认同)
  • @ABH 您需要使用反转公式来计算坐标。在 C# 中,它将是 `private double[] ConvertCoordinate(double lat, double lng) { double x = lng * 20037508.34 / 180; double y = Math.Log(Math.Tan((90 + lat) * Math.PI / 360)) / (Math.PI / 180); y = y * 20037508.34 / 180;返回新的双 [] { x, y }; }` (2认同)