单纯使用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

最新文章

  1. 负载均衡——nginx理论
  2. socket、webService、RMI ?
  3. mysql如何给汉字按照首字母顺序排序
  4. 用GDB排查Python程序故障
  5. OpenFlow能解决私有云网络VLAN问题么
  6. nodejs--express开发个人博客(2)
  7. 开源语法分析器--ANTLR
  8. Linux系统安全需要注意的一些问题
  9. webpack 引入 bootstrap
  10. Hibernate用注解生成表
  11. (六) 编写vivid
  12. Windows 10 专业版 长期服务版 激活
  13. UglifyJs打包压缩问题引起的思考
  14. 018 easygui的使用
  15. Xcode编辑器之基本使用(一)
  16. jbpm 6 vs activities 5评估(持续更新、亲测实际项目评估)
  17. 洛谷P1208
  18. 一、springcloud服务注册、发现、调用(consul/eureka)
  19. 队列的理解和实现(二) ----- 链队列(java实现)
  20. puppet practice

热门文章

  1. mybatis查询返回多条数据
  2. min-max 容斥简记
  3. Typora笔记收费的解决
  4. python与java中符号表达式的区别
  5. Python打包时包含静态文件处理方法
  6. host头攻击
  7. windows 安装配置mysql 8,以及远程连接访问
  8. flask、element、vue项目实战:搭建一个加密excel数据的网站
  9. python机器学习——朴素贝叶斯算法
  10. 前端element ui 文件base64加密字符串 上传