使用 ww.cad 完成dwg文件转shp(包含所有属性)
单纯使用ArcEngine提供的接口读取dwg数据转shp存在众多属性无法读取的情况(最直观的 南方cass生产的dwg文件有SOUTH这一字段,为目标要素的类型)
private void ConvertDwgToShp()
{ DwgReader pDwgReader = new DwgReader(@"D:\app\CAD\test.dwg"); DxfModel pDxf = pDwgReader.Read();
DxfEntityCollection xx = pDxf.Entities; //为写入shp文件做准备
WriteDestShpFile wSHP = new WriteDestShpFile(); //在遍历CAD要素时 筛选唯一图层,创建shp用
List<string> pLayerList = new List<string>();
//创建shp文件时,字段集合
List<string> pDwgFieldList = new List<string>();
//写入shp时,字段与值 的键值对
Dictionary<string,string> pDic = new Dictionary<string,string>(); IWorkspaceFactory pWFactory = new ShapefileWorkspaceFactoryClass();
IFeatureWorkspace pFWorkspace = pWFactory.OpenFromFile("C:/test",0) as IFeatureWorkspace; DelegateTest delegateTest = null;
foreach (DxfEntity item in xx)
{
//当前要素的类型(点线面)
string GeoType = GetEntityType.GetitemType(item);
//当前要素将要存入的图层名称
string DesLayerName = string.Format("{0}_{1}", item.Layer.Name, GeoType); //扩展属性
DxfExtendedDataCollection pDxfDataCol = item.ExtendedDataCollection; pDic.Clear();
pDwgFieldList.Clear(); foreach (DxfExtendedData ExData in pDxfDataCol)
{
//AppID.Name 字段名
pDwgFieldList.Add(ExData.AppId.Name); string values = "";
for (int j = 0; j < ExData.Values.Count; j++)
{
values += ExData.Values[j];
}
pDic.Add(ExData.AppId.Name, values);
} if (!pLayerList.Contains(DesLayerName))
{
pLayerList.Add(DesLayerName);
//此处为根据要素类类型,名称,字段及路径的一个创建shp文件的方法(需要方法联系,下有联系方式)
CreateDestShpFile.CreateShpFile(GeoType, DesLayerName, pDwgFieldList, "C:/test");
} switch (item.GetType().Name)
{
case "DxfLwPolyline":
delegateTest = new DelegateTest((new ConvertDxfLwPolyline()).ConvertToshp);
break;
case "DxfLwPoint":
delegateTest = new DelegateTest((new ConvertDxfPoint()).ConvertToshp);
break;
case "DxfCircle":
delegateTest = new DelegateTest((new ConvertDxfCircle()).ConvertToshp);
break;
case "DxfPolyline2D":
delegateTest = new DelegateTest((new ConvertDxfPolyline2D()).ConvertToshp);
break;
default:
Console.WriteLine(item.GetType().Name);
break;
}
IGeometry pGeometry = delegateTest.Invoke(item); IFeatureClass pFeatureClass = pFWorkspace.OpenFeatureClass(DesLayerName);
wSHP.WriteDestFeature(pFeatureClass, pGeometry,pDic);
}
}
个人理解:CAD中没有面要素与线要素的概念,全部都是线要素,只存在图形封闭与不封闭的区分,因此封闭的时候视为面,下为CAD要素为DxfLwPolyline时的要素转换代码,其它同理。
1 public IGeometry ConvertToshp(DxfEntity item)
2 {
3 //CAD 获取点集合
4 DxfLwPolyline pPointColl = item as DxfLwPolyline;
5
6 IGeometry pGeometry = null;
7 if (pPointColl.Closed)
8 {
9 IPointCollection pPoints = new PolygonClass();
10 foreach (var point in pPointColl.Vertices)
11 {
12 IPoint pPoint = new PointClass() { X = point.X, Y = point.Y };
13 pPoints.AddPoint(pPoint);
14 }
15 pPoints.AddPoint(pPoints.get_Point(0));
16 pGeometry = pPoints as IPolygon;
17 }
18 else
19 {
20 IPointCollection pPoints = new PolylineClass();
21 foreach (var point in pPointColl.Vertices)
22 {
23 IPoint pPoint = new PointClass() { X = point.X, Y = point.Y };
24 pPoints.AddPoint(pPoint);
25 }
26 pGeometry = pPoints as IPolyline;
27 }
28 return pGeometry;
29 }
使用的是 ww.cad 类库 版本4.0.35.21(单纯复制粘贴不可使用,非关键代码篇幅原因没展示)
联系VX:cl141545646
使用 ww.cad 完成dwg文件转shp(包含所有属性)的更多相关文章
- CAD保存DWG文件,设置保存的文件版本号和密码
主要用到函数说明: MxDrawXCustomFunction::Mx_SaveDwgEx 保存DWG文件,可以设置保存的文件版本号和密码,详细说明如下: 参数 说明 IN CString sFile ...
- C# 读取CAD文件缩略图(DWG文件)
//C# 读取CAD文件缩略图(DWG文件) https://blog.csdn.net/hanghangaidoudou/article/details/8589574 //2010-09-04 1 ...
- C# 实现预览dwg文件完整源代码(无需autocad环境)
using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sys ...
- 梦想CAD控件,用于浏览和编辑DWG文件,在脱离AUTOCAD的情况下独立运行,相当于简易CAD
(百度百科连接) 梦想绘图控件5.2 是国内最强,最专业的CAD开发组件(控件),不需要AutoCAD就能独立运行.控件使用VC 2010开发,最早从2007年第一个版本完成,经过多年的累积已经非常 ...
- 如何在网页中浏览和编辑DWG文件 梦想CAD控件
如何在网页中浏览和编辑DWG文件 梦想CAD控件 www.mxdraw.com 梦想绘图控件5.2 是国内最强,最专业的CAD开发组件(控件),不需要AutoCAD就能独立运行.控件使用VC 201 ...
- 高精度快速预览打开dwg文件的CAD控件CAD Image DLL介绍及下载
CAD Image DLL对于DXF格式, DWG格式(AutoCAD R12 到AutoCAD 2004/2005), PLT 以及 HPGL/HPGL2文件都有快速的显示速度和精度,开发者再也不会 ...
- CAD控件:网上打开dwg文件时,对dwg文件路径加密的功能
梦想CAD控件2015.03.12最新更新 1. 增加控件状态栏文字,自定义功能, C++接口为 : CStatusBarInformationReactor::CreatePro ...
- CAD把一个dwg文件,或者图像文件当着一个背景导入(com接口VB语言)
主要用到函数说明: MxDrawXCustomFunction::Mx_OpenBackgroundFile 把一个dwg文件,或者图像文件当着一个背景导入.详细说明如下: 参数 说明 CString ...
- CAD把一个DWG文件中的多个图框一次性全部插入到打开的DWG文件中
主要用到函数说明: _DMxDrawX::InsertBlock 向控件数据库中插入一个图块,不用它插入匿名块,详细说明如下: 参数 说明 BSTR pszDwgFileName 图块定义的dwg 文 ...
- CAD图DWG解析WebGIS可视化技术分析总结
背景 AutoCAD是国际上著名的二维和三维CAD设计软件,用于二维绘图.详细绘制.设计文档和基本三维设计.现已经成为国际上广为流行的绘图工具..dwg文件格式成为二维绘图的事实标准格式. 但由于Au ...
随机推荐
- ctfshow web入门41
这个题过滤了$.+.-.^.~使得异或自增和取反构造字符都无法使用,同时甚至过滤了字母和数字. 但是特意留了个或运算符|. 由此我们可以尝试从ascii为0-255的字符中,找到用或运算能得到我们可用 ...
- tomcat 2 - 默认连接器精简版
tomcat 将一个包中所有类使用的错误信息存储在 properties 文件中,每个包有一个 properties 文件.每个 properties 文件都是用 org.apache.catali ...
- JS学习-常用的Web API
web API web-api 分类 链接 描述 操作文档的API 操作document dom,html,svg 从服务器获取数据的API XMLHttpRequest XMLHttpRequest ...
- SSH 秘钥登入
1.打开权限 vim /etc/ssh/sshd_config 去掉 PubkeyAuthentication yes 一行的# 2.重启ssh服务 systemctl restart ss ...
- Mac如何卸载软件 Mac如何删除软件
初次接触Mac苹果电脑的用户可能不知道如何卸载已经装好的应用软件,之前有给大家介绍Mac如何安装软件,现在教大家如何卸载软件,其实非常简单,让我们看看吧: 1.首先我们打开Finder,就是我们Doc ...
- 寻找进程ID
- oracle 函数instr
- redux-thunk初步使用
redux中间件,用来处理异步action 返回 一个函数 内部函数接收存储方法dispatch和getState参数 demo: import { GET_ONLINE_STATUS, SET_O ...
- nacos之服务注册、发现及维持心跳
注册服务(增加健康检查) 服务发现(默认15s没有心跳请求,则自动注销服务) 心跳(维持服务运行状态) 参数说明 serviceName:服务名称 beat:服务的详细信息 ip 端口等,json ...
- wx小程序 组件无法使用全局样式 (app.wxss)
解决方法: 在组件中加上options选项 Component({ options: { addGlobalClass: true } })