使用ProjNet.Silverlight进行ArcGis座标转换(有解决出错问题方法)
使用ProjNet.Silverlight可以将ArcGis中的从标由大地座标转换为经纬座标,代码如下
public List<MapPoint> ConvertTo(List<MapPoint> mps) { CoordinateTransformationFactory ctfac = new CoordinateTransformationFactory(); Point p = new Point(108.94, 34.28); string bj1954Lcc = "PROJCS[\"China_Lambert_Conformal_Conic\",GEOGCS[\"GCS_Beijing_1954\",DATUM[\"D_Beijing_1954\",SPHEROID[\"Krasovsky_1940\",6378245.0,298.3]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Lambert_Conformal_Conic\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",105.0],PARAMETER[\"Standard_Parallel_1\",30.0],PARAMETER[\"Standard_Parallel_2\",62.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0]]"; IProjectedCoordinateSystem fromCS = CoordinateSystemWktReader.Parse(bj1954Lcc) as IProjectedCoordinateSystem; GeographicCoordinateSystem toCS = (GeographicCoordinateSystem)fromCS.GeographicCoordinateSystem; List<MapPoint> list = new List<MapPoint>(); foreach (var mp in mps) { var p1 = new Point(mp.X, mp.Y); var p2 = ctfac.CreateFromCoordinateSystems(fromCS, toCS).MathTransform.Transform(p1); list.Add(new MapPoint(p2.X, p2.Y)); } return list; }
下载ProjNet.Silverlight后在Silverlight中使用是会出一个'p' is not recognized.的错误,找了半天没有解决,最后反编译代码然后跟踪发现原来有一个字符处理时使用的是Encoding是Unicode,在中文的C#中字符串的默认编码是UTF-8,将代码中的Unicode改为UTF-8即可!
需要改的代码在:ProjNet.Converters.WellKnownText.IO.StreamTokenizer类中的
private TokenType NextTokenAny()中!