www.TimeGIS.com

时空地图 www.TimeGIS.com

交互式图形化建模仿真软件开发

导航

地理坐标转换的C#实现 - Xian1980, BeiJing 1954, WGS84

在编写地图相关的软件时,经常碰到的问题就是坐标转换,

我们可以用ArcGIS的功能实现,也有学测绘的人专门写了程序来转换

如果你要在自己的系统中实现这个功能,

比如说,得到一个arcgis shp 文件,它的坐标系是西安1980, 北京1954,你需要把坐标转为WGS84,并在Google Map上显示出来,

开源软件 http://projnet.codeplex.com/http://dotspatial.codeplex.com/ 可能是你的选择,

在他们的网站上你可以找到他们为何要写这些功能的原因和出处。

初学者们可能需要去搜索一下 “西安1980, 北京1954”

 

下面是具体步骤:

 

首先你需要从网站下载编译好的DLL, 

 

在Proj.NET里面你需要

using ProjNet.CoordinateSystems;
using ProjNet.Converters.WellKnownText;
using ProjNet.CoordinateSystems.Transformations;

 

CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory();

string wktUtm30 = "PROJCS[\"UTM-30\",GEOGCS[\"Unused\",DATUM[\"UTM Projections\",SPHEROID[\"WGS 1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",500000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-3],PARAMETER[\"Scale_Factor\",0.9996],PARAMETER[\"Latitude_Of_Origin\",0],UNIT[\"Meter\",1]]";
ICoordinateSystem cs1 = CoordinateSystemWktReader.Parse(wktUtm30) as ICoordinateSystem;
ICoordinateSystem cs2 = GeographicCoordinateSystem.WGS84;
ICoordinateTransformation trans = ctfac.CreateFromCoordinateSystems(cs1, cs2);

double[] fromPoint = new double[] { 37270, 76370 };
double[] toPoint = trans.MathTransform.Transform(fromPoint);

 

然而在中国普遍使用的 西安1980, 北京1954,这个Proj.NET不支持高斯-克鲁格投影,只好尝试另外一个。

 

using DotSpatial.Projections;

 

//Proj4js.defs["EPSG:2414"] = "+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=krass +units=m +no_defs";
//Sets up a array to contain the x and y coordinates
double[] xy = new double[2];
xy[0] = 39079460;
xy[1] = 3335377;
//An array for the z coordinate
double[] z = new double[1];
z[0] = 1;

ProjectionInfo pStart = KnownCoordinateSystems.Projected.GausKrugerBeijing1954.Beijing19543DegreeGKZone38;
string s = pStart.ToEsriString();
string t = pStart.ToProj4String();

string wktbj1954 = "PROJCS[\"Beijing_1954_3_Degree_GK_Zone_38\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",SPHEROID[\"Krasovsky_1940\",6378245.0,298.3]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Gauss_Kruger\"],PARAMETER[\"False_Easting\",38500000.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",114.0],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]";
ProjectionInfo pStart2 = ProjectionInfo.FromEsriString(wktbj1954);

//.FromProj4String("+proj=tmerc +lat_0=0 +lon_0=114 +k=1 +x_0=38500000 +y_0=0 +ellps=krass +units=m +no_defs");                  

ProjectionInfo pEnd = KnownCoordinateSystems.Geographic.World.WGS1984;

//Calls the reproject function that will transform the input location to the output locaiton
Reproject.ReprojectPoints(xy, z, pStart2, pEnd, 0, 1);

xy[0] = 120;
xy[1] = 30;
Reproject.ReprojectPoints(xy, z, pEnd, pStart, 0, 1);

 

经过测试,满足我的需求。

这样的话,只要用DotSpatial这个就可以了,暂时放弃使用Proj.NET. 希望给同行有参考意义。

 

快手软件: http://www.kuaishou.net/

 

 

 

posted on 2012-09-27 18:04  时空地图-TimeGIS-com  阅读(4017)  评论(0编辑  收藏  举报

www.TimeGIS.com