通过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 ...
随机推荐
- [New Portal]Windows Azure Virtual Machine (11) 在本地使用Hyper-V制作虚拟机模板,并上传至Azure (1)
<Windows Azure Platform 系列文章目录> 本章介绍的内容是将本地Hyper-V的VHD,上传到Azure数据中心,作为自定义的虚拟机模板. 注意:因为在制作VHD的最 ...
- js基础篇——localStorage使用要点
localStorage主要用来替代cookie,解决cookie(可参考cookie使用要点)读写困难.容量有限的问题.localStorage有以下几个特点 1.localStorage是一个普通 ...
- WCF服务创建与使用(请求应答模式)
不说废话,直接上代码.以下服务创建是在独立的WCF类库中,若采用WCF应程程序,定义及创建服务代码均相同,但文件名不同,是CalculatorService.svc 第一步,定义服务契约(Servic ...
- [JS] JS模块化开发之RequireJS
本节将简述RequireJS常用的功能 RequireJS 实现了 Asynchronous Module API. 目录: 为什么使用RequireJS 加载RequireJS Hello Worl ...
- Android Studio添加PNG图片报错原因
今天在网上看到一个关于Splash Activity的Android帖子,博主在一通讲解之后也给出了代码.于是果断下载下来了看看怎么实现的.一步步照着流程把这个功能实现了一遍.一切都没有大问题,但是在 ...
- C语言学习016:单链表
#include <stdio.h> //定义一个链表,链表是一种递归结构,在定义的时候必须要给结构起一个名字 typedef struct folder{ int level; char ...
- iOS阶段学习第17天笔记(NSFileManager-NSFileHandle-文件操作)
iOS学习(OC语言)知识点整理 一.单例模式 1)单例是一种编程思想,一个设计模式,与语言无关在采用了单例对象的应用程序中,需要单例类自行提供实例化单例对象, 不管实例化单例对象多少次,只有一个对象 ...
- 【C#】第3章学习要点(二)自定义类和结构
分类:C#.VS2015 创建日期:2016-06-19 使用教材:(十二五国家级规划教材)<C#程序设计及应用教程>(第3版) 一.要点概述 别人提供的类都是为了简化你的工作量用的,可是 ...
- 项目中的web api知识总结
最近在做公司的项目,自己负责webapi的框架的搭建与开发,最近很忙,一直没时间对工作中遇到的知识点缺少个总结,现总结一下,对自己是个提升,如果个人的小点点小总结能对博友有帮助那也是善莫大焉. (1) ...
- SSO单点登录实现原理与总结
一.什么是单点登录SSO(Single Sign-On) SSO是一种统一认证和授权机制,指访问同一服务器不同应用中的受保护资源的同一用户,只需要登录一次,即通过一个应用中的安全验证后,再访问其他应用 ...