前言
很多教程将excel表显示XY并导出图层,导出的图层是没有其他字段信息的。当需要导出图层一并包含其他字段怎么处理呢。
这里有个重点提示:shapefile图层的属性表字段名称是限长的(具体多长可以在ArcGIS里看一下),Excel中字段名称不要过长,否则,读取表格创建featureClass时会判断出错。最好用英文表示
如将上述Excel数据处理成点图层(.shp)
函数及说明
(1)
功能:Excel数据创建IFeatureClass
输入数据:Excel路径
输出数据:IfeatureClass
public IFeatureClass getExcelTable(string path)
{
string name = System.IO.Path.GetFileNameWithoutExtension(path);
ESRI.ArcGIS.esriSystem.IPropertySet proset = new ESRI.ArcGIS.esriSystem.PropertySetClass();
string strcon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + @";Extended Properties=Excel 8.0";
proset.SetProperty("CONNECTSTRING", strcon);
IWorkspaceFactory workspf = new ESRI.ArcGIS.DataSourcesOleDB.OLEDBWorkspaceFactoryClass();
IFeatureWorkspace fworkfac = workspf.Open(proset, 0) as IFeatureWorkspace;
IQueryDef myQueryDef = fworkfac.CreateQueryDef();
myQueryDef.Tables = "["+name+"$]";
myQueryDef.SubFields = "*";
myQueryDef.WhereClause = "";
ICursor myCursor = myQueryDef.Evaluate();
IFields myfields = myCursor.Fields;
IRow myRow;
IPoint point = new PointClass();
IFeatureClass ne