通过Map 3D API读取线状要素的节点坐标

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读取线状要素的节点坐标

时间: 2024-11-11 15:29:19

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

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

Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开发学习指南.另外,如果你用到Map 3D相关的功能,你还可能需要Map 3D的开发知识,看Map 3D API二次开发学习指南. 软件准备及开发环境 AutoCAD Civil 3D 软件,推荐2014以上版本,你可以从Autodesk 官方网站下载试用版, Visual Studio 2012 或

蓝牙利用协议栈API读取设备MAC地址

最近在移植QQ物联协议,需要读取设备mac地址. 读取CC2541设备MAC地址的方法,有直接读取mac寄存器,也可以调用协议栈API.这里采用的是调用API的形式. 1 /*利用协议栈API读取MAC地址*/ 2 static uint8 macaddr[B_ADDR_LEN]={0}; // mac 地址 3 uint8_t macstr[13] = {0}; 4 5 GAPRole_GetParameter(GAPROLE_BD_ADDR, macaddr); 6 sprintf((cha

Java API 读取HDFS目录下的所有文件

/** * 获取1号店生鲜食品的分类id字符串 * @param filePath * @return */ public String getYHDSXCategoryIdStr(String filePath) { final String DELIMITER = new String(new byte[]{1}); final String INNER_DELIMITER = ","; // 遍历目录下的所有文件 BufferedReader br = null; try { F

File API 读取文件小结

简单地说,File API只规定怎样从硬盘上提取文件,然后交给在网页中运行的JavaScript代码. 与以往文件上传不一样,File API不是为了向服务器提交文件设计的. 关于File API不能做什么也非常值得注意.它不能修改文件,也不能创建新文件. 想保存任何数据,你可以通过Ajax把数据发送到服务器,或者把它保存在本地存储空间中. 取得文件 使用input元素.将其type属性设置为file,这样是最常见的标准上传文本框 隐藏的input元素.为了保证风格一致,可以把input元素隐藏

Java API 读取HDFS的单文件

HDFS上的单文件: -bash-3.2$ hadoop fs -ls /user/pms/ouyangyewei/data/input/combineorder/repeat_rec_category Found 1 items -rw-r--r-- 2 deploy supergroup 520 2014-08-14 17:03 /user/pms/ouyangyewei/data/input/combineorder/repeat_rec_category/repeatRecCategor

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

1.工具的用途:用HTML5 file api读取文件的MD5码.MD5码在文件的唯一性识别上有很重要的应用,业内常用MD5进行文件识别.文件秒传.文件安全性检查等: 2.适用性:IE.Chrome皆兼容: 3.缺陷:当上传大文件时,需要较长的时间才能扫描出MD5码: 4.关于引用:其中引用了js文件(spark-md5.js) <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo

Libgdx New 3D API 教程之 -- 加载3D场景的背后-第二部分

http://bbs.9ria.com/thread-221699-1-1.html 在本教程的第一部分,我们已经看过LibGDX 3D API中Model类的总体结构.在第2部分中,我们将会分析渲染管道,从加载模型开始,到真正的渲染模型.我们将不会在渲染管道的某个问题上进行深入探讨.我们只会介绍一些非常基本的内容,这是我觉得你使用3D API时,应该了解的. 在这一部分,我们要分析渲染究竟做了什么.明白我们在渲染时所做的事很重要.在前一部分本教程,我们已经看到,一个Model是由很多个Node

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

申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)具体步骤如下:                                                                     www.169it.com 1.生SHA1密钥(旧版是MD5)eclipse->help->install new software->add(name: keytool;location:http://www.keytool.sourceforge.net

Libgdx New 3D API 教程之 -- Libgdx中的3D frustum culling

This blog is a chinese version of xoppa's Libgdx new 3D api tutorial. For English version, please refer to >>LINK<< 我要偷懒了,好久没看LibGDX,也很久没看3D,新教程的题目我就不懂了.不过看了课程的内容,相信你们都会理解. 正文: 当渲染一个3d场景时,其中真正可见的对象通常都比总对象数少很多.因此渲染全部的物体,包括那些根本看不到的,即浪费了富贵的GPU时间,