将坐标从EPSG 3857转换为4326 DotSpatial

时间:2016-05-30 10:52:23

标签: c# epsg dotspatial

我的数据库中有EPSG 3857格式的坐标列表。 我需要在EPSG 4326中转换它们 我正在尝试使用DotSpatial,但我的代码总是重新调整Infinity的双数组。

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数组总是无穷大; 有人能帮助我吗?

2 个答案:

答案 0 :(得分:5)

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

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

JsonConvert.SerializeObject(
        toSerialize,
        new JsonSerializerSettings()
        {
          TypeNameHandling = TypeNameHandling.Auto
        });

答案 1 :(得分:1)

EPSG 3857坐标投影到EPSG 4326坐标系有点棘手。 Microsoft建议使用ProjNet4GeoAPI,所以我决定使用它。

https://docs.microsoft.com/en-us/ef/core/modeling/spatial#srid-ignored-during-client-operations

我已经证实它可以在这里工作

http://epsg.io/transform#s_srs=3857&t_srs=4326&x=1530088.9600000&y=5085240.8300000

转换示例:

var x = 1530088.96d;
var y = 5085240.83d;

var epsg3857ProjectedCoordinateSystem = ProjNet.CoordinateSystems.ProjectedCoordinateSystem.WebMercator;
var epsg4326GeographicCoordinateSystem = ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84;

var coordinateTransformationFactory = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
var coordinateTransformation = coordinateTransformationFactory.CreateFromCoordinateSystems(epsg3857ProjectedCoordinateSystem, epsg4326GeographicCoordinateSystem);

var epsg3857Coordinate = new GeoAPI.Geometries.Coordinate(x, y);

var epsg4326Coordinate = coordinateTransformation.MathTransform.Transform(epsg3857Coordinate);