using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesFile;
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 整幅加载ToolStripMenuItem_Click(object sender, EventArgs e)
{
#region 一:整幅加载
try
{
this.axMapControl1.ActiveView.Clear();//清空当前视图
OpenFileDialog xjCADOpenFileDialog = new OpenFileDialog();
xjCADOpenFileDialog.Title = "打开CAD数据文件";
xjCADOpenFileDialog.Filter = "CAD数据(*.dwg)|*.dwg";
if (xjCADOpenFileDialog.ShowDialog() == DialogResult.OK)
{
string xjCADFullPath = xjCADOpenFileDialog.FileName;//文件绝对路径
int xjIndex = xjCADFullPath.LastIndexOf("\\");
string xjCADFilePath = xjCADFullPath.Substring(0, xjIndex);//文件目录
string xjCADFileName = xjCADFullPath.Substring(xjIndex + 1);//文件名称
//打开CAD数据集
IWorkspaceFactory xjCADWsF = new CadWorkspaceFactoryClass();//using ESRI.ArcGIS.Geodatabase;//using ESRI.ArcGIS.DataSourcesFile;
IFeatureWorkspace xjCADFWs = (IFeatureWorkspace)xjCADWsF.OpenFromFile(xjCADFilePath, 0);
IFeatureDataset xjCADFeatureDataset = xjCADFWs.OpenFeatureDataset(xjCADFileName);
IFeatureClassContainer xjFeatClassContainer = (IFeatureClassContainer)xjCADFeatureDataset;//管理IFeatureDataset中的每个要素类
//遍历
for (int i = 0; i < xjFeatClassContainer.ClassCount; i++)
{
IFeatureClass xjFeatureClass = xjFeatClassContainer.get_Class(i);//要素集
if (xjFeatureClass.FeatureType == esriFeatureType.esriFTCoverageAnnotation)//注记层
{
IFeatureLayer xjCADFeatureLayer = new CadAnnotationLayerClass();//using ESRI.ArcGIS.Carto;
xjCADFeatureLayer.Name = xjFeatureClass.AliasName;
xjCADFeatureLayer.FeatureClass = xjFeatureClass;
this.axMapControl1.Map.AddLayer(xjCADFeatureLayer);
}
else //点、线、面
{
IFeatureLayer xjCADFeatureLayer = new FeatureLayerClass();
xjCADFeatureLayer.Name = xjFeatureClass.AliasName;
xjCADFeatureLayer.FeatureClass = xjFeatureClass;
this.axMapControl1.Map.AddLayer(xjCADFeatureLayer);
}
this.axMapControl1.ActiveView.Refresh();//刷新
}
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
#endregion
}
}
}
VS2010+ArcEngine10.1具体窗体+代码见:点击打开链接