zoukankan      html  css  js  c++  java
  • 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中也适用。

    作者:峻祁连
    邮箱:junqilian@163.com
    出处:http://junqilian.cnblogs.com
    转载请保留此信息。
  • 相关阅读:
    jQuery中.bind() .live() .delegate() .on()的区别
    jq中Deferred对象的使用
    事件捕获和事件冒泡
    exec与match方法的区别
    json的转换操作
    iframe内容自适应高度
    Html:upload
    小米盒子
    APUE读书笔记:关于sigsuspend
    我的C笔记
  • 原文地址:https://www.cnblogs.com/junqilian/p/2158329.html
Copyright © 2011-2022 走看看