# 快手软件 www.TimeGIS.com

• 随笔 - 63
• 文章 - 1
• 评论 - 11
• 引用 - 0

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

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);

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);

posted on 2012-09-27 18:04 快手软件-TimeGIS-com 阅读(...) 评论(...) 编辑 收藏