By Daniel Du

在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();
    } } } }
												

通过Map 3D API读取线状要素的节点坐标的更多相关文章

  1. Civil 3D API二次开发学习指南

    Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...

  2. File API 读取上传的文件

    1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...

  3. 使用google map v3 api 开发地图服务

    Google Map V3 API 学习地址: http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/article ...

  4. 申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)

    申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)具体步骤如下:                                                     ...

  5. Google Map JavaScript API V3 实例大全

    Google Map JavaScript API V3 实例大全 基础知识 简单的例子 地理位置 语言 位置 坐标 简单的投影 事件 简单事件 关闭事件 多次添加事件 事件属性 控制 php禁用ui ...

  6. google map android api v2

    我在这主要列举几个需要注意的问题: 1.需要注意使用的api版本的问题,例如google map android api v1就和v2差别很大,包括申请key方面,所以在搜索资料的时候一定注意版本问题 ...

  7. Libgdx New 3D API 教程之 -- Libgdx中使用Materials

    This blog is a chinese version of xoppa's Libgdx new 3D api tutorial. For English version, please re ...

  8. HTML5 file api读取文件的MD5码工具

    1.工具的用途:用HTML5 file api读取文件的MD5码.MD5码在文件的唯一性识别上有很重要的应用,业内常用MD5进行文件识别.文件秒传.文件安全性检查等: 2.适用性:IE.Chrome皆 ...

  9. Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法

    先说一下 Map V2 API Key 的问题吧: 在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的K ...

随机推荐

  1. 初探JavaScript(三)——JS带我"碰壁"带我飞

    已经写了两篇关于小白的JavaScript之行,不可否认,每一种语言都有其精华与糟粕之处,来不及细细体味其精华奥妙,也没法对其评头论足,只能先了解,后深入.到目前为止已经看完<JavaScrip ...

  2. [C] C语言中的布尔值

    C不具备显示的布尔类型,所以使用整数来代替,规则是:零是假,任何非零值皆为真. 反过来说,如果逻辑表达式为真其值一定为真,若逻辑表达式为假其值一定为零.

  3. JavaScript之旅(DOM)

    JavaScript之旅(DOM) [TOC] 一.认识DOM 什么是 DOM? DOM 是 Document Object Model(文档对象模型)的缩写. DOM 是 W3C(万维网联盟)的标准 ...

  4. javascript时间戳和日期字符串相互转换

    <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="C ...

  5. php面向对象常见的专业术语

    类 − 定义了一件事物的抽象特点.类的定义包含了数据的形式以及对数据的操作. 对象 − 是类的实例. 成员变量 − 定义在类内部的变量.该变量的值对外是不可见的,但是可以通过成员函数访问,在类被实例化 ...

  6. jquery的promise实践--连续加载图片

    在javascript设计模式实践之代理模式--图片预加载中用代理模式实现了图片预加载功能. 现在就更进一步,完成一个能够一张一张的连续图片加载的功能. 功能: 1.一张一张加载图片. 2.加载错误, ...

  7. Entity Framework 实体框架的形成之旅--Code First的框架设计(5)

    在前面几篇介绍了Entity Framework 实体框架的形成过程,整体框架主要是基于Database First的方式构建,也就是利用EDMX文件的映射关系,构建表与表之间的关系,这种模式弹性好, ...

  8. HoverTree系统源码介绍

    HoverTree是一个开源asp.net系统.系统的效果请到:http://hovertree.com体验. 源码描述:一.源码特点采用典型的三层架构进行开发,实现了留言板的功能,后台管理,留言审核 ...

  9. MongoDB在实际项目中的使用

    MongoDB简介 MongoDB是近些年来流行起来的NoSql的代表,和传统数据库最大的区别是支持文档型数据库. 当然,现在的一些数据库通过自定义复合类型,可变长数组等手段也可以模拟文档型数据库. ...

  10. CodeSmith连接Oracle

    Win7上仅安装了Oracle32位客户端,此时CodeSmith无法连接Oracle数据库. 解决方法一:如果同一台电脑安装了Oracle64位数据库,这样CodeSmith可以连接数据库. 解决方 ...