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. CSS好看的按钮

    好看的按钮 <style> .btn { BORDER-RIGHT: #7b9ebd 1px solid; PADDING-RIGHT: 2px; BORDER-TOP: #7b9ebd ...

  2. java字符编码和oracle乱码

    编码问题我仍旧没搞懂,最根本的从哪里来就没搞懂.当页面发送请求,编码到后台是什么编码呢?好吧,我默认的都是utf-8.后台接收参数后,可以在控制台打印出来,我也不清楚是什么编码.然后,就是数据库问题. ...

  3. golang内存分配

    golang内存分配 new一个对象的时候,入口函数是malloc.go中的newobject函数 func newobject(typ *_type) unsafe.Pointer { flags ...

  4. LeetCode - Triangle

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...

  5. 【转载】HttpWebRequest开启gzip压缩简介

    在用HttpWebRequest对象时,一般我们都没有开启gzip压缩,如果服务端返回的数据比较大,这是我们需要开启gzip压缩,怎么开启呢? 1.给HttpWebRequest对象,添加如下Head ...

  6. WCF快速上手

    需求:在同一台机子上,有一个B/S程序,和一个C/S程序(不要问为什么,事实就是这样),B/S程序需要主动和C/S程序通信(C/S程序主动与B/S程序通信的情况这里暂不讨论). 下面以最快的速度写一个 ...

  7. winform自定义日期控件,要求可以手动输入日期DatePicker

    要求:文本框中能手动输入数字,向上箭头根据鼠标位置给年月日递增,向下箭头递减 一:页面加载时: private void FlatDatePicker_Load(object sender, Even ...

  8. 模式的混合-我們真的需要一次一次的讀配置嗎-MultitonPrototypeFactoryMethod

    我們真的需要一次一次的讀配置嗎 通過配置文件,我們其實極大地優化了代碼的結構,很多易變的元素都可以通過配置來修訂. 配置文件是一個文件,那麼使用的時候不可避免的涉及到IO操作. 在內存不值錢的今天,我 ...

  9. 【C#进阶系列】14 字符、字符串和文本编码

    本来写了蛮多的,结果因为重启了一下机器导致写的东西都没了. 然后再回想之前写了什么,反而更像是把知识提炼了一番. 关于字符 字符什么的只要记住.net里面都用的Unicode编码就好.字符和数字之间转 ...

  10. sql 指定值排序

    --SELECT [ButtonName] as text,[FunctionName] as handler,[iconCls] --FROM [ButtonTable] where PKID in ...