javascript - 将坐标从 EPSG 3857 转换为 4326

标签 javascript c# coordinates epsg

我的数据库中有一个 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;
    }

xy 数组总是包含无穷大; 有人可以帮助我吗?

最佳答案

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

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

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

最后只是一个可以在所有语言中使用的数学公式。例如是 Javascript 它将是

const e = 2.7182818284
const X = 20037508.34

const lat3857 = 1743704.947843 
const long3857 = 16978473.105100

//converting the logitute from epsg 3857 to 4326
const long4326 = (lat3857*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(e ** exponent)
lat4326 = lat4326 / (Math.PI / 360)
lat4326 = lat4326 - 90

关于javascript - 将坐标从 EPSG 3857 转换为 4326,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37523872/

相关文章:

javascript - 如何检查数组中是否存在某个数字?

从坐标确定矩形的算法

java - 将点从坐标系(0,800)转换为坐标系(50,-50)jFrame<->opengl

javascript - 使用jquery ajax跨域检索json数据

javascript - 借助 JS/Jquery 函数通过 URL 加载 youtube 视频

javascript - 如何删除 Material 设计中的所有 css 类和 js,以获得默认选择框

c# - 这种使用泛型的模式有名称吗?

c# - 如何在没有临时文件的情况下将文件从 Windows 窗体(listView)拖放到桌面(任何资源管理器窗口)

javascript - Jquery将表格导出到csv隐藏表格单元格

javascript - 检查直线两点之间是否存在坐标