通过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读取线状要素的节点坐标的更多相关文章
- Civil 3D API二次开发学习指南
Civil 3D构建于AutoCAD 和 Map 3D之上,在学习Civil 3D API二次开发之前,您至少需要了解AutoCAD API的二次开发,你可以参考AutoCAD .NET API二次开 ...
- File API 读取上传的文件
1, 在html 文档中,<input type="file"> 我们可以选择文件进行上传,但这时只能上传一个文件.如果加上multiple 属性,可以上传多个文件,上 ...
- 使用google map v3 api 开发地图服务
Google Map V3 API 学习地址: http://code.google.com/intl/zh-CN/apis/maps/documentation/javascript/article ...
- 申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)
申请Android Map 的API Key(v2)的最新申请方式(SHA1密钥)具体步骤如下: ...
- Google Map JavaScript API V3 实例大全
Google Map JavaScript API V3 实例大全 基础知识 简单的例子 地理位置 语言 位置 坐标 简单的投影 事件 简单事件 关闭事件 多次添加事件 事件属性 控制 php禁用ui ...
- google map android api v2
我在这主要列举几个需要注意的问题: 1.需要注意使用的api版本的问题,例如google map android api v1就和v2差别很大,包括申请key方面,所以在搜索资料的时候一定注意版本问题 ...
- 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 ...
- HTML5 file api读取文件的MD5码工具
1.工具的用途:用HTML5 file api读取文件的MD5码.MD5码在文件的唯一性识别上有很重要的应用,业内常用MD5进行文件识别.文件秒传.文件安全性检查等: 2.适用性:IE.Chrome皆 ...
- Google Map Android api V2 中使用MapView遇到CameraUpdateFactory is not initialized!的解决办法
先说一下 Map V2 API Key 的问题吧: 在打包APP时需要自己生成一个XXX.keystore 用这个密室库生成的SHA1去申请的key 作为AndroidManifest.xml 中的K ...
随机推荐
- Python - Tips
01 - input与raw_input的区别 input() #可以直接输入数字,但输入字符的要用引号''或者双引号"" raw_input() #将所有的输入都直接当作一串字符 ...
- JVM之类加载器下篇
除了自定义的类加载之外,jvm存在三种类加载器,并以一种父委托的加载机制进行加载. --启动类加载器,又称根加载器,是一个native的方法,使用c++实现.在java中我们用null标识,用于加载j ...
- 使用laravel一分钟搭建CURD后台页面
配置即一切 一切皆于需求,后台从0开始搭建,但是写了一两个页面后发现太多的是对单表的增删改查操作,于是就想到了,能不能做一个快速搭建的后台.想到一句话,配置即一切.如果一个CURD后台能只进行配置就自 ...
- IOS开发技巧快速生成二维码
随着移动互联网的发展,二维码应用非常普遍,各大商场,饭店,水果店 基本都有二维码的身影,那么ios中怎么生成二维码呢? 下面的的程序演示了快速生成二维码的方法: 在ios里面要生成二维码,需要借助一个 ...
- MySql安装出现问题---无服务,修改密码
之前在项目中一直使用的是SqlServer数据库,现在学习下MySql,下面是学习MySql的学习笔记. MySql简介 MySql是一种关联数据库管理系统(关系型),将数据 ...
- winform中ComboBox利用AutoComplete属性实现模糊查询(有缺陷)
上一篇文章是用ComboBox里面的原生事件实现模糊查询,操作比较灵活一些,但是收到评论说,利用AutoComplete属性就可以实现模糊查询,但是据本人所了解,AutoComplete虽然能够方便的 ...
- .NET Nancy 详解(三) Respone 和 ViewEngine
我们在ASP.NET MVC中可以返回各种类型的ActionResult(以下图片来自于园友--待补..) 在Nancy 中本着简单粗暴的原则,使用方式略有不同.这期我们使用的版本是Nancy的第一个 ...
- [Asp.net 5] Configuration-新一代的配置文件(接口定义与基础实现)
关于配置文件的目录:[Asp.net 5] Configuration-新一代的配置文件 本系列文章讲的是asp.net 5(Asp.net VNext)中的配置文件部分,工程下载地址为:https: ...
- C# 重载的几种实现
算法重用是非常普遍的需求,在C#中可以使用如下手段实现,非常简单,自己记录一下,方便查询. 以一个小功能为例来说明一下:打印1-5这5个数,和A-E这5个字符. 重载方式 static void Ma ...
- iOS阶段学习第三天笔记(运算符)
iOS学习(C语言)知识点整理笔记 1.运算符 一.算术运算符 1)表达式由变量.常量.运算符构成,有确定的类型和值 2)算术运算符包括: +(加),-(减),*(乘),/(除),%(模) 3)算术运 ...