C#、AE开发入门之打开CAD文件并显示

加载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();
        }

 

转载于:https://www.cnblogs.com/cdp1591652208/p/9005814.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值