博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
通过Map 3D API读取线状要素的节点坐标
阅读量:7051 次
发布时间:2019-06-28

本文共 5520 字,大约阅读时间需要 18 分钟。

By 

在Map 3D中可以使用Create from Geometry命令把AutoCAD实体转换成Map 3D中的FDO要素,比如可以把AutoCAD的polyline转换成FDO线状要素。

对于只包含直线的AutoCAD polyline,在转成FDO要素后,将是一个MgCurveString对象,并且只包含一个LinearSegment。

如果AutoCAD polyine中包含弧Arc, 那转换出来的FDO要素对象,将是一个包含多个segment的MgCurveString对象。其中有Arc Segment也有linear segment。

下面是对这样的线状要素读取坐标点的代码:

using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput; using Autodesk.Gis.Map.Platform.Interop; using Autodesk.Gis.Map.Platform; using OSGeo.MapGuide; // This line is not mandatory, but improves loading performances [assembly: CommandClass(typeof(GetFeatureType.MyCommands))] namespace GetFeatureType {
public class MyCommands {
// Modal Command with localized name [CommandMethod("getPolylineCoordinates")] public void MyCommand() // This method can have any name {
    Editor ed = Autodesk.AutoCAD.ApplicationServices.Application         .DocumentManager.MdiActiveDocument.Editor;     Transaction trans = Autodesk.AutoCAD.ApplicationServices.Application         .DocumentManager.MdiActiveDocument.Database.TransactionManager         .StartTransaction();     using (trans)     {
        // Get the Map Object         AcMapMap currentMap = AcMapMap.GetCurrentMap();         // Prompt user to Select Feature in Map         PromptSelectionOptions psop = new PromptSelectionOptions();         psop.MessageForAdding = "Select the FDO Feature in Map 3D to read Data : ";         psop.SingleOnly = true;         PromptSelectionResult psResult = ed.GetSelection(psop);         if (psResult.Status == PromptStatus.OK)         {
            SelectionSet selSet = psResult.Value;             // Get Map Selectionset from AutoCAD SelectionSet             MgSelectionBase mapSelBase = AcMapFeatureEntityService                 .GetSelection(selSet);             AcMapLayer mapLayer = AcMapFeatureEntityService                 .GetLayer(psResult.Value[0].ObjectId);             //Get the ID of the selected Parcel             MgFeatureReader ftrRdr = mapSelBase.GetSelectedFeatures(                 mapLayer, mapLayer.FeatureClassName, false);             while (ftrRdr.ReadNext())             {
                MgClassDefinition cd = ftrRdr.GetClassDefinition();                 //the geomety property name maybe different for your                 //data source                 MgByteReader byteRdr = ftrRdr.GetGeometry("Geometry");                 MgAgfReaderWriter wtr = new MgAgfReaderWriter();                 MgGeometry geom = wtr.Read(byteRdr);                 if (geom is OSGeo.MapGuide.MgCurveString)                 {
                    var cs = geom as MgCurveString;                     ed.WriteMessage("\n geo is MgCurveString.");                     for (int i = 0, segmentCount = cs.Count; i < segmentCount; i++)                     {
                        var seg = cs.GetSegment(i);                         if (seg is MgArcSegment)                         {
                            ed.WriteMessage("\nthis is an Arc Segment.");                             var arcSeg = seg as MgArcSegment;                             string msg = string.Format(                                 "\nstart point: x= {0}, y={1}",                                 arcSeg.StartCoordinate.X,                                 arcSeg.StartCoordinate.Y);                             ed.WriteMessage(msg);                             msg = string.Format(                                 "\ncontrol point  x= {0}, y={1}",                                 arcSeg.ControlCoordinate.X,                                 arcSeg.ControlCoordinate.Y);                             ed.WriteMessage(msg);                             msg = string.Format(                                 "\nend point: x= {0}, y={1}",                                 arcSeg.EndCoordinate.X,                                 arcSeg.EndCoordinate.Y);                             ed.WriteMessage(msg);                         }                         if (seg is MgLinearSegment)                         {
                            ed.WriteMessage("\nthis is a linear Segment.");                             var linearSeg = seg as MgLinearSegment;                             var interator = linearSeg.GetCoordinates();                             while (interator.MoveNext())                             {
                                var x = interator.GetCurrent().X;                                 var y = interator.GetCurrent().Y;                                 ed.WriteMessage(string.Format(                                     "\n x = {0}, y={1} ", x, y));                             }                         }                     }                 }                 if (geom is OSGeo.MapGuide.MgLineString)                 {
                    var ls = geom as MgLineString;                     var interator = ls.GetCoordinates();                     while (interator.MoveNext())                     {
                        var x = interator.GetCurrent().X;                         var y = interator.GetCurrent().Y;                         ed.WriteMessage(string.Format(                             "\n x = {0}, y={1} ", x, y));                     }                 }             }         }         trans.Commit();     } } } }
 
作者:
邮箱:junqilian@163.com 
出处:  
转载请保留此信息。
本文转自峻祁连. Moving to Cloud/Mobile博客园博客,原文链接:http://www.cnblogs.com/junqilian/p/3836094.html
,如需转载请自行联系原作者
你可能感兴趣的文章
Linux文件内容去重
查看>>
设计模式 之 状态模式
查看>>
Java泛型(一)ArrayList和HashMap
查看>>
redis笔记 (番外篇)——从RDBMS到NoSQL的架构演化及CAP原理
查看>>
iOS中根据已有经纬度定位并显示在地图上
查看>>
Git同时使用多个 ssh key
查看>>
hdu 2501
查看>>
findbugs错误类型对照表
查看>>
Eclipse代码补全,修改 空格键 "=" 键不上屏
查看>>
01背包问题的java界面实现
查看>>
[leetcode] Permutations
查看>>
查看Android应用包名package和入口activity名称
查看>>
jquery disabled设置不可编辑
查看>>
Java Base
查看>>
mysql优化sql语句查询的方法(一)
查看>>
既然存在,就是合理的
查看>>
【GIT-1】GIT 的基础教程 创建,添加,更替,追溯版本库
查看>>
【原创】公司自研缓存系统UPU的总结
查看>>
一个JavaScript的简单通用验证
查看>>
java面试基本数据类型考点
查看>>