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
    转载请保留此信息。
  • 相关阅读:
    bootstrap modal 弹出效果
    集合List内容
    input文本框设置和移除默认值
    jQuery hover事件
    jQuery事件之鼠标事件
    jquery操作select(取值,设置选中)
    JS里设定延时:js中SetInterval与setTimeout用法
    移动端 触摸事件 ontouchstart、ontouchmove、ontouchend、ontouchcancel
    profiler加入计划任务
    sql server 时间小汇
  • 原文地址:https://www.cnblogs.com/junqilian/p/2158329.html
Copyright © 2011-2022 走看看