加载CAD文件稍显复杂一些,总体还是和前面基本类似

     private void button3_Click(object sender, EventArgs e)
        {
            axMapControl1.ClearLayers();
            IWorkspaceFactory pWF = new ESRI.ArcGIS.DataSourcesFile.CadWorkspaceFactory();//利用工厂对象去生成一个CAD文件的工作空间
            IWorkspace pW = pWF.OpenFromFile(cadPath,0);    //打开对应的文件夹路径
            IFeatureWorkspace pFW = (IFeatureWorkspace)pW;

            IFeatureClass pFW_text = pFW.OpenFeatureClass("裙子.dwg:Polygon");//利用要素类去接收对应的cad文件中的面属性
            IFeatureLayer pFeatureLayer2 = new FeatureLayerClass();//生成一个要素图层对象
            pFeatureLayer2.FeatureClass = pFW_text;//将接收要素类的cad文件赋值给要素图层的要素类属性
            axMapControl1.AddLayer(pFeatureLayer2);//添加对应的polygon图层

            IFeatureClass pFC = pFW.OpenFeatureClass("裙子.dwg:Polyline");//利用要素类去接收对应的cad文件中的线属性
            IFeatureLayer pFeatLyr = new FeatureLayerClass();//生成一个要素图层对象(接收线)
            pFeatLyr.FeatureClass = pFC;//将线属性赋值给对应的要素图层
            ISimpleLineSymbol pLineSymbol = new SimpleLineSymbolClass();//创建一个线特征对象
            IRgbColor pColor = new RgbColorClass();//生成一个颜色控制的接口
            pColor.Red = 0;
            pColor.Blue = 255;
            pColor.Green = 0;

            pLineSymbol.Color = (IColor)pColor;//将线对象的颜色设置为对应的颜色
            pLineSymbol.Style = esriSimpleLineStyle.esriSLSSolid;//设置线的样式

            ISimpleRenderer pRender = new SimpleRendererClass();
            pRender.Symbol = pLineSymbol as ISymbol;

            IGeoFeatureLayer pGeoLyr = pFeatLyr as IGeoFeatureLayer;
            pGeoLyr.Renderer = pRender as IFeatureRenderer;

            axMapControl1.AddLayer(pFeatLyr);
            axMapControl1.ActiveView.Refresh();
        }

 

版权声明:本文为cdp1591652208原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/cdp1591652208/p/9005814.html