ArcEngine对CSV文件的操作

来源:互联网 发布:商城模板html源码下载 编辑:程序博客网 时间:2024/06/05 23:39

加载csv文件

using ESRI.ArcGIS.esriSystem;using ESRI.ArcGIS.DataSourcesOleDB;using ESRI.ArcGIS.Geodatabase;public static ITable OpenCSVFile(string csvFullPath){    string csvPath = System.IO.Path.GetDirectoryName(csvFullPath); //csv文件的文件夹位置    string csvName = System.IO.Path.GetFileName(csvFullPath);//csv文件的文件名    IWorkspaceFactory pWorkspaceFactory = new OLEDBWorkspaceFactory();    IPropertySet pPropSet = new PropertySet();    //注意如果csv文件的字符编码是utf-8    //pPropSet.SetProperty("CONNECTSTRING", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + tablePath + ";Extended Properties='Text;HDR=Yes;IMEX=1;CharacterSet=65001;'");    pPropSet.SetProperty("CONNECTSTRING", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + csvPath + ";Extended Properties='Text;HDR=Yes;IMEX=1;'");    IWorkspace pWorkspace = pWorkspaceFactory.Open(pPropSet, 0);    IFeatureWorkspace pFeatureWorkspace2 = (IFeatureWorkspace)pWorkspace;    ITable pTable = pFeatureWorkspace2.OpenTable(csvName);    return pTable;}

shp文件join csv表格并导出

using ESRI.ArcGIS.GeoDatabaseUI;using ESRI.ArcGIS.Carto;public static void JoinCSV2ShpAndExport(IFeatureLayer pFeatureLayer, ITable pTable, string layerJoinField, string csvJoinField){      //join     IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;     IMemoryRelationshipClassFactory pMemoryRelationClassFC = new MemoryRelationshipClassFactory();     IRelationshipClass pRelationshipClass = pMemoryRelationClassFC.Open("", pFeatureClass, layerJoinField, (IObjectClass)pTable, csvJoinField, "forword", "backword", esriRelCardinality.esriRelCardinalityOneToOne);     IDisplayRelationshipClass pDisplayrelationShip = (IDisplayRelationshipClass)pFeatureLayer;                                pDisplayrelationShip.DisplayRelationshipClass(pRelationshipClass, esriJoinType.esriLeftOuterJoin);     IRelationshipClassCollectionEdit pRelClassCollEdit = pFeatureLayer as IRelationshipClassCollectionEdit;    pRelClassCollEdit.AddRelationshipClass(pRelationshipClass);     IDisplayTable displayTable = pRelClassCollEdit as IDisplayTable;     IRelQueryTable joinedTable = displayTable.DisplayTable as IRelQueryTable;     //导出     IDatasetName srcName = (joinedTable as IDataset).FullName as IDatasetName;     IDatasetName destName = new FeatureClassNameClass() as IDatasetName;     destName.Name = "aa";//输出文件的名称     IWorkspaceName destWsName = new WorkspaceNameClass();     destWsName.PathName = "C:\\Temp\\";//输出文件的位置     destWsName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory.1";    destName.WorkspaceName = destWsName;    IFeatureClassName destFcName = destName as IFeatureClassName;    destFcName.FeatureType = esriFeatureType.esriFTSimple;    destFcName.ShapeFieldName = "Shape";    destFcName.ShapeType = pFeatureClass.ShapeType;    IQueryFilter queryF = null;    ISelectionSet selnSet = null;    IGeometryDef geomDef = null;    ExportOperation exOp = new ExportOperationClass();    exOp.ExportFeatureClass(srcName, queryF, selnSet, geomDef, destFcName, 0);    ////移除表连接    pRelClassCollEdit.RemoveAllRelationshipClasses();    pDisplayrelationShip.DisplayRelationshipClass(null, esriJoinType.esriLeftInnerJoin);}
原创粉丝点击