UTM WGS84 互相转换

Mercator 投影与 WGS-84坐标系互相转换

简介

WGS84 坐标系 是为GPS全球定位系统使用而建立的坐标系统。
Mercator (墨卡托投影) 是一种地图投影系统,用于为地球表面的位置分配坐标,可以参考别人编制的 UTM Grid,例如中国东部属于 UTM Zone 50N。

代码

引用 ProjNet 库,ProjNet 是 Proj 的 .Net 版本,是一种通用坐标转换软件,可将地理空间坐标从一个坐标参考系统 (CRS) 转换到另一个坐标参考系统。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/// <summary>
/// Transform UTM to WGS84
/// </summary>
/// <param name="points">UTM Easting Northing</param>
/// <param name="zone">UTM zone</param>
/// <param name="north">true of Northern hemisphere, false if southern</param>
/// <returns>WGS84</returns>
private static double[] TransformUtm32ToWgs84(double[] points, int zone = 50, bool north = true)
{
CoordinateTransformationFactory cstFactory = new CoordinateTransformationFactory();
ICoordinateTransformation utm32ToWgs84 = cstFactory.CreateFromCoordinateSystems(
ProjectedCoordinateSystem.WGS84_UTM(zone, north),
GeographicCoordinateSystem.WGS84
);
return utm32ToWgs84.MathTransform.Transform(points);
}

/// <summary>
/// Transform WGS84 to UTM
/// </summary>
/// <param name="points">WGS84 Longitude Latitude</param>
/// <param name="zone">UTM zone</param>
/// <param name="north">true of Northern hemisphere, false if southern</param>
/// <returns>UTM</returns>
private static double[] TransformWgs84ToUtm32(double[] points, int zone = 50, bool north = true)
{
CoordinateTransformationFactory cstFactory = new CoordinateTransformationFactory();
ICoordinateTransformation wgs84ToUtm32 = cstFactory.CreateFromCoordinateSystems(
GeographicCoordinateSystem.WGS84,
ProjectedCoordinateSystem.WGS84_UTM(zone, north)
);
return wgs84ToUtm32.MathTransform.Transform(points);
}

static void Main(string[] args)
{
var output1 = TransformUtm32ToWgs84(new[] { 447617.70449733676, 4429247.0759452293 });
var output2 = TransformWgs84ToUtm32(new[] { 116.386231, 40.011798 });
}