通过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 ...
随机推荐
- postgres中几个复杂的sql语句
postgres中几个复杂的sql语句 需求一 需要获取一个问题列表,这个问题列表的排序方式是分为两个部分,第一部分是一个已有的数组[0,579489,579482,579453,561983,561 ...
- HT for Web基于HTML5的图像操作(一)
HT for Web独创的矢量图片设计架构,使其具有强大丰富的动态图形呈现能力,但从最近知乎热议的“Adobe Photoshop 是否已经过时?”的话题,大家能体会到很多情况下实际项目不可能完全采用 ...
- 语义化HTML:i、b、em和strong标签
一.前言 在HTML4.1中i和b作为表象标签分别表示斜体和粗体样式,而强调样式与内容分离的XHTML中则出现样式效果相同的em和strong表义标签,此时我们会建议避免使用i和b标签,应该改用em和 ...
- codeMirror插件使用讲解
codeMirror是一款十分强大的代码编辑插件,提供了十分丰富的API,最近在项目中用到了这款插件,于是在这里给大家分享下使用方法和心得: codeMirror调用非常方便 首先在页面中载入插件CS ...
- helper实现隐藏前台特效
想实现下面的功能:如下图所示 点击已结束按钮,使上面的红色跳转到已结束活动按钮上面,本来前台代码里面是使用了一个action来实现的,但是我改了点东西,使跳转不了. 前台代码 <ul class ...
- [转]HTML5 本地图片预览
[原文链接] https://www.huangwenchao.com.cn/2015/03/html5-image-preview.html 问题 加入我们在 HTML 里面有一个图片上传控件: & ...
- linux下的C语言开发
在很多人的眼里,C语言和linux常常是分不开的.这其中的原因很多,其中最重要的一部分我认为是linux本身就是C语言的杰出作品.当然,linux操作系统本身对C语言的支持也是相当到位的.作为一个真正 ...
- DataTable 除去列中重复值
DataTable dtPCI = dtblSourceData.DefaultView.ToTable(true, new string[] { "Server Cell PCI" ...
- Microsoft.Practices.Unity入门
Unity是微软Patterns & Practices团队所开发的一个轻量级的,并且可扩展的依赖注入(Dependency Injection)容器,它支持常用的三种依赖注入方式:构造器注入 ...
- android FragmentActivity+FragmentTabHost+Fragment框架布局
这周比较闲,计划系统的学习一下android开发,我本是一名IOS程序员,对手机开发还是有自己的一套思路的, 固这套思路用到我当前学android上了,先选择从Main页面的tabbar部分代码入手, ...