单纯使用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(包含所有属性)的更多相关文章

  1. CAD保存DWG文件,设置保存的文件版本号和密码

    主要用到函数说明: MxDrawXCustomFunction::Mx_SaveDwgEx 保存DWG文件,可以设置保存的文件版本号和密码,详细说明如下: 参数 说明 IN CString sFile ...

  2. C# 读取CAD文件缩略图(DWG文件)

    //C# 读取CAD文件缩略图(DWG文件) https://blog.csdn.net/hanghangaidoudou/article/details/8589574 //2010-09-04 1 ...

  3. C# 实现预览dwg文件完整源代码(无需autocad环境)

    using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sys ...

  4. 梦想CAD控件,用于浏览和编辑DWG文件,在脱离AUTOCAD的情况下独立运行,相当于简易CAD

    (百度百科连接) 梦想绘图控件5.2  是国内最强,最专业的CAD开发组件(控件),不需要AutoCAD就能独立运行.控件使用VC 2010开发,最早从2007年第一个版本完成,经过多年的累积已经非常 ...

  5. 如何在网页中浏览和编辑DWG文件 梦想CAD控件

    如何在网页中浏览和编辑DWG文件 梦想CAD控件 www.mxdraw.com 梦想绘图控件5.2  是国内最强,最专业的CAD开发组件(控件),不需要AutoCAD就能独立运行.控件使用VC 201 ...

  6. 高精度快速预览打开dwg文件的CAD控件CAD Image DLL介绍及下载

    CAD Image DLL对于DXF格式, DWG格式(AutoCAD R12 到AutoCAD 2004/2005), PLT 以及 HPGL/HPGL2文件都有快速的显示速度和精度,开发者再也不会 ...

  7. CAD控件:网上打开dwg文件时,对dwg文件路径加密的功能

    梦想CAD控件2015.03.12最新更新  1. 增加控件状态栏文字,自定义功能,        C++接口为 :   CStatusBarInformationReactor::CreatePro ...

  8. CAD把一个dwg文件,或者图像文件当着一个背景导入(com接口VB语言)

    主要用到函数说明: MxDrawXCustomFunction::Mx_OpenBackgroundFile 把一个dwg文件,或者图像文件当着一个背景导入.详细说明如下: 参数 说明 CString ...

  9. CAD把一个DWG文件中的多个图框一次性全部插入到打开的DWG文件中

    主要用到函数说明: _DMxDrawX::InsertBlock 向控件数据库中插入一个图块,不用它插入匿名块,详细说明如下: 参数 说明 BSTR pszDwgFileName 图块定义的dwg 文 ...

  10. CAD图DWG解析WebGIS可视化技术分析总结

    背景 AutoCAD是国际上著名的二维和三维CAD设计软件,用于二维绘图.详细绘制.设计文档和基本三维设计.现已经成为国际上广为流行的绘图工具..dwg文件格式成为二维绘图的事实标准格式. 但由于Au ...

随机推荐

  1. Kubernetes Service发布

    一.定义Service 1-1.首先创建一个Deployment 类型nginx #定义Deployment类型nginx yaml文件 apiVersion: apps/v1 kind: Deplo ...

  2. 项目启动报错:关于modals以及node版本相关

    programme1: 1.代码用master分支的. 2. 删除node_module ,  yarn lock 文件,package-lock文件. 3. 用 npm install 或者 yar ...

  3. 代码and截图

    1.babassl ZUC算法代码: #include <stdio.h> #include <string.h> #include <openssl/crypto.h& ...

  4. 方法综合练习:out、params、ref

    using System; namespace ConsoleApp1 { class Program { /// <summary> /// 求两个参数之间的最大值 /// </s ...

  5. JavaScript垃圾回收机制的了解

    对于js种的任意长度字符串,对象,数组是没有固定大小的,只有在分配存储时,解释器就会分配内存来存储这些数据.当js的解释器消耗完系统所有可用内存时,就会造成系统崩溃.因此js有着自己的一套垃圾回收机制 ...

  6. 异步按照同步顺序执行的function

    function  step1 (callback) {     console.log(111111)     callback.call() } function  step2 (callback ...

  7. weblogic10.3.1.0安装(windows版)

    转: weblogic10.3.1.0安装(windows版) 安装完成后 配置数据源 然后配置部署项目. myeclipse 配置weblogic

  8. pythonn全栈学习笔记--logging模块学习(四)

    一.logging相关配置 1 import logging 2 """ 3 asctime:运行时间 4 name:主模块名称 5 levelname:日志级别 INF ...

  9. EF getCookie

    table class="table table-bordered"> <thead> <tr> <td>商品名称</td> ...

  10. springboot修改默认端口

    方案一: src/main/resuorces 文件夹下新建application.properties 文件 并添加内容server.port=8011即可 方案二: 使用EmbeddedServl ...