Map3D/MapGuide API中如何计算两点间的距离?
下面代码演示了Map 3D API中如何计算两点间的地球大圆距离和欧几里得距离,直接看代码:
[CommandMethod("ComputeDistance")] public void ComputeDistance() { double x1 = -87.7104750022991; double y1 = 43.7017449116101; double x2 = -87.703061972587; double y2 = 43.7016702994388; Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; //Get coordinate system of current map AcMapMap currentMap = AcMapMap.GetCurrentMap(); string srsWkt = currentMap.GetMapSRS(); //ed.WriteMessage("srs = " + srsWkt + "\n"); MgCoordinateSystemFactory coordSysFactory = new MgCoordinateSystemFactory(); MgCoordinateSystem coordSys = coordSysFactory.Create(srsWkt); //compute gread circle distance double distance = coordSys.MeasureGreatCircleDistance(x1, y1, x2, y2); distance = coordSys.ConvertCoordinateSystemUnitsToMeters(distance); ed.WriteMessage("gread circle dist = " + distance.ToString() + "\n"); //compute Euclidean distance distance = coordSys.MeasureEuclideanDistance(x1, y1, x2, y2); distance = coordSys.ConvertCoordinateSystemUnitsToMeters(distance); ed.WriteMessage("Euclidean distance = " + distance.ToString() + "\n"); //Another method, compute the distance from Newyork to Boston MgCoordinateSystemMeasure coordSysMeasure = coordSys.GetMeasure(); double dist = coordSysMeasure.GetDistance(-74.806394, 40.714169, -71.061342, 42.355892); dist = coordSys.ConvertCoordinateSystemUnitsToMeters(dist); ed.WriteMessage(" distance = " + dist.ToString() + "\n"); }核心代码在MapGuide中也适用。
